@@ -119,7 +119,7 @@ def test_get_metadata_audio_file(metadata_getter):
119
119
120
120
@pytest .mark .parametrize (
121
121
"num_frames_from_header, num_frames_from_content, expected_num_frames" ,
122
- [(None , 10 , 10 ), (10 , None , 10 ), (None , None , None )],
122
+ [(10 , 20 , 20 ), (None , 10 , 10 ), (10 , None , 10 )],
123
123
)
124
124
def test_num_frames_fallback (
125
125
num_frames_from_header , num_frames_from_content , expected_num_frames
@@ -143,6 +143,93 @@ def test_num_frames_fallback(
143
143
assert metadata .num_frames == expected_num_frames
144
144
145
145
146
+ @pytest .mark .parametrize (
147
+ "average_fps_from_header, duration_seconds_from_header, expected_num_frames" ,
148
+ [(60 , 10 , 600 ), (60 , None , None ), (None , 10 , None ), (None , None , None )],
149
+ )
150
+ def test_calculate_num_frames_using_fps_and_duration (
151
+ average_fps_from_header , duration_seconds_from_header , expected_num_frames
152
+ ):
153
+ """Check that if num_frames_from_content and num_frames_from_header are missing,
154
+ `.num_frames` is calculated using average_fps_from_header and duration_seconds_from_header
155
+ """
156
+ metadata = VideoStreamMetadata (
157
+ duration_seconds_from_header = duration_seconds_from_header ,
158
+ bit_rate = 123 ,
159
+ num_frames_from_header = None , # None to test calculating num_frames
160
+ num_frames_from_content = None , # None to test calculating num_frames
161
+ begin_stream_seconds_from_header = 0 ,
162
+ begin_stream_seconds_from_content = 0 ,
163
+ end_stream_seconds_from_content = 4 ,
164
+ codec = "whatever" ,
165
+ width = 123 ,
166
+ height = 321 ,
167
+ average_fps_from_header = average_fps_from_header ,
168
+ stream_index = 0 ,
169
+ )
170
+
171
+ assert metadata .num_frames == expected_num_frames
172
+
173
+
174
+ @pytest .mark .parametrize (
175
+ "duration_seconds_from_header, begin_stream_seconds_from_content, end_stream_seconds_from_content, expected_duration_seconds" ,
176
+ [(60 , 5 , 20 , 15 ), (60 , 1 , None , 60 ), (60 , None , 1 , 60 ), (None , 0 , 10 , 10 )],
177
+ )
178
+ def test_duration_seconds_fallback (
179
+ duration_seconds_from_header ,
180
+ begin_stream_seconds_from_content ,
181
+ end_stream_seconds_from_content ,
182
+ expected_duration_seconds ,
183
+ ):
184
+ """Check that using begin_stream_seconds_from_content and end_stream_seconds_from_content to calculate `.duration_seconds`
185
+ has priority. If either value is missing, duration_seconds_from_header is used.
186
+ """
187
+ metadata = VideoStreamMetadata (
188
+ duration_seconds_from_header = duration_seconds_from_header ,
189
+ bit_rate = 123 ,
190
+ num_frames_from_header = 5 ,
191
+ num_frames_from_content = 10 ,
192
+ begin_stream_seconds_from_header = 0 ,
193
+ begin_stream_seconds_from_content = begin_stream_seconds_from_content ,
194
+ end_stream_seconds_from_content = end_stream_seconds_from_content ,
195
+ codec = "whatever" ,
196
+ width = 123 ,
197
+ height = 321 ,
198
+ average_fps_from_header = 5 ,
199
+ stream_index = 0 ,
200
+ )
201
+
202
+ assert metadata .duration_seconds == expected_duration_seconds
203
+
204
+
205
+ @pytest .mark .parametrize (
206
+ "num_frames_from_header, average_fps_from_header, expected_duration_seconds" ,
207
+ [(100 , 10 , 10 ), (100 , None , None ), (None , 10 , None ), (None , None , None )],
208
+ )
209
+ def test_calculate_duration_seconds_using_fps_and_num_frames (
210
+ num_frames_from_header , average_fps_from_header , expected_duration_seconds
211
+ ):
212
+ """Check that duration_seconds is calculated using average_fps_from_header and num_frames_from_header
213
+ if duration_seconds_from_header is missing.
214
+ """
215
+ metadata = VideoStreamMetadata (
216
+ duration_seconds_from_header = None , # None to test calculating duration_seconds
217
+ bit_rate = 123 ,
218
+ num_frames_from_header = num_frames_from_header ,
219
+ num_frames_from_content = 10 ,
220
+ begin_stream_seconds_from_header = 0 ,
221
+ begin_stream_seconds_from_content = None , # None to test calculating duration_seconds
222
+ end_stream_seconds_from_content = None , # None to test calculating duration_seconds
223
+ codec = "whatever" ,
224
+ width = 123 ,
225
+ height = 321 ,
226
+ average_fps_from_header = average_fps_from_header ,
227
+ stream_index = 0 ,
228
+ )
229
+ assert metadata .duration_seconds_from_header is None
230
+ assert metadata .duration_seconds == expected_duration_seconds
231
+
232
+
146
233
def test_repr ():
147
234
# Test for calls to print(), str(), etc. Useful to make sure we don't forget
148
235
# to add additional @properties to __repr__
0 commit comments