Skip to content

Commit 25c0758

Browse files
Philip de NierWyattBlue
Philip de Nier
authored andcommitted
Check None packet when setting time_base after decode
1 parent 285cf40 commit 25c0758

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

av/codec/context.pyx

+2-1
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,8 @@ cdef class CodecContext:
527527
# is carrying around.
528528
# TODO: Somehow get this from the stream so we can not pass the
529529
# packet here (because flushing packets are bogus).
530-
frame._time_base = packet._time_base
530+
if packet is not None:
531+
frame._time_base = packet._time_base
531532

532533
frame.index = self.ptr.frame_number - 1
533534

tests/test_decode.py

+32
Original file line numberDiff line numberDiff line change
@@ -124,3 +124,35 @@ def test_decode_close_then_use(self):
124124
getattr(container, attr)
125125
except AssertionError:
126126
pass
127+
128+
def test_flush_decoded_video_frame_count(self):
129+
container = av.open(fate_suite("h264/interlaced_crop.mp4"))
130+
video_stream = next(s for s in container.streams if s.type == "video")
131+
132+
self.assertIs(video_stream, container.streams.video[0])
133+
134+
# Decode the first GOP, which requires a flush to get all frames
135+
have_keyframe = False
136+
input_count = 0
137+
output_count = 0
138+
139+
for packet in container.demux(video_stream):
140+
if packet.is_keyframe:
141+
if have_keyframe:
142+
break
143+
have_keyframe = True
144+
145+
input_count += 1
146+
147+
for frame in video_stream.decode(packet):
148+
output_count += 1
149+
150+
# Check the test works as expected and requires a flush
151+
self.assertLess(output_count, input_count)
152+
153+
for frame in video_stream.decode(None):
154+
# The Frame._time_base is not set by PyAV
155+
self.assertIsNone(frame.time_base)
156+
output_count += 1
157+
158+
self.assertEqual(output_count, input_count)

0 commit comments

Comments
 (0)