Skip to content

packet.is_corrupt is off by one #1597

@dotysan

Description

@dotysan

Not sure if this is a bug in PyAV or ffmpeg. But here goes...

Overview

When ffmpeg debugging is enabled, and a corrupt packet is encountered, it reports a different pts from the current PyAV packet that has .is_corrupt == True.

Reproduction

#! /usr/bin/env python3.12

import av

from logger import log

av.logging.set_level(av.logging.INFO)
# av.logging.restore_default_callback()

input_mpegts = 'rtsp://127.0.0.1:3011/net0'
input_options = {
    'rtsp_transport': 'tcp',
}

with av.open(
    input_mpegts,
    container_options=input_options,
) as in_container:

    for packet in in_container.demux():
        log.debug(packet)

        if packet.is_corrupt:
            log.warning(f"corrupt: {packet}")

The ffmpeg logging indicates a corrupt packet of pts=X. However, the packet.is_corrupt is the next one.

Versions

  • OS: Ubuntu 22.04LTS
  • PyAV: v13.1.0

Ugly workaround

last_packet = av.Packet()
for packet in in_container.demux():
    if last_packet.is_corrupt:  # BUG! why is it off by one?!?
        log.warning(f"this corrupt: {packet}")
    last_packet = packet

In the above, the pts of the ffmpeg DEBUG corrupt packet matches ours.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions