@@ -189,7 +189,7 @@ def __repr__(self) -> str:
189
189
return f"@{ self .path .name } "
190
190
191
191
192
- def initFileInfo (path : str , ffmpeg : FFmpeg , log : Log ) -> FileInfo :
192
+ def initFileInfo (path : str , log : Log ) -> FileInfo :
193
193
import av
194
194
195
195
av .logging .set_level (av .logging .PANIC )
@@ -203,52 +203,20 @@ def initFileInfo(path: str, ffmpeg: FFmpeg, log: Log) -> FileInfo:
203
203
audios : tuple [AudioStream , ...] = ()
204
204
subtitles : tuple [SubtitleStream , ...] = ()
205
205
206
- _dir = os .path .dirname (ffmpeg .path )
207
- _ext = os .path .splitext (ffmpeg .path )[1 ]
208
- ffprobe = os .path .join (_dir , f"ffprobe{ _ext } " )
209
-
210
- for i , v in enumerate (cont .streams .video ):
211
- vdur = 0.0
206
+ for v in cont .streams .video :
212
207
if v .duration is not None and v .time_base is not None :
213
208
vdur = float (v .duration * v .time_base )
209
+ else :
210
+ vdur = 0.0
214
211
215
212
fps = v .average_rate
216
213
if (fps is None or fps < 1 ) and v .name in ("png" , "mjpeg" , "webp" ):
217
214
fps = Fraction (25 )
218
215
if fps is None or fps == 0 :
219
216
fps = Fraction (30 )
220
217
221
- _sar = c_range = c_space = c_primary = c_transfer = None
222
- try :
223
- _raw = get_stdout (
224
- [
225
- ffprobe ,
226
- "-v" ,
227
- "error" ,
228
- "-select_streams" ,
229
- f"v:{ i } " ,
230
- "-show_entries" ,
231
- "stream=sample_aspect_ratio:stream=color_range:stream=color_space:stream=color_primaries:stream=color_transfer" ,
232
- "-of" ,
233
- "default=noprint_wrappers=1:nokey=1" ,
234
- path ,
235
- ]
236
- )
237
- _sar , c_range , c_space , c_primary , c_transfer = _raw .strip ().split ("\n " )
238
- except Exception :
239
- log .debug ("Unexpected ffprobe shape" )
240
-
241
- if v .sample_aspect_ratio is None :
242
- if _sar is None :
243
- sar = Fraction (1 )
244
- else :
245
- try :
246
- sar = Fraction (_sar .replace (":" , "/" ))
247
- except Exception :
248
- sar = Fraction (1 )
249
- else :
250
- sar = v .sample_aspect_ratio
251
-
218
+ sar = Fraction (1 ) if v .sample_aspect_ratio is None else v .sample_aspect_ratio
219
+ cc = v .codec_context
252
220
videos += (
253
221
VideoStream (
254
222
v .width ,
@@ -258,11 +226,11 @@ def initFileInfo(path: str, ffmpeg: FFmpeg, log: Log) -> FileInfo:
258
226
vdur ,
259
227
sar ,
260
228
v .time_base ,
261
- v . codec_context .pix_fmt ,
262
- v .color_range ,
263
- v .colorspace ,
264
- v .color_primaries ,
265
- v .color_trc ,
229
+ cc .pix_fmt ,
230
+ cc .color_range ,
231
+ cc .colorspace ,
232
+ cc .color_primaries ,
233
+ cc .color_trc ,
266
234
0 if v .bit_rate is None else v .bit_rate ,
267
235
v .language ,
268
236
),
@@ -273,13 +241,14 @@ def initFileInfo(path: str, ffmpeg: FFmpeg, log: Log) -> FileInfo:
273
241
if a .duration is not None and a .time_base is not None :
274
242
adur = float (a .duration * a .time_base )
275
243
244
+ a_cc = a .codec_context
276
245
audios += (
277
246
AudioStream (
278
- a . codec_context .name ,
279
- 0 if a .sample_rate is None else a .sample_rate ,
280
- a .channels ,
247
+ a_cc .name ,
248
+ 0 if a_cc .sample_rate is None else a_cc .sample_rate ,
249
+ a_cc .channels ,
281
250
adur ,
282
- 0 if a .bit_rate is None else a .bit_rate ,
251
+ 0 if a_cc .bit_rate is None else a_cc .bit_rate ,
283
252
a .language ,
284
253
),
285
254
)
0 commit comments