在pyav python中读取视频流字节时是否有任何硬件解码或编码?
我有一个使用 pyav 包读取视频字节的 python 脚本,如下代码所示。当我使用这段代码时,我发现使用大量 CPU RAM 读取长流的视频字节会使所有核心都很忙(CPU 使用率高)。但在我的项目中,我想以较低的CPU使用率实时处理它们,所以我想知道是否有任何硬件编码或硬件解码用于读取pyav中的流(即基于GPU而不是基于CPU)
def _get_video_stream_info(self, video_bytes):
stream_options = [{'codec': 'h264'}]
self.container = av.open(video_bytes, stream_options=stream_options)
video_stream = [s for s in self.container.streams if s.type == "video"][0]
fps = int(video_stream.average_rate)
total_frames = video_stream.frames
logger.info(f'[INFO] FPS video straem = {fps}')
logger.info(f'[INFO] Total frames video straem = {total_frames}')
num_split_frames = self.duration_split * fps
packet_list = []
for packet in self.container.demux(video_stream):
packet_list.append(packet)
return packet_list
I have a python scripts for reading video bytes using pyav package as below code. when I use this code I figured out that reading that video byte for a long stream using a lot amount of CPU RAM and makes all cores busy(High CPU usage). But in my project I want to process them in realtime with lower CPU usage, so I want to know is there any hardware encoding or hardware decoding for reading stream in pyav(i.e GPU based instead of CPU based)
def _get_video_stream_info(self, video_bytes):
stream_options = [{'codec': 'h264'}]
self.container = av.open(video_bytes, stream_options=stream_options)
video_stream = [s for s in self.container.streams if s.type == "video"][0]
fps = int(video_stream.average_rate)
total_frames = video_stream.frames
logger.info(f'[INFO] FPS video straem = {fps}')
logger.info(f'[INFO] Total frames video straem = {total_frames}')
num_split_frames = self.duration_split * fps
packet_list = []
for packet in self.container.demux(video_stream):
packet_list.append(packet)
return packet_list
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

根据您的需要调整此示例,您需要创建一个 Codec 上下文,如下使用 Nvidia cuda
Adapt this example to your fits, you need to create a Codec context,below with Nvidia cuda