_________________________________________________________________________________ TestVideoEncoder.test_video_encoder_against_ffmpeg_cli[29.97-to_tensor-encode_params0-mp4] _________________________________________________________________________________
[gw0] freebsd15 -- Python 3.11.14 /usr/local/bin/python3.11
self = <test.test_encoders.TestVideoEncoder object at 0x33413eb34650>, tmp_path = PosixPath('/tmp/pytest-of-yuri/pytest-21/popen-gw0/test_video_encoder_against_ffm97'), format = 'mp4', encode_params = {'crf': 0, 'pixel_format': 'yuv444p', 'preset': None}
method = 'to_tensor', frame_rate = 29.97
@needs_ffmpeg_cli
@pytest.mark.parametrize(
"format",
(
"mov",
"mp4",
"avi",
"mkv",
"flv",
pytest.param(
"webm",
marks=[
pytest.mark.slow,
pytest.mark.skipif(
get_ffmpeg_major_version() == 4
or (IS_WINDOWS and get_ffmpeg_major_version() in (6, 7)),
reason="Codec for webm is not available in this FFmpeg installation.",
),
],
),
),
)
@pytest.mark.parametrize(
"encode_params",
[
{"pixel_format": "yuv444p", "crf": 0, "preset": None},
{"pixel_format": "yuv420p", "crf": 30, "preset": None},
{"pixel_format": "yuv420p", "crf": None, "preset": "ultrafast"},
{"pixel_format": "yuv420p", "crf": None, "preset": None},
],
)
@pytest.mark.parametrize("method", ("to_file", "to_tensor", "to_file_like"))
@pytest.mark.parametrize("frame_rate", [30, 29.97])
def test_video_encoder_against_ffmpeg_cli(
self, tmp_path, format, encode_params, method, frame_rate
):
pixel_format = encode_params["pixel_format"]
crf = encode_params["crf"]
preset = encode_params["preset"]
ffmpeg_version = get_ffmpeg_major_version()
if format in ("avi", "flv") and pixel_format == "yuv444p":
pytest.skip(f"Default codec for {format} does not support {pixel_format}")
source_frames = self.decode(TEST_SRC_2_720P.path)
# Encode with FFmpeg CLI
temp_raw_path = str(tmp_path / "temp_input.raw")
with open(temp_raw_path, "wb") as f:
f.write(source_frames.permute(0, 2, 3, 1).cpu().numpy().tobytes())
ffmpeg_encoded_path = str(tmp_path / f"ffmpeg_output.{format}")
# Some codecs (ex. MPEG4) do not support CRF or preset.
# Flags not supported by the selected codec will be ignored.
ffmpeg_cmd = [
"ffmpeg",
"-y",
"-f",
"rawvideo",
"-pix_fmt",
"rgb24", # Input format
"-s",
f"{source_frames.shape[3]}x{source_frames.shape[2]}",
"-r",
str(frame_rate),
"-i",
temp_raw_path,
]
if pixel_format is not None: # Output format
ffmpeg_cmd.extend(["-pix_fmt", pixel_format])
if preset is not None:
ffmpeg_cmd.extend(["-preset", preset])
if crf is not None:
ffmpeg_cmd.extend(["-crf", str(crf)])
# Output path must be last
ffmpeg_cmd.append(ffmpeg_encoded_path)
subprocess.run(ffmpeg_cmd, check=True)
ffmpeg_frames = self.decode(ffmpeg_encoded_path).data
# Encode with our video encoder
encoder = VideoEncoder(frames=source_frames, frame_rate=frame_rate)
encoder_output_path = str(tmp_path / f"encoder_output.{format}")
if method == "to_file":
encoder.to_file(
dest=encoder_output_path,
pixel_format=pixel_format,
crf=crf,
preset=preset,
)
encoder_frames = self.decode(encoder_output_path)
elif method == "to_tensor":
> encoded_output = encoder.to_tensor(
format=format,
pixel_format=pixel_format,
crf=crf,
preset=preset,
)
test/test_encoders.py:1116:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
../stage/usr/local/lib/python3.11/site-packages/torchcodec/encoders/_video_encoder.py:128: in to_tensor
return _core.encode_video_to_tensor(
/usr/local/lib/python3.11/site-packages/torch/_ops.py:819: in __call__
return self._op(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^
/usr/local/lib/python3.11/site-packages/torch/utils/_device.py:109: in __torch_function__
return func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <OpOverload(op='torchcodec_ns.encode_video_to_tensor', overload='default')>, args = (), kwargs = {'codec': None, 'crf': 0, 'extra_options': [], 'format': 'mp4', ...}
def __call__(self, /, *args: _P.args, **kwargs: _P.kwargs) -> _T:
> return self._op(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^
E RuntimeError: Invalid AVIO context holder.
/usr/local/lib/python3.11/site-packages/torch/_ops.py:819: RuntimeError
-------------------------------------------------------------------------------------------------------------------- Captured stderr call --------------------------------------------------------------------------------------------------------------------
ffmpeg version 8.0.1 Copyright (c) 2000-2025 the FFmpeg developers
built with FreeBSD clang version 19.1.7 (https://github.com/llvm/llvm-project.git llvmorg-19.1.7-0-gcd708029e0b2)
configuration: --prefix=/usr/local --mandir=/usr/local/share/man --datadir=/usr/local/share/ffmpeg --docdir=/usr/local/share/doc/ffmpeg --pkgconfigdir=/usr/local/libdata/pkgconfig --disable-static --disable-libcelt --disable-mbedtls --enable-shared --enable-pic --enable-gpl --cc=cc --cxx=c++ --disable-alsa --disable-libopencore-amrnb --disable-libopencore-amrwb --enable-libaom --disable-libaribb24 --enable-asm --enable-libass --disable-libbs2b --disable-libcaca --disable-libcdio --disable-libcodec2 --enable-libdav1d --disable-libdc1394 --disable-debug --enable-htmlpages --enable-libdrm --enable-libdvdnav --enable-libdvdread --disable-libfdk-aac --disable-libflite --enable-fontconfig --enable-libfreetype --enable-frei0r --disable-libfribidi --disable-gcrypt --disable-libglslang --disable-libgme --enable-gmp --enable-gnutls --enable-version3 --disable-libgsm --enable-libharfbuzz --enable-iconv --disable-libilbc --disable-libjack --enable-libjxl --disable-libkvazaar --disable-ladspa --enable-libmp3lame --enable-lcms2 --disable-liblensfun --enable-libbluray --enable-libplacebo --enable-librsvg --enable-libxml2 --enable-lto --disable-lv2 --disable-libmfx --disable-libmodplug --disable-libmysofa --enable-network --disable-nonfree --enable-cuvid --enable-nvdec --enable-nvenc --disable-openal --disable-opencl --disable-opengl --disable-libopenh264 --disable-libopenjpeg --disable-libopenmpt --disable-openssl --enable-optimizations --enable-libopus --disable-pocketsphinx --disable-libpulse --disable-librabbitmq --disable-librav1e --disable-librist --enable-runtime-cpudetect --disable-librubberband --disable-sdl2 --enable-libshaderc --disable-libsmbclient --disable-libsnappy --disable-sndio --disable-libsoxr --disable-libspeex --enable-libsrt --disable-libssh --enable-libsvtav1 --disable-libtensorflow --disable-libtesseract --disable-libtheora --disable-libtwolame --enable-libv4l2 --enable-vaapi --disable-vapoursynth --enable-vdpau --disable-libvidstab --enable-libvmaf --enable-libvorbis --disable-libvo-amrwbenc --disable-libvpl --enable-libvpx --enable-vulkan --disable-libvvenc --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxcb --enable-libxcb-shape --enable-libxcb-shm --enable-libxcb-xfixes --enable-xlib --disable-libxvid --disable-outdev=xv --disable-libzimg --disable-libzmq --disable-libzvbi --disable-xlib
libavutil 60. 8.100 / 60. 8.100
libavcodec 62. 11.100 / 62. 11.100
libavformat 62. 3.100 / 62. 3.100
libavdevice 62. 1.100 / 62. 1.100
libavfilter 11. 4.100 / 11. 4.100
libswscale 9. 1.100 / 9. 1.100
libswresample 6. 1.100 / 6. 1.100
[rawvideo @ 0x2643cf08e280] Estimating duration from bitrate, this may be inaccurate
Input #0, rawvideo, from '/tmp/pytest-of-yuri/pytest-21/popen-gw0/test_video_encoder_against_ffm97/temp_input.raw':
Duration: 00:00:01.00, start: 0.000000, bitrate: 662888 kb/s
Stream #0:0: Video: rawvideo (RGB[24] / 0x18424752), rgb24, 1280x720, 662888 kb/s, 29.97 tbr, 29.97 tbn
Stream mapping:
Stream #0:0 -> #0:0 (rawvideo (native) -> h264 (libx264))
Press [q] to stop, [?] for help
[libx264 @ 0x2643cf01aa80] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 BMI2 AVX2 AVX512
[libx264 @ 0x2643cf01aa80] profile High 4:4:4 Predictive, level 3.1, 4:4:4, 8-bit
[libx264 @ 0x2643cf01aa80] 64 - core 164 - H.264/MPEG-4 AVC codec - Copyleft 2003-2022 - http://www.videolan.org/x264.html - options: cabac=1 ref=3 deblock=1:0:0 analyse=0x3:0x113 me=hex subme=7 psy=0 mixed_ref=1 me_range=16 chroma_me=1 trellis=0 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=0 chroma_qp_offset=0 threads=22 lookahead_threads=3 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=0 weightp=2 keyint=250 keyint_min=25 scenecut=40 intra_refresh=0 rc=cqp mbtree=0 qp=0
Output #0, mp4, to '/tmp/pytest-of-yuri/pytest-21/popen-gw0/test_video_encoder_against_ffm97/ffmpeg_output.mp4':
Metadata:
encoder : Lavf62.3.100
Stream #0:0: Video: h264 (avc1 / 0x31637661), yuv444p(tv, progressive), 1280x720, q=2-31, 29.97 fps, 11988 tbn
Metadata:
encoder : Lavc62.11.100 libx264
Side data:
cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: N/A
[out#0/mp4 @ 0x2643cf0af700] video:2925KiB audio:0KiB subtitle:0KiB other streams:0KiB global headers:0KiB muxing overhead: 0.032349%
frame= 30 fps=0.0 q=-1.0 Lsize= 2926KiB time=00:00:01.00 bitrate=23947.1kbits/s speed=5.65x elapsed=0:00:00.17
[libx264 @ 0x2643cf01aa80] frame I:1 Avg QP: 0.00 size:111478
[libx264 @ 0x2643cf01aa80] frame P:29 Avg QP: 0.00 size: 99428
[libx264 @ 0x2643cf01aa80] mb I I16..4..PCM: 86.9% 7.1% 5.9% 0.0%
[libx264 @ 0x2643cf01aa80] mb P I16..4..PCM: 6.9% 0.6% 1.0% 0.0% P16..4: 4.5% 1.9% 2.0% 0.0% 0.0% skip:83.0%
[libx264 @ 0x2643cf01aa80] 8x8 transform intra:7.1% inter:13.3%
[libx264 @ 0x2643cf01aa80] coded y,u,v intra: 37.7% 38.8% 38.9% inter: 5.7% 5.7% 5.7%
[libx264 @ 0x2643cf01aa80] i16 v,h,dc,p: 79% 20% 0% 0%
[libx264 @ 0x2643cf01aa80] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 37% 22% 37% 2% 0% 0% 0% 1% 0%
[libx264 @ 0x2643cf01aa80] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 44% 44% 6% 1% 1% 1% 1% 1% 1%
[libx264 @ 0x2643cf01aa80] Weighted P-Frames: Y:0.0% UV:0.0%
[libx264 @ 0x2643cf01aa80] ref P L0: 67.0% 2.4% 18.6% 12.1%
[libx264 @ 0x2643cf01aa80] kb/s:23935.23
_________________________________________________________________________________ TestVideoEncoder.test_video_encoder_against_ffmpeg_cli[29.97-to_tensor-encode_params0-mkv] _________________________________________________________________________________
[gw0] freebsd15 -- Python 3.11.14 /usr/local/bin/python3.11
self = <test.test_encoders.TestVideoEncoder object at 0x33413eb34c50>, tmp_path = PosixPath('/tmp/pytest-of-yuri/pytest-21/popen-gw0/test_video_encoder_against_ffm99'), format = 'mkv', encode_params = {'crf': 0, 'pixel_format': 'yuv444p', 'preset': None}
method = 'to_tensor', frame_rate = 29.97
@needs_ffmpeg_cli
@pytest.mark.parametrize(
"format",
(
"mov",
"mp4",
"avi",
"mkv",
"flv",
pytest.param(
"webm",
marks=[
pytest.mark.slow,
pytest.mark.skipif(
get_ffmpeg_major_version() == 4
or (IS_WINDOWS and get_ffmpeg_major_version() in (6, 7)),
reason="Codec for webm is not available in this FFmpeg installation.",
),
],
),
),
)
@pytest.mark.parametrize(
"encode_params",
[
{"pixel_format": "yuv444p", "crf": 0, "preset": None},
{"pixel_format": "yuv420p", "crf": 30, "preset": None},
{"pixel_format": "yuv420p", "crf": None, "preset": "ultrafast"},
{"pixel_format": "yuv420p", "crf": None, "preset": None},
],
)
@pytest.mark.parametrize("method", ("to_file", "to_tensor", "to_file_like"))
@pytest.mark.parametrize("frame_rate", [30, 29.97])
def test_video_encoder_against_ffmpeg_cli(
self, tmp_path, format, encode_params, method, frame_rate
):
pixel_format = encode_params["pixel_format"]
crf = encode_params["crf"]
preset = encode_params["preset"]
ffmpeg_version = get_ffmpeg_major_version()
if format in ("avi", "flv") and pixel_format == "yuv444p":
pytest.skip(f"Default codec for {format} does not support {pixel_format}")
source_frames = self.decode(TEST_SRC_2_720P.path)
# Encode with FFmpeg CLI
temp_raw_path = str(tmp_path / "temp_input.raw")
with open(temp_raw_path, "wb") as f:
f.write(source_frames.permute(0, 2, 3, 1).cpu().numpy().tobytes())
ffmpeg_encoded_path = str(tmp_path / f"ffmpeg_output.{format}")
# Some codecs (ex. MPEG4) do not support CRF or preset.
# Flags not supported by the selected codec will be ignored.
ffmpeg_cmd = [
"ffmpeg",
"-y",
"-f",
"rawvideo",
"-pix_fmt",
"rgb24", # Input format
"-s",
f"{source_frames.shape[3]}x{source_frames.shape[2]}",
"-r",
str(frame_rate),
"-i",
temp_raw_path,
]
if pixel_format is not None: # Output format
ffmpeg_cmd.extend(["-pix_fmt", pixel_format])
if preset is not None:
ffmpeg_cmd.extend(["-preset", preset])
if crf is not None:
ffmpeg_cmd.extend(["-crf", str(crf)])
# Output path must be last
ffmpeg_cmd.append(ffmpeg_encoded_path)
subprocess.run(ffmpeg_cmd, check=True)
ffmpeg_frames = self.decode(ffmpeg_encoded_path).data
# Encode with our video encoder
encoder = VideoEncoder(frames=source_frames, frame_rate=frame_rate)
encoder_output_path = str(tmp_path / f"encoder_output.{format}")
if method == "to_file":
encoder.to_file(
dest=encoder_output_path,
pixel_format=pixel_format,
crf=crf,
preset=preset,
)
encoder_frames = self.decode(encoder_output_path)
elif method == "to_tensor":
> encoded_output = encoder.to_tensor(
format=format,
pixel_format=pixel_format,
crf=crf,
preset=preset,
)
test/test_encoders.py:1116:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
../stage/usr/local/lib/python3.11/site-packages/torchcodec/encoders/_video_encoder.py:128: in to_tensor
return _core.encode_video_to_tensor(
/usr/local/lib/python3.11/site-packages/torch/_ops.py:819: in __call__
return self._op(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^
/usr/local/lib/python3.11/site-packages/torch/utils/_device.py:109: in __torch_function__
return func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <OpOverload(op='torchcodec_ns.encode_video_to_tensor', overload='default')>, args = (), kwargs = {'codec': None, 'crf': 0, 'extra_options': [], 'format': 'mkv', ...}
def __call__(self, /, *args: _P.args, **kwargs: _P.kwargs) -> _T:
> return self._op(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^
E RuntimeError: Invalid AVIO context holder.
/usr/local/lib/python3.11/site-packages/torch/_ops.py:819: RuntimeError
-------------------------------------------------------------------------------------------------------------------- Captured stderr call --------------------------------------------------------------------------------------------------------------------
ffmpeg version 8.0.1 Copyright (c) 2000-2025 the FFmpeg developers
built with FreeBSD clang version 19.1.7 (https://github.com/llvm/llvm-project.git llvmorg-19.1.7-0-gcd708029e0b2)
configuration: --prefix=/usr/local --mandir=/usr/local/share/man --datadir=/usr/local/share/ffmpeg --docdir=/usr/local/share/doc/ffmpeg --pkgconfigdir=/usr/local/libdata/pkgconfig --disable-static --disable-libcelt --disable-mbedtls --enable-shared --enable-pic --enable-gpl --cc=cc --cxx=c++ --disable-alsa --disable-libopencore-amrnb --disable-libopencore-amrwb --enable-libaom --disable-libaribb24 --enable-asm --enable-libass --disable-libbs2b --disable-libcaca --disable-libcdio --disable-libcodec2 --enable-libdav1d --disable-libdc1394 --disable-debug --enable-htmlpages --enable-libdrm --enable-libdvdnav --enable-libdvdread --disable-libfdk-aac --disable-libflite --enable-fontconfig --enable-libfreetype --enable-frei0r --disable-libfribidi --disable-gcrypt --disable-libglslang --disable-libgme --enable-gmp --enable-gnutls --enable-version3 --disable-libgsm --enable-libharfbuzz --enable-iconv --disable-libilbc --disable-libjack --enable-libjxl --disable-libkvazaar --disable-ladspa --enable-libmp3lame --enable-lcms2 --disable-liblensfun --enable-libbluray --enable-libplacebo --enable-librsvg --enable-libxml2 --enable-lto --disable-lv2 --disable-libmfx --disable-libmodplug --disable-libmysofa --enable-network --disable-nonfree --enable-cuvid --enable-nvdec --enable-nvenc --disable-openal --disable-opencl --disable-opengl --disable-libopenh264 --disable-libopenjpeg --disable-libopenmpt --disable-openssl --enable-optimizations --enable-libopus --disable-pocketsphinx --disable-libpulse --disable-librabbitmq --disable-librav1e --disable-librist --enable-runtime-cpudetect --disable-librubberband --disable-sdl2 --enable-libshaderc --disable-libsmbclient --disable-libsnappy --disable-sndio --disable-libsoxr --disable-libspeex --enable-libsrt --disable-libssh --enable-libsvtav1 --disable-libtensorflow --disable-libtesseract --disable-libtheora --disable-libtwolame --enable-libv4l2 --enable-vaapi --disable-vapoursynth --enable-vdpau --disable-libvidstab --enable-libvmaf --enable-libvorbis --disable-libvo-amrwbenc --disable-libvpl --enable-libvpx --enable-vulkan --disable-libvvenc --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxcb --enable-libxcb-shape --enable-libxcb-shm --enable-libxcb-xfixes --enable-xlib --disable-libxvid --disable-outdev=xv --disable-libzimg --disable-libzmq --disable-libzvbi --disable-xlib
libavutil 60. 8.100 / 60. 8.100
libavcodec 62. 11.100 / 62. 11.100
libavformat 62. 3.100 / 62. 3.100
libavdevice 62. 1.100 / 62. 1.100
libavfilter 11. 4.100 / 11. 4.100
libswscale 9. 1.100 / 9. 1.100
libswresample 6. 1.100 / 6. 1.100
[rawvideo @ 0x363ebbc8e280] Estimating duration from bitrate, this may be inaccurate
Input #0, rawvideo, from '/tmp/pytest-of-yuri/pytest-21/popen-gw0/test_video_encoder_against_ffm99/temp_input.raw':
Duration: 00:00:01.00, start: 0.000000, bitrate: 662888 kb/s
Stream #0:0: Video: rawvideo (RGB[24] / 0x18424752), rgb24, 1280x720, 662888 kb/s, 29.97 tbr, 29.97 tbn
Stream mapping:
Stream #0:0 -> #0:0 (rawvideo (native) -> h264 (libx264))
Press [q] to stop, [?] for help
[libx264 @ 0x363ebbc1aa80] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 BMI2 AVX2 AVX512
[libx264 @ 0x363ebbc1aa80] profile High 4:4:4 Predictive, level 3.1, 4:4:4, 8-bit
[libx264 @ 0x363ebbc1aa80] 64 - core 164 - H.264/MPEG-4 AVC codec - Copyleft 2003-2022 - http://www.videolan.org/x264.html - options: cabac=1 ref=3 deblock=1:0:0 analyse=0x3:0x113 me=hex subme=7 psy=0 mixed_ref=1 me_range=16 chroma_me=1 trellis=0 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=0 chroma_qp_offset=0 threads=22 lookahead_threads=3 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=0 weightp=2 keyint=250 keyint_min=25 scenecut=40 intra_refresh=0 rc=cqp mbtree=0 qp=0
Output #0, matroska, to '/tmp/pytest-of-yuri/pytest-21/popen-gw0/test_video_encoder_against_ffm99/ffmpeg_output.mkv':
Metadata:
encoder : Lavf62.3.100
Stream #0:0: Video: h264 (H264 / 0x34363248), yuv444p(tv, progressive), 1280x720, q=2-31, 29.97 fps, 1k tbn
Metadata:
encoder : Lavc62.11.100 libx264
Side data:
cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: N/A
[out#0/matroska @ 0x363ebbcaf700] video:2925KiB audio:0KiB subtitle:0KiB other streams:0KiB global headers:0KiB muxing overhead: 0.029211%
frame= 30 fps=0.0 q=-1.0 Lsize= 2926KiB time=00:00:01.00 bitrate=23946.3kbits/s speed=5.36x elapsed=0:00:00.18
[libx264 @ 0x363ebbc1aa80] frame I:1 Avg QP: 0.00 size:111478
[libx264 @ 0x363ebbc1aa80] frame P:29 Avg QP: 0.00 size: 99428
[libx264 @ 0x363ebbc1aa80] mb I I16..4..PCM: 86.9% 7.1% 5.9% 0.0%
[libx264 @ 0x363ebbc1aa80] mb P I16..4..PCM: 6.9% 0.6% 1.0% 0.0% P16..4: 4.5% 1.9% 2.0% 0.0% 0.0% skip:83.0%
[libx264 @ 0x363ebbc1aa80] 8x8 transform intra:7.1% inter:13.3%
[libx264 @ 0x363ebbc1aa80] coded y,u,v intra: 37.7% 38.8% 38.9% inter: 5.7% 5.7% 5.7%
[libx264 @ 0x363ebbc1aa80] i16 v,h,dc,p: 79% 20% 0% 0%
[libx264 @ 0x363ebbc1aa80] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 37% 22% 37% 2% 0% 0% 0% 1% 0%
[libx264 @ 0x363ebbc1aa80] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 44% 44% 6% 1% 1% 1% 1% 1% 1%
[libx264 @ 0x363ebbc1aa80] Weighted P-Frames: Y:0.0% UV:0.0%
[libx264 @ 0x363ebbc1aa80] ref P L0: 67.0% 2.4% 18.6% 12.1%
[libx264 @ 0x363ebbc1aa80] kb/s:23935.23
________________________________________________________________________________ TestVideoEncoder.test_video_encoder_against_ffmpeg_cli[29.97-to_tensor-encode_params0-webm] _________________________________________________________________________________
[gw0] freebsd15 -- Python 3.11.14 /usr/local/bin/python3.11
self = <test.test_encoders.TestVideoEncoder object at 0x33413eb35250>, tmp_path = PosixPath('/tmp/pytest-of-yuri/pytest-21/popen-gw0/test_video_encoder_against_ffm101'), format = 'webm'
encode_params = {'crf': 0, 'pixel_format': 'yuv444p', 'preset': None}, method = 'to_tensor', frame_rate = 29.97
@needs_ffmpeg_cli
@pytest.mark.parametrize(
"format",
(
"mov",
"mp4",
"avi",
"mkv",
"flv",
pytest.param(
"webm",
marks=[
pytest.mark.slow,
pytest.mark.skipif(
get_ffmpeg_major_version() == 4
or (IS_WINDOWS and get_ffmpeg_major_version() in (6, 7)),
reason="Codec for webm is not available in this FFmpeg installation.",
),
],
),
),
)
@pytest.mark.parametrize(
"encode_params",
[
{"pixel_format": "yuv444p", "crf": 0, "preset": None},
{"pixel_format": "yuv420p", "crf": 30, "preset": None},
{"pixel_format": "yuv420p", "crf": None, "preset": "ultrafast"},
{"pixel_format": "yuv420p", "crf": None, "preset": None},
],
)
@pytest.mark.parametrize("method", ("to_file", "to_tensor", "to_file_like"))
@pytest.mark.parametrize("frame_rate", [30, 29.97])
def test_video_encoder_against_ffmpeg_cli(
self, tmp_path, format, encode_params, method, frame_rate
):
pixel_format = encode_params["pixel_format"]
crf = encode_params["crf"]
preset = encode_params["preset"]
ffmpeg_version = get_ffmpeg_major_version()
if format in ("avi", "flv") and pixel_format == "yuv444p":
pytest.skip(f"Default codec for {format} does not support {pixel_format}")
source_frames = self.decode(TEST_SRC_2_720P.path)
# Encode with FFmpeg CLI
temp_raw_path = str(tmp_path / "temp_input.raw")
with open(temp_raw_path, "wb") as f:
f.write(source_frames.permute(0, 2, 3, 1).cpu().numpy().tobytes())
ffmpeg_encoded_path = str(tmp_path / f"ffmpeg_output.{format}")
# Some codecs (ex. MPEG4) do not support CRF or preset.
# Flags not supported by the selected codec will be ignored.
ffmpeg_cmd = [
"ffmpeg",
"-y",
"-f",
"rawvideo",
"-pix_fmt",
"rgb24", # Input format
"-s",
f"{source_frames.shape[3]}x{source_frames.shape[2]}",
"-r",
str(frame_rate),
"-i",
temp_raw_path,
]
if pixel_format is not None: # Output format
ffmpeg_cmd.extend(["-pix_fmt", pixel_format])
if preset is not None:
ffmpeg_cmd.extend(["-preset", preset])
if crf is not None:
ffmpeg_cmd.extend(["-crf", str(crf)])
# Output path must be last
ffmpeg_cmd.append(ffmpeg_encoded_path)
subprocess.run(ffmpeg_cmd, check=True)
ffmpeg_frames = self.decode(ffmpeg_encoded_path).data
# Encode with our video encoder
encoder = VideoEncoder(frames=source_frames, frame_rate=frame_rate)
encoder_output_path = str(tmp_path / f"encoder_output.{format}")
if method == "to_file":
encoder.to_file(
dest=encoder_output_path,
pixel_format=pixel_format,
crf=crf,
preset=preset,
)
encoder_frames = self.decode(encoder_output_path)
elif method == "to_tensor":
> encoded_output = encoder.to_tensor(
format=format,
pixel_format=pixel_format,
crf=crf,
preset=preset,
)
test/test_encoders.py:1116:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
../stage/usr/local/lib/python3.11/site-packages/torchcodec/encoders/_video_encoder.py:128: in to_tensor
return _core.encode_video_to_tensor(
/usr/local/lib/python3.11/site-packages/torch/_ops.py:819: in __call__
return self._op(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^
/usr/local/lib/python3.11/site-packages/torch/utils/_device.py:109: in __torch_function__
return func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <OpOverload(op='torchcodec_ns.encode_video_to_tensor', overload='default')>, args = (), kwargs = {'codec': None, 'crf': 0, 'extra_options': [], 'format': 'webm', ...}
def __call__(self, /, *args: _P.args, **kwargs: _P.kwargs) -> _T:
> return self._op(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^
E RuntimeError: Invalid AVIO context holder.
/usr/local/lib/python3.11/site-packages/torch/_ops.py:819: RuntimeError
Version: 0.10.0
Python-3.11
ffmpeg-8.0.1
FreeBSD 15 STABLE