Skip to content

Commit 11937f2

Browse files
author
Daniel Flores
committed
add test_against_to_file
1 parent 8b88783 commit 11937f2

File tree

2 files changed

+28
-9
lines changed

2 files changed

+28
-9
lines changed

src/torchcodec/_core/Encoder.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -538,6 +538,7 @@ torch::Tensor validateFrames(const torch::Tensor& frames) {
538538
} // namespace
539539

540540
VideoEncoder::~VideoEncoder() {
541+
// TODO-VideoEncoder: Unify destructor with ~AudioEncoder()
541542
if (avFormatContext_ && avFormatContext_->pb) {
542543
if (avFormatContext_->pb->error == 0) {
543544
avio_flush(avFormatContext_->pb);

test/test_ops.py

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1432,21 +1432,39 @@ def test_video_encoder_round_trip(self, tmp_path, format, method):
14321432
assert psnr(s_frame, rt_frame) > 30
14331433
assert_close(s_frame, rt_frame, atol=atol, rtol=0)
14341434

1435+
@pytest.mark.parametrize(
1436+
"format", ("mov", "mp4", "avi", "mkv", "webm", "flv", "gif")
1437+
)
1438+
def test_against_to_file(self, tmp_path, format):
1439+
# Test that to_file and to_tensor produce the same results
1440+
ffmpeg_version = get_ffmpeg_major_version()
1441+
if format == "webm" and (
1442+
ffmpeg_version == 4 or (IS_WINDOWS and ffmpeg_version in (6, 7))
1443+
):
1444+
pytest.skip("Codec for webm is not available in this FFmpeg installation.")
1445+
1446+
source_frames = self.decode(TEST_SRC_2_720P.path).data
1447+
params = dict(frame_rate=30, crf=0)
1448+
1449+
encoded_file = tmp_path / f"output.{format}"
1450+
encode_video_to_file(frames=source_frames, filename=str(encoded_file), **params)
1451+
encoded_tensor = encode_video_to_tensor(source_frames, format=format, **params)
1452+
1453+
torch.testing.assert_close(
1454+
self.decode(encoded_file).data, self.decode(encoded_tensor).data
1455+
)
1456+
14351457
@pytest.mark.skipif(in_fbcode(), reason="ffmpeg CLI not available")
14361458
@pytest.mark.parametrize(
14371459
"format", ("mov", "mp4", "avi", "mkv", "webm", "flv", "gif")
14381460
)
14391461
def test_video_encoder_against_ffmpeg_cli(self, tmp_path, format):
14401462
ffmpeg_version = get_ffmpeg_major_version()
1441-
if format == "webm":
1442-
if ffmpeg_version == 4:
1443-
pytest.skip(
1444-
"Codec for webm is not available in the FFmpeg4 installation."
1445-
)
1446-
if IS_WINDOWS and ffmpeg_version in (6, 7):
1447-
pytest.skip(
1448-
"Codec for webm is not available in the FFmpeg6/7 installation on Windows."
1449-
)
1463+
if format == "webm" and (
1464+
ffmpeg_version == 4 or (IS_WINDOWS and ffmpeg_version in (6, 7))
1465+
):
1466+
pytest.skip("Codec for webm is not available in this FFmpeg installation.")
1467+
14501468
source_frames = self.decode(TEST_SRC_2_720P.path).data
14511469

14521470
# Encode with FFmpeg CLI

0 commit comments

Comments
 (0)