Skip to content

Commit d35fa3a

Browse files
mollyxufacebook-github-bot
authored andcommitted
Add tests for VideoEncoder fileName-related error checks in torchcodec
Summary: Added tests for - When an invalid file extension is passed in as fileName - When a non-existent path is passed in as fileName Differential Revision: D83087084
1 parent 6f906f4 commit d35fa3a

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

src/torchcodec/_core/Encoder.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -574,8 +574,6 @@ VideoEncoder::VideoEncoder(
574574
fileName,
575575
", make sure it's a valid path? ",
576576
getFFMPEGErrorStringFromErrorCode(status));
577-
// TODO-VideoEncoder: Add tests for above fileName related checks
578-
579577
initializeEncoder(videoStreamOptions);
580578
}
581579

test/test_ops.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1268,6 +1268,24 @@ def test_bad_input(self, tmp_path):
12681268
filename=output_file,
12691269
)
12701270

1271+
with pytest.raises(
1272+
RuntimeError, match=r"Couldn't allocate AVFormatContext. The destination file is ./file.bad_extension, check the desired extension\?"
1273+
):
1274+
encode_video_to_file(
1275+
frames=torch.randint(high=255, size=(10, 3, 60, 60), dtype=torch.uint8),
1276+
frame_rate=10,
1277+
filename="./file.bad_extension",
1278+
)
1279+
1280+
with pytest.raises(
1281+
RuntimeError, match=r"avio_open failed. The destination file is ./bad/path.mp3, make sure it's a valid path\?"
1282+
):
1283+
encode_video_to_file(
1284+
frames=torch.randint(high=255, size=(10, 3, 60, 60), dtype=torch.uint8),
1285+
frame_rate=10,
1286+
filename="./bad/path.mp3",
1287+
)
1288+
12711289
def decode(self, file_path) -> torch.Tensor:
12721290
decoder = create_from_file(str(file_path), seek_mode="approximate")
12731291
add_video_stream(decoder)

0 commit comments

Comments
 (0)