如何在 pyav 解码之前跳过帧以加快解码过程?

发布于 2025-01-20 07:27:04 字数 1095 浏览 1 评论 0原文

我有一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文