Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check None packet when setting time_base after decode #1281

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion av/codec/context.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,8 @@ cdef class CodecContext:
# is carrying around.
# TODO: Somehow get this from the stream so we can not pass the
# packet here (because flushing packets are bogus).
frame._time_base = packet._time_base
if packet is not None:
frame._time_base = packet._time_base

frame.index = self.ptr.frame_number - 1

Expand Down
32 changes: 32 additions & 0 deletions tests/test_decode.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,3 +124,35 @@ def test_decode_close_then_use(self):
getattr(container, attr)
except AssertionError:
pass

def test_flush_decoded_video_frame_count(self):
container = av.open(fate_suite("h264/interlaced_crop.mp4"))
video_stream = next(s for s in container.streams if s.type == "video")

self.assertIs(video_stream, container.streams.video[0])

# Decode the first GOP, which requires a flush to get all frames
have_keyframe = False
input_count = 0
output_count = 0

for packet in container.demux(video_stream):
if packet.is_keyframe:
if have_keyframe:
break
have_keyframe = True

input_count += 1

for frame in video_stream.decode(packet):
output_count += 1

# Check the test works as expected and requires a flush
self.assertLess(output_count, input_count)

for frame in video_stream.decode(None):
# The Frame._time_base is not set by PyAV
self.assertIsNone(frame.time_base)
output_count += 1

self.assertEqual(output_count, input_count)
Loading