Skip to content

Commit 103f714

Browse files
authored
pytorch/torchcodec - 3.12 fixes
Differential Revision: D77327183 Pull Request resolved: #744
1 parent e654189 commit 103f714

File tree

1 file changed

+27
-20
lines changed

1 file changed

+27
-20
lines changed

test/test_ops.py

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
# This source code is licensed under the BSD-style license found in the
55
# LICENSE file in the root directory of this source tree.
66

7+
import contextlib
78
import io
89
import os
910
from functools import partial
@@ -555,11 +556,7 @@ def test_color_conversion_library_with_dimension_order(
555556
def test_color_conversion_library_with_generated_videos(
556557
self, tmp_path, width, height, width_scaling_factor, height_scaling_factor
557558
):
558-
ffmpeg_cli = "ffmpeg"
559-
if os.environ.get("IN_FBCODE_TORCHCODEC") == "1":
560-
import importlib.resources
561559

562-
ffmpeg_cli = importlib.resources.path(__package__, "ffmpeg")
563560
# We consider filtergraph to be the reference color conversion library.
564561
# However the video decoder sometimes uses swscale as that is faster.
565562
# The exact color conversion library used is an implementation detail
@@ -573,22 +570,32 @@ def test_color_conversion_library_with_generated_videos(
573570
# We don't specify a particular encoder because the ffmpeg binary could
574571
# be configured with different encoders. For the purposes of this test,
575572
# 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)
592599

593600
decoder = create_from_file(str(video_path))
594601
add_video_stream(decoder)

0 commit comments

Comments
 (0)