@@ -343,15 +343,9 @@ def subtitle(
343
343
for packet in container .demux (subtitle_stream ):
344
344
if packet .pts is None or packet .duration is None :
345
345
continue
346
- for subset in packet .decode ():
347
- # See definition of `AVSubtitle`
348
- # in: https://ffmpeg.org/doxygen/trunk/avcodec_8h_source.html
349
- start = float (packet .pts * subtitle_stream .time_base )
350
- dur = float (packet .duration * subtitle_stream .time_base )
351
-
352
- end = round ((start + dur ) * self .tb )
353
- sub_length = max (sub_length , end )
346
+ sub_length = max (sub_length , packet .pts + packet .duration )
354
347
348
+ sub_length = round (sub_length * subtitle_stream .time_base * self .tb )
355
349
result = np .zeros ((sub_length ), dtype = np .bool_ )
356
350
del sub_length
357
351
@@ -363,25 +357,25 @@ def subtitle(
363
357
continue
364
358
if early_exit :
365
359
break
366
- for subset in packet .decode ():
367
- if max_count is not None and count >= max_count :
368
- early_exit = True
369
- break
370
360
371
- start = float (packet .pts * subtitle_stream .time_base )
372
- dur = float (packet .duration * subtitle_stream .time_base )
361
+ if max_count is not None and count >= max_count :
362
+ early_exit = True
363
+ break
364
+
365
+ start = float (packet .pts * subtitle_stream .time_base )
366
+ dur = float (packet .duration * subtitle_stream .time_base )
373
367
374
- san_start = round (start * self .tb )
375
- san_end = round ((start + dur ) * self .tb )
368
+ san_start = round (start * self .tb )
369
+ san_end = round ((start + dur ) * self .tb )
376
370
377
- for sub in subset :
378
- if not isinstance (sub , AssSubtitle ):
379
- continue
371
+ for sub in packet . decode () :
372
+ if not isinstance (sub , AssSubtitle ):
373
+ continue
380
374
381
- line = sub .dialogue .decode (errors = "ignore" )
382
- if line and re .search (re_pattern , line ):
383
- result [san_start :san_end ] = 1
384
- count += 1
375
+ line = sub .dialogue .decode (errors = "ignore" )
376
+ if line and re .search (re_pattern , line ):
377
+ result [san_start :san_end ] = 1
378
+ count += 1
385
379
386
380
container .seek (0 )
387
381
return result
0 commit comments