Skip to content

Commit d84775a

Browse files
eromomondvrogozhNicolasHug
authored
Tests: fix tests if running with self-built ffmpeg (#812)
Co-authored-by: Dmitry Rogozhkin <[email protected]> Co-authored-by: Nicolas Hug <[email protected]>
1 parent 1ec5666 commit d84775a

File tree

3 files changed

+12
-5
lines changed

3 files changed

+12
-5
lines changed

src/torchcodec/_core/custom_ops.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -656,6 +656,10 @@ std::string get_stream_json_metadata(
656656

657657
// Returns version information about the various FFMPEG libraries that are
658658
// loaded in the program's address space.
659+
// TODO: ideally we'd have a more robust way of getting the ffmpeg version,
660+
// we're using av_version_info() which is not standardized and shouldn't be
661+
// parsed by code (which we do!). See
662+
// https://github.com/pytorch/torchcodec/issues/100
659663
std::string _get_json_ffmpeg_library_versions() {
660664
std::stringstream ss;
661665
ss << "{\n";

test/test_metadata.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
create_from_file,
1616
get_container_metadata,
1717
get_container_metadata_from_header,
18-
get_ffmpeg_library_versions,
1918
VideoStreamMetadata,
2019
)
2120
from torchcodec.decoders import AudioDecoder, VideoDecoder
@@ -78,9 +77,7 @@ def test_get_metadata(metadata_getter):
7877
with pytest.raises(NotImplementedError, match="Decide on logic"):
7978
metadata.bit_rate
8079

81-
ffmpeg_major_version = int(
82-
get_ffmpeg_library_versions()["ffmpeg_version"].split(".")[0]
83-
)
80+
ffmpeg_major_version = get_ffmpeg_major_version()
8481
if ffmpeg_major_version <= 5:
8582
expected_duration_seconds_from_header = 16.57
8683
expected_bit_rate_from_header = 324915

test/utils.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,13 @@ def cpu_and_cuda():
2828

2929

3030
def get_ffmpeg_major_version():
31-
return int(get_ffmpeg_library_versions()["ffmpeg_version"].split(".")[0])
31+
ffmpeg_version = get_ffmpeg_library_versions()["ffmpeg_version"]
32+
# When building FFmpeg from source there can be a `n` prefix in the version
33+
# string. This is quite brittle as we're using av_version_info(), which has
34+
# no stable format. See https://github.com/pytorch/torchcodec/issues/100
35+
if ffmpeg_version.startswith("n"):
36+
ffmpeg_version = ffmpeg_version.removeprefix("n")
37+
return int(ffmpeg_version.split(".")[0])
3238

3339

3440
# For use with decoded data frames. On CPU Linux, we expect exact, bit-for-bit

0 commit comments

Comments
 (0)