From ad60c0e2514551406b849f2caf06d74a41b7c1e2 Mon Sep 17 00:00:00 2001 From: Edgar Romo Montiel Date: Fri, 8 Aug 2025 14:38:39 -0700 Subject: [PATCH 1/3] Tests: fix tests if running with self-built ffmpeg If self-building ffmpeg from the tag for development reasons, it's version is set as `n6.1.2` (with n-prefix). This causes failures in the torchcodec tests. This patch handles such a case accounting for the `n6.1.2` ffmpeg version format. Co-authored-by: Dmitry Rogozhkin Signed-off-by: Edgar Romo Montiel --- test/test_metadata.py | 4 +--- test/utils.py | 5 ++++- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/test/test_metadata.py b/test/test_metadata.py index 9f6b91ca7..7da45f18e 100644 --- a/test/test_metadata.py +++ b/test/test_metadata.py @@ -78,9 +78,7 @@ def test_get_metadata(metadata_getter): with pytest.raises(NotImplementedError, match="Decide on logic"): metadata.bit_rate - ffmpeg_major_version = int( - get_ffmpeg_library_versions()["ffmpeg_version"].split(".")[0] - ) + ffmpeg_major_version = get_ffmpeg_major_version() if ffmpeg_major_version <= 5: expected_duration_seconds_from_header = 16.57 expected_bit_rate_from_header = 324915 diff --git a/test/utils.py b/test/utils.py index be9eb847d..517100ebf 100644 --- a/test/utils.py +++ b/test/utils.py @@ -28,7 +28,10 @@ def cpu_and_cuda(): def get_ffmpeg_major_version(): - return int(get_ffmpeg_library_versions()["ffmpeg_version"].split(".")[0]) + ffmpeg_version = get_ffmpeg_library_versions()["ffmpeg_version"] + if ffmpeg_version.startswith("n"): + ffmpeg_version = ffmpeg_version.removeprefix("n") + return int(ffmpeg_version.split(".")[0]) # For use with decoded data frames. On CPU Linux, we expect exact, bit-for-bit From e0039873e8c784d32f7f8bc5ebd992e757b750dd Mon Sep 17 00:00:00 2001 From: Edgar Romo Montiel Date: Tue, 12 Aug 2025 12:48:55 -0700 Subject: [PATCH 2/3] remove unused import --- test/test_metadata.py | 1 - 1 file changed, 1 deletion(-) diff --git a/test/test_metadata.py b/test/test_metadata.py index 7da45f18e..bf1419a00 100644 --- a/test/test_metadata.py +++ b/test/test_metadata.py @@ -15,7 +15,6 @@ create_from_file, get_container_metadata, get_container_metadata_from_header, - get_ffmpeg_library_versions, VideoStreamMetadata, ) from torchcodec.decoders import AudioDecoder, VideoDecoder From a1458a98a33a06b043a4b067357fc1d4bd3a4c9e Mon Sep 17 00:00:00 2001 From: Edgar Romo Montiel Date: Wed, 13 Aug 2025 12:02:24 -0700 Subject: [PATCH 3/3] Add required comments to test/utils.py and src/torchcodec/_core/custom_ops.cpp files Co-authored-by: Nicolas Hug Signed-off-by: Edgar Romo Montiel --- src/torchcodec/_core/custom_ops.cpp | 4 ++++ test/utils.py | 3 +++ 2 files changed, 7 insertions(+) diff --git a/src/torchcodec/_core/custom_ops.cpp b/src/torchcodec/_core/custom_ops.cpp index daec2010e..0e446a24e 100644 --- a/src/torchcodec/_core/custom_ops.cpp +++ b/src/torchcodec/_core/custom_ops.cpp @@ -656,6 +656,10 @@ std::string get_stream_json_metadata( // Returns version information about the various FFMPEG libraries that are // loaded in the program's address space. +// TODO: ideally we'd have a more robust way of getting the ffmpeg version, +// we're using av_version_info() which is not standardized and shouldn't be +// parsed by code (which we do!). See +// https://github.com/pytorch/torchcodec/issues/100 std::string _get_json_ffmpeg_library_versions() { std::stringstream ss; ss << "{\n"; diff --git a/test/utils.py b/test/utils.py index 517100ebf..c258ac440 100644 --- a/test/utils.py +++ b/test/utils.py @@ -29,6 +29,9 @@ def cpu_and_cuda(): def get_ffmpeg_major_version(): ffmpeg_version = get_ffmpeg_library_versions()["ffmpeg_version"] + # When building FFmpeg from source there can be a `n` prefix in the version + # string. This is quite brittle as we're using av_version_info(), which has + # no stable format. See https://github.com/pytorch/torchcodec/issues/100 if ffmpeg_version.startswith("n"): ffmpeg_version = ffmpeg_version.removeprefix("n") return int(ffmpeg_version.split(".")[0])