File tree 2 files changed +34
-1
lines changed
2 files changed +34
-1
lines changed Original file line number Diff line number Diff line change @@ -527,7 +527,8 @@ cdef class CodecContext:
527
527
# is carrying around.
528
528
# TODO: Somehow get this from the stream so we can not pass the
529
529
# 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
531
532
532
533
frame.index = self .ptr.frame_number - 1
533
534
Original file line number Diff line number Diff line change @@ -124,3 +124,35 @@ def test_decode_close_then_use(self):
124
124
getattr (container , attr )
125
125
except AssertionError :
126
126
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 )
You can’t perform that action at this time.
0 commit comments