如何在 pyav 解码之前跳过帧以加快解码过程?
我有一个 python 脚本,可以读取长视频的字节。我想每秒跳过一些帧。 例如视频的 fps 是 24,我想删除那些未乘以 3 的帧 如果帧编号类似于此列表 [1,2,3,4, ...,24] ,我期望这个列表 [3,6,9,12,15,...,24]
问题是,如果我在 pyav 中解码之前跳过帧,则返回的帧会损坏(当我保存它们时,我看到保存的帧中有一些噪音),而且它还给了我一个错误。 这是我的 python 代码:
stream_options = [{'codec': 'h264'}]
container = av.open(video_path, stream_options=stream_options)
video_stream = [s for s in container.streams if s.type == "video"][0]
packet_list = []
for id_p, packet in enumerate(container.demux(video_stream)):
packet_list.append(packet)
skip=3
for id_pack, packet in enumerate(packet_list):
if id_pack % skip==0:
frame = packet.decode()
if len(frame):
frame_np = frame[0].to_ndarray(format='rgb24')
frame_list.append(frame_np)
它给了我一个错误,如下所示:
co located POCs unavailable
reference picture missing during reorder
reference picture missing during reorder
Missing reference picture, default is 65636
有没有办法在 pyav 中解码之前丢帧? 解码所有帧需要很长时间
I have a python script that can read bytes of a long video. I want to skip some frames in each second.
for example the fps of the video is 24 and I want to drop those frames that are not multiplication by 3
if the frame numbers are like this list [1,2,3,4, ...,24]
, and I expect this list [3,6,9,12,15,...,24]
the problem is that, if I skip the frames before decoding in pyav, the returned frames are corrupted (when I saved them I see some noises in the saved frames) and also it gave me an error.
here is my python code:
stream_options = [{'codec': 'h264'}]
container = av.open(video_path, stream_options=stream_options)
video_stream = [s for s in container.streams if s.type == "video"][0]
packet_list = []
for id_p, packet in enumerate(container.demux(video_stream)):
packet_list.append(packet)
skip=3
for id_pack, packet in enumerate(packet_list):
if id_pack % skip==0:
frame = packet.decode()
if len(frame):
frame_np = frame[0].to_ndarray(format='rgb24')
frame_list.append(frame_np)
it gave me an error as below:
co located POCs unavailable
reference picture missing during reorder
reference picture missing during reorder
Missing reference picture, default is 65636
Is there any way to drop frames before decoding in pyav?
decoding all frames takes a long time
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论