diff --git a/src/torchcodec/decoders/_core/VideoDecoder.cpp b/src/torchcodec/decoders/_core/VideoDecoder.cpp index 1df0ff275..09c451182 100644 --- a/src/torchcodec/decoders/_core/VideoDecoder.cpp +++ b/src/torchcodec/decoders/_core/VideoDecoder.cpp @@ -418,7 +418,7 @@ VideoDecoder::VideoStreamOptions::VideoStreamOptions( } } -void VideoDecoder::addVideoStreamDecoder( +void VideoDecoder::addVideoStream( int streamIndex, const VideoStreamOptions& videoStreamOptions) { TORCH_CHECK( diff --git a/src/torchcodec/decoders/_core/VideoDecoder.h b/src/torchcodec/decoders/_core/VideoDecoder.h index 37142bd7b..11f11a4ce 100644 --- a/src/torchcodec/decoders/_core/VideoDecoder.h +++ b/src/torchcodec/decoders/_core/VideoDecoder.h @@ -136,7 +136,7 @@ class VideoDecoder { struct AudioStreamOptions {}; - void addVideoStreamDecoder( + void addVideoStream( int streamIndex, const VideoStreamOptions& videoStreamOptions = VideoStreamOptions()); void addAudioStreamDecoder( diff --git a/src/torchcodec/decoders/_core/VideoDecoderOps.cpp b/src/torchcodec/decoders/_core/VideoDecoderOps.cpp index 9ce55d81e..3958376c0 100644 --- a/src/torchcodec/decoders/_core/VideoDecoderOps.cpp +++ b/src/torchcodec/decoders/_core/VideoDecoderOps.cpp @@ -220,8 +220,7 @@ void _add_video_stream( } auto videoDecoder = unwrapTensorToGetDecoder(decoder); - videoDecoder->addVideoStreamDecoder( - stream_index.value_or(-1), videoStreamOptions); + videoDecoder->addVideoStream(stream_index.value_or(-1), videoStreamOptions); } void seek_to_pts(at::Tensor& decoder, double seconds) { diff --git a/test/decoders/VideoDecoderTest.cpp b/test/decoders/VideoDecoderTest.cpp index 87a69f28b..4e6710cb7 100644 --- a/test/decoders/VideoDecoderTest.cpp +++ b/test/decoders/VideoDecoderTest.cpp @@ -148,7 +148,7 @@ TEST(VideoDecoderTest, RespectsWidthAndHeightFromOptions) { VideoDecoder::VideoStreamOptions videoStreamOptions; videoStreamOptions.width = 100; videoStreamOptions.height = 120; - decoder->addVideoStreamDecoder(-1, videoStreamOptions); + decoder->addVideoStream(-1, videoStreamOptions); torch::Tensor tensor = decoder->getNextFrame().data; EXPECT_EQ(tensor.sizes(), std::vector({3, 120, 100})); } @@ -158,7 +158,7 @@ TEST(VideoDecoderTest, RespectsOutputTensorDimensionOrderFromOptions) { std::unique_ptr decoder = std::make_unique(path); VideoDecoder::VideoStreamOptions videoStreamOptions; videoStreamOptions.dimensionOrder = "NHWC"; - decoder->addVideoStreamDecoder(-1, videoStreamOptions); + decoder->addVideoStream(-1, videoStreamOptions); torch::Tensor tensor = decoder->getNextFrame().data; EXPECT_EQ(tensor.sizes(), std::vector({270, 480, 3})); } @@ -167,7 +167,7 @@ TEST_P(VideoDecoderTest, ReturnsFirstTwoFramesOfVideo) { std::string path = getResourcePath("nasa_13013.mp4"); std::unique_ptr ourDecoder = createDecoderFromPath(path, GetParam()); - ourDecoder->addVideoStreamDecoder(-1); + ourDecoder->addVideoStream(-1); auto output = ourDecoder->getNextFrame(); torch::Tensor tensor0FromOurDecoder = output.data; EXPECT_EQ(tensor0FromOurDecoder.sizes(), std::vector({3, 270, 480})); @@ -206,7 +206,7 @@ TEST_P(VideoDecoderTest, DecodesFramesInABatchInNCHW) { ourDecoder->scanFileAndUpdateMetadataAndIndex(); int bestVideoStreamIndex = *ourDecoder->getContainerMetadata().bestVideoStreamIndex; - ourDecoder->addVideoStreamDecoder(bestVideoStreamIndex); + ourDecoder->addVideoStream(bestVideoStreamIndex); // Frame with index 180 corresponds to timestamp 6.006. auto output = ourDecoder->getFramesAtIndices({0, 180}); auto tensor = output.data; @@ -228,7 +228,7 @@ TEST_P(VideoDecoderTest, DecodesFramesInABatchInNHWC) { ourDecoder->scanFileAndUpdateMetadataAndIndex(); int bestVideoStreamIndex = *ourDecoder->getContainerMetadata().bestVideoStreamIndex; - ourDecoder->addVideoStreamDecoder( + ourDecoder->addVideoStream( bestVideoStreamIndex, VideoDecoder::VideoStreamOptions("dimension_order=NHWC")); // Frame with index 180 corresponds to timestamp 6.006. @@ -250,7 +250,7 @@ TEST_P(VideoDecoderTest, SeeksCloseToEof) { std::string path = getResourcePath("nasa_13013.mp4"); std::unique_ptr ourDecoder = createDecoderFromPath(path, GetParam()); - ourDecoder->addVideoStreamDecoder(-1); + ourDecoder->addVideoStream(-1); ourDecoder->setCursorPtsInSeconds(388388. / 30'000); auto output = ourDecoder->getNextFrame(); EXPECT_EQ(output.ptsSeconds, 388'388. / 30'000); @@ -263,7 +263,7 @@ TEST_P(VideoDecoderTest, GetsFramePlayedAtTimestamp) { std::string path = getResourcePath("nasa_13013.mp4"); std::unique_ptr ourDecoder = createDecoderFromPath(path, GetParam()); - ourDecoder->addVideoStreamDecoder(-1); + ourDecoder->addVideoStream(-1); auto output = ourDecoder->getFramePlayedAt(6.006); EXPECT_EQ(output.ptsSeconds, 6.006); // The frame's duration is 0.033367 according to ffprobe, @@ -293,7 +293,7 @@ TEST_P(VideoDecoderTest, SeeksToFrameWithSpecificPts) { std::string path = getResourcePath("nasa_13013.mp4"); std::unique_ptr ourDecoder = createDecoderFromPath(path, GetParam()); - ourDecoder->addVideoStreamDecoder(-1); + ourDecoder->addVideoStream(-1); ourDecoder->setCursorPtsInSeconds(6.0); auto output = ourDecoder->getNextFrame(); torch::Tensor tensor6FromOurDecoder = output.data; @@ -393,7 +393,7 @@ TEST_P(VideoDecoderTest, PreAllocatedTensorFilterGraph) { ourDecoder->scanFileAndUpdateMetadataAndIndex(); int bestVideoStreamIndex = *ourDecoder->getContainerMetadata().bestVideoStreamIndex; - ourDecoder->addVideoStreamDecoder( + ourDecoder->addVideoStream( bestVideoStreamIndex, VideoDecoder::VideoStreamOptions("color_conversion_library=filtergraph")); auto output = @@ -410,7 +410,7 @@ TEST_P(VideoDecoderTest, PreAllocatedTensorSwscale) { ourDecoder->scanFileAndUpdateMetadataAndIndex(); int bestVideoStreamIndex = *ourDecoder->getContainerMetadata().bestVideoStreamIndex; - ourDecoder->addVideoStreamDecoder( + ourDecoder->addVideoStream( bestVideoStreamIndex, VideoDecoder::VideoStreamOptions("color_conversion_library=swscale")); auto output =