Skip to content

Commit 47246b4

Browse files
mollyxufacebook-github-bot
authored andcommitted
Add tests for VideoEncoder fileName-related error checks in torchcodec (#909)
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 47246b4

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-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: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1268,6 +1268,26 @@ def test_bad_input(self, tmp_path):
12681268
filename=output_file,
12691269
)
12701270

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

0 commit comments

Comments
 (0)