4
4
# This source code is licensed under the BSD-style license found in the
5
5
# LICENSE file in the root directory of this source tree.
6
6
7
+ import contextlib
7
8
import io
8
9
import os
9
10
from functools import partial
@@ -555,11 +556,7 @@ def test_color_conversion_library_with_dimension_order(
555
556
def test_color_conversion_library_with_generated_videos (
556
557
self , tmp_path , width , height , width_scaling_factor , height_scaling_factor
557
558
):
558
- ffmpeg_cli = "ffmpeg"
559
- if os .environ .get ("IN_FBCODE_TORCHCODEC" ) == "1" :
560
- import importlib .resources
561
559
562
- ffmpeg_cli = importlib .resources .path (__package__ , "ffmpeg" )
563
560
# We consider filtergraph to be the reference color conversion library.
564
561
# However the video decoder sometimes uses swscale as that is faster.
565
562
# The exact color conversion library used is an implementation detail
@@ -573,22 +570,32 @@ def test_color_conversion_library_with_generated_videos(
573
570
# We don't specify a particular encoder because the ffmpeg binary could
574
571
# be configured with different encoders. For the purposes of this test,
575
572
# the actual encoder is irrelevant.
576
- command = [
577
- ffmpeg_cli ,
578
- "-y" ,
579
- "-f" ,
580
- "lavfi" ,
581
- "-i" ,
582
- "color=blue" ,
583
- "-pix_fmt" ,
584
- "yuv420p" ,
585
- "-s" ,
586
- f"{ width } x{ height } " ,
587
- "-frames:v" ,
588
- "1" ,
589
- video_path ,
590
- ]
591
- subprocess .check_call (command )
573
+ with contextlib .ExitStack () as stack :
574
+ ffmpeg_cli = "ffmpeg"
575
+
576
+ if os .environ .get ("IN_FBCODE_TORCHCODEC" ) == "1" :
577
+ import importlib .resources
578
+
579
+ ffmpeg_cli = stack .enter_context (
580
+ importlib .resources .path (__package__ , "ffmpeg" )
581
+ )
582
+
583
+ command = [
584
+ ffmpeg_cli ,
585
+ "-y" ,
586
+ "-f" ,
587
+ "lavfi" ,
588
+ "-i" ,
589
+ "color=blue" ,
590
+ "-pix_fmt" ,
591
+ "yuv420p" ,
592
+ "-s" ,
593
+ f"{ width } x{ height } " ,
594
+ "-frames:v" ,
595
+ "1" ,
596
+ video_path ,
597
+ ]
598
+ subprocess .check_call (command )
592
599
593
600
decoder = create_from_file (str (video_path ))
594
601
add_video_stream (decoder )
0 commit comments