33import os
44import subprocess
55import timeit
6- from concurrent .futures import ThreadPoolExecutor
6+ from concurrent .futures import ThreadPoolExecutor , wait
77from itertools import product
88
99import matplotlib .pyplot as plt
@@ -306,6 +306,7 @@ def generate_video(command):
306306 print (command )
307307 print (" " .join (command ))
308308 subprocess .check_call (command )
309+ return True
309310
310311
311312def generate_videos (
@@ -321,6 +322,7 @@ def generate_videos(
321322 executor = ThreadPoolExecutor (max_workers = 20 )
322323 video_count = 0
323324
325+ futures = []
324326 for resolution , duration , fps , gop_size , encoding , pix_fmt in product (
325327 resolutions , durations , fpses , gop_sizes , encodings , pix_fmts
326328 ):
@@ -342,9 +344,12 @@ def generate_videos(
342344 pix_fmt ,
343345 outfile ,
344346 ]
345- executor .submit (generate_video , command )
347+ futures . append ( executor .submit (generate_video , command ) )
346348 video_count += 1
347349
350+ wait (futures )
351+ for f in futures :
352+ assert f .result ()
348353 executor .shutdown (wait = True )
349354 print (f"Generated { video_count } videos" )
350355
@@ -442,21 +447,21 @@ def plot_data(df_data, plot_path):
442447
443448def run_benchmarks (
444449 decoder_dict ,
445- video_paths ,
450+ video_files_paths ,
446451 num_uniform_samples ,
447452 min_runtime_seconds ,
448453 benchmark_video_creation ,
449454):
450455 results = []
451456 df_data = []
452- print (f"video_paths= { video_paths } " )
457+ print (f"video_files_paths= { video_files_paths } " )
453458 verbose = False
454459 for decoder_name , decoder in decoder_dict .items ():
455- for video_path in video_paths :
456- print (f"video={ video_path } , decoder={ decoder_name } " )
460+ for video_file_path in video_files_paths :
461+ print (f"video={ video_file_path } , decoder={ decoder_name } " )
457462 # We only use the VideoDecoder to get the metadata and get
458463 # the list of PTS values to seek to.
459- simple_decoder = VideoDecoder (video_path )
464+ simple_decoder = VideoDecoder (video_file_path )
460465 duration = simple_decoder .metadata .duration_seconds
461466 pts_list = [
462467 i * duration / num_uniform_samples for i in range (num_uniform_samples )
@@ -465,16 +470,16 @@ def run_benchmarks(
465470 metadata_string = f"{ metadata .codec } { metadata .width } x{ metadata .height } , { metadata .duration_seconds } s { metadata .average_fps } fps"
466471 if verbose :
467472 print (
468- f"video={ video_path } , decoder={ decoder_name } , pts_list={ pts_list } "
473+ f"video={ video_file_path } , decoder={ decoder_name } , pts_list={ pts_list } "
469474 )
470475 seeked_result = benchmark .Timer (
471476 stmt = "decoder.get_frames_from_video(video_file, pts_list)" ,
472477 globals = {
473- "video_file" : video_path ,
478+ "video_file" : video_file_path ,
474479 "pts_list" : pts_list ,
475480 "decoder" : decoder ,
476481 },
477- label = f"video={ video_path } { metadata_string } " ,
482+ label = f"video={ video_file_path } { metadata_string } " ,
478483 sub_label = decoder_name ,
479484 description = f"{ num_uniform_samples } seek()+next()" ,
480485 )
@@ -483,7 +488,7 @@ def run_benchmarks(
483488 )
484489 df_item = {}
485490 df_item ["decoder" ] = decoder_name
486- df_item ["video" ] = video_path
491+ df_item ["video" ] = video_file_path
487492 df_item ["description" ] = results [- 1 ].description
488493 df_item ["frame_count" ] = num_uniform_samples
489494 df_item ["median" ] = results [- 1 ].median
@@ -498,11 +503,11 @@ def run_benchmarks(
498503 consecutive_frames_result = benchmark .Timer (
499504 stmt = "decoder.get_consecutive_frames_from_video(video_file, consecutive_frames_to_extract)" ,
500505 globals = {
501- "video_file" : video_path ,
506+ "video_file" : video_file_path ,
502507 "consecutive_frames_to_extract" : num_consecutive_nexts ,
503508 "decoder" : decoder ,
504509 },
505- label = f"video={ video_path } { metadata_string } " ,
510+ label = f"video={ video_file_path } { metadata_string } " ,
506511 sub_label = decoder_name ,
507512 description = f"{ num_consecutive_nexts } next()" ,
508513 )
@@ -513,7 +518,7 @@ def run_benchmarks(
513518 )
514519 df_item = {}
515520 df_item ["decoder" ] = decoder_name
516- df_item ["video" ] = video_path
521+ df_item ["video" ] = video_file_path
517522 df_item ["description" ] = results [- 1 ].description
518523 df_item ["frame_count" ] = num_consecutive_nexts
519524 df_item ["median" ] = results [- 1 ].median
@@ -524,18 +529,18 @@ def run_benchmarks(
524529 df_item ["fps_p25" ] = 1.0 * num_consecutive_nexts / results [- 1 ]._p25
525530 df_data .append (df_item )
526531
527- first_video_path = video_paths [0 ]
532+ first_video_file_path = video_files_paths [0 ]
528533 if benchmark_video_creation :
529- simple_decoder = VideoDecoder (first_video_path )
534+ simple_decoder = VideoDecoder (first_video_file_path )
530535 metadata = simple_decoder .metadata
531536 metadata_string = f"{ metadata .codec } { metadata .width } x{ metadata .height } , { metadata .duration_seconds } s { metadata .average_fps } fps"
532537 creation_result = benchmark .Timer (
533538 stmt = "create_torchcodec_decoder_from_file(video_file)" ,
534539 globals = {
535- "video_file" : first_video_path ,
540+ "video_file" : first_video_file_path ,
536541 "create_torchcodec_decoder_from_file" : create_torchcodec_decoder_from_file ,
537542 },
538- label = f"video={ first_video_path } { metadata_string } " ,
543+ label = f"video={ first_video_file_path } { metadata_string } " ,
539544 sub_label = "TorchcodecNonCompiled" ,
540545 description = "create()+next()" ,
541546 )
0 commit comments