Skip to content

Commit 9b36a5d

Browse files
committed
Add VP9 support
1 parent ad3b6d5 commit 9b36a5d

File tree

4 files changed

+29
-12
lines changed

4 files changed

+29
-12
lines changed

src/torchcodec/_core/BetaCudaDeviceInterface.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,10 +150,11 @@ cudaVideoCodec validateCodecSupport(AVCodecID codecId) {
150150
return cudaVideoCodec_HEVC;
151151
case AV_CODEC_ID_AV1:
152152
return cudaVideoCodec_AV1;
153+
case AV_CODEC_ID_VP9:
154+
return cudaVideoCodec_VP9;
153155
// TODONVDEC P0: support more codecs
154156
// case AV_CODEC_ID_MPEG4: return cudaVideoCodec_MPEG4;
155157
// case AV_CODEC_ID_VP8: return cudaVideoCodec_VP8;
156-
// case AV_CODEC_ID_VP9: return cudaVideoCodec_VP9;
157158
// case AV_CODEC_ID_MJPEG: return cudaVideoCodec_JPEG;
158159
default: {
159160
TORCH_CHECK(false, "Unsupported codec type: ", avcodec_get_name(codecId));

test/resources/testsrc2_vp9.webm

102 KB
Binary file not shown.

test/test_decoders.py

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
SINE_MONO_S32_8000,
4646
TEST_SRC_2_720P,
4747
TEST_SRC_2_720P_H265,
48+
TEST_SRC_2_720P_VP9,
4849
unsplit_device_str,
4950
)
5051

@@ -588,7 +589,7 @@ def test_get_frame_at_av1(self, device):
588589
return
589590

590591
if device == "cuda" and in_fbcode():
591-
pytest.skip("AV1 decoding on CUDA is not supported internally")
592+
pytest.skip("decoding on CUDA is not supported internally")
592593

593594
decoder = VideoDecoder(AV1_VIDEO.path, device=device)
594595
device, _ = unsplit_device_str(device)
@@ -1451,15 +1452,16 @@ def test_get_frames_at_tensor_indices(self):
14511452
BT709_FULL_RANGE,
14521453
TEST_SRC_2_720P_H265,
14531454
AV1_VIDEO,
1455+
TEST_SRC_2_720P_VP9,
14541456
),
14551457
)
14561458
@pytest.mark.parametrize("contiguous_indices", (True, False))
14571459
@pytest.mark.parametrize("seek_mode", ("exact", "approximate"))
14581460
def test_beta_cuda_interface_get_frame_at(
14591461
self, asset, contiguous_indices, seek_mode
14601462
):
1461-
if asset == AV1_VIDEO and seek_mode == "approximate":
1462-
pytest.skip("AV1 asset doesn't work with approximate mode")
1463+
if asset in (AV1_VIDEO, TEST_SRC_2_720P_VP9) and seek_mode == "approximate":
1464+
pytest.skip("asset doesn't work with approximate mode")
14631465

14641466
ref_decoder = VideoDecoder(asset.path, device="cuda", seek_mode=seek_mode)
14651467
beta_decoder = VideoDecoder(
@@ -1493,15 +1495,16 @@ def test_beta_cuda_interface_get_frame_at(
14931495
BT709_FULL_RANGE,
14941496
TEST_SRC_2_720P_H265,
14951497
AV1_VIDEO,
1498+
TEST_SRC_2_720P_VP9,
14961499
),
14971500
)
14981501
@pytest.mark.parametrize("contiguous_indices", (True, False))
14991502
@pytest.mark.parametrize("seek_mode", ("exact", "approximate"))
15001503
def test_beta_cuda_interface_get_frames_at(
15011504
self, asset, contiguous_indices, seek_mode
15021505
):
1503-
if asset == AV1_VIDEO and seek_mode == "approximate":
1504-
pytest.skip("AV1 asset doesn't work with approximate mode")
1506+
if asset in (AV1_VIDEO, TEST_SRC_2_720P_VP9) and seek_mode == "approximate":
1507+
pytest.skip("asset doesn't work with approximate mode")
15051508

15061509
ref_decoder = VideoDecoder(asset.path, device="cuda", seek_mode=seek_mode)
15071510
beta_decoder = VideoDecoder(
@@ -1536,12 +1539,13 @@ def test_beta_cuda_interface_get_frames_at(
15361539
BT709_FULL_RANGE,
15371540
TEST_SRC_2_720P_H265,
15381541
AV1_VIDEO,
1542+
TEST_SRC_2_720P_VP9,
15391543
),
15401544
)
15411545
@pytest.mark.parametrize("seek_mode", ("exact", "approximate"))
15421546
def test_beta_cuda_interface_get_frame_played_at(self, asset, seek_mode):
1543-
if asset == AV1_VIDEO and seek_mode == "approximate":
1544-
pytest.skip("AV1 asset doesn't work with approximate mode")
1547+
if asset in (AV1_VIDEO, TEST_SRC_2_720P_VP9) and seek_mode == "approximate":
1548+
pytest.skip("asset doesn't work with approximate mode")
15451549

15461550
ref_decoder = VideoDecoder(asset.path, device="cuda", seek_mode=seek_mode)
15471551
beta_decoder = VideoDecoder(
@@ -1572,13 +1576,14 @@ def test_beta_cuda_interface_get_frame_played_at(self, asset, seek_mode):
15721576
TEST_SRC_2_720P,
15731577
BT709_FULL_RANGE,
15741578
TEST_SRC_2_720P_H265,
1579+
TEST_SRC_2_720P_VP9,
15751580
AV1_VIDEO,
15761581
),
15771582
)
15781583
@pytest.mark.parametrize("seek_mode", ("exact", "approximate"))
15791584
def test_beta_cuda_interface_get_frames_played_at(self, asset, seek_mode):
1580-
if asset == AV1_VIDEO and seek_mode == "approximate":
1581-
pytest.skip("AV1 asset doesn't work with approximate mode")
1585+
if asset in (AV1_VIDEO, TEST_SRC_2_720P_VP9) and seek_mode == "approximate":
1586+
pytest.skip("asset doesn't work with approximate mode")
15821587

15831588
ref_decoder = VideoDecoder(asset.path, device="cuda", seek_mode=seek_mode)
15841589
beta_decoder = VideoDecoder(
@@ -1611,12 +1616,13 @@ def test_beta_cuda_interface_get_frames_played_at(self, asset, seek_mode):
16111616
BT709_FULL_RANGE,
16121617
TEST_SRC_2_720P_H265,
16131618
AV1_VIDEO,
1619+
TEST_SRC_2_720P_VP9,
16141620
),
16151621
)
16161622
@pytest.mark.parametrize("seek_mode", ("exact", "approximate"))
16171623
def test_beta_cuda_interface_backwards(self, asset, seek_mode):
1618-
if asset == AV1_VIDEO and seek_mode == "approximate":
1619-
pytest.skip("AV1 asset doesn't work with approximate mode")
1624+
if asset in (AV1_VIDEO, TEST_SRC_2_720P_VP9) and seek_mode == "approximate":
1625+
pytest.skip("asset doesn't work with approximate mode")
16201626

16211627
ref_decoder = VideoDecoder(asset.path, device="cuda", seek_mode=seek_mode)
16221628
beta_decoder = VideoDecoder(

test/utils.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -717,3 +717,13 @@ def sample_format(self) -> str:
717717
},
718718
frames={0: {}}, # Not needed for now
719719
)
720+
721+
# ffmpeg -f lavfi -i testsrc2=size=1280x720:rate=30:duration=1 -c:v libvpx-vp9 -b:v 1M output_vp9.webm
722+
TEST_SRC_2_720P_VP9 = TestVideo(
723+
filename="testsrc2_vp9.webm",
724+
default_stream_index=0,
725+
stream_infos={
726+
0: TestVideoStreamInfo(width=1280, height=720, num_color_channels=3),
727+
},
728+
frames={0: {}}, # Not needed for now
729+
)

0 commit comments

Comments
 (0)