@@ -223,6 +223,28 @@ TEST_P(VideoDecoderTest, DecodesFramesInABatchInNCHW) {
223223 EXPECT_TRUE (torch::equal (tensor[1 ], tensorTime6FromFFMPEG));
224224}
225225
226+ void testDecoderWithColorConversion (const std::string& colorConversionLibrary) {
227+ std::string path = getResourcePath (" nasa_13013.mp4" );
228+ auto preAllocatedOutputTensor = torch::empty ({270 , 480 , 3 }, {torch::kUInt8 });
229+
230+ std::unique_ptr<VideoDecoder> ourDecoder =
231+ createDecoderFromPath (path, GetParam ());
232+ ourDecoder->scanFileAndUpdateMetadataAndIndex ();
233+ int bestVideoStreamIndex =
234+ *ourDecoder->getContainerMetadata ().bestVideoStreamIndex ;
235+ ourDecoder->addVideoStreamDecoder (
236+ bestVideoStreamIndex,
237+ VideoDecoder::VideoStreamDecoderOptions (
238+ " color_conversion_library=" + colorConversionLibrary));
239+ auto output = ourDecoder->getFrameAtIndex (
240+ bestVideoStreamIndex, 0 , preAllocatedOutputTensor);
241+ EXPECT_EQ (output.frame .data_ptr (), preAllocatedOutputTensor.data_ptr ());
242+ }
243+ TEST_P (VideoDecoderTest, PreAllocatedTensor) {
244+ testDecoderWithColorConversion (" swscale" );
245+ testDecoderWithColorConversion (" filtergraph" );
246+ }
247+
226248TEST_P (VideoDecoderTest, DecodesFramesInABatchInNHWC) {
227249 std::string path = getResourcePath (" nasa_13013.mp4" );
228250 std::unique_ptr<VideoDecoder> ourDecoder =
0 commit comments