@@ -325,16 +325,30 @@ def __iter__(self):
325
325
return self ._decode (container )
326
326
327
327
def get_progress (self , pos ):
328
- container = self ._get_av_container ()
329
- # Not for all containers return real value
330
- stream = container .streams .video [0 ]
331
- return pos / stream .duration if stream .duration else None
328
+ duration = self ._get_duration ()
329
+ return pos / duration if duration else None
332
330
333
331
def _get_av_container (self ):
334
332
if isinstance (self ._source_path [0 ], io .BytesIO ):
335
333
self ._source_path [0 ].seek (0 ) # required for re-reading
336
334
return av .open (self ._source_path [0 ])
337
335
336
+ def _get_duration (self ):
337
+ container = self ._get_av_container ()
338
+ stream = container .streams .video [0 ]
339
+ duration = None
340
+ if stream .duration :
341
+ duration = stream .duration
342
+ else :
343
+ # may have a DURATION in format like "01:16:45.935000000"
344
+ duration_str = stream .metadata .get ("DURATION" , None )
345
+ tb_denominator = stream .time_base .denominator
346
+ if duration_str and tb_denominator :
347
+ _hour , _min , _sec = duration_str .split (':' )
348
+ duration_sec = 60 * 60 * float (_hour ) + 60 * float (_min ) + float (_sec )
349
+ duration = duration_sec * tb_denominator
350
+ return duration
351
+
338
352
def get_preview (self ):
339
353
container = self ._get_av_container ()
340
354
stream = container .streams .video [0 ]
0 commit comments