@@ -197,10 +197,9 @@ VideoDecoder::BatchDecodedOutput::BatchDecodedOutput(
197197 const StreamMetadata& metadata)
198198 : ptsSeconds(torch::empty({numFrames}, {torch::kFloat64 })),
199199 durationSeconds (torch::empty({numFrames}, {torch::kFloat64 })) {
200- int height = 0 ;
201- int width = 0 ;
202- std::tie (height, width) =
203- getHeightAndWidthFromOptionsOrMetadata (options, metadata);
200+ auto frameDims = getHeightAndWidthFromOptionsOrMetadata (options, metadata);
201+ int height = frameDims.height ;
202+ int width = frameDims.width ;
204203 frames = allocateEmptyHWCTensor (height, width, options.device , numFrames);
205204}
206205
@@ -364,10 +363,10 @@ void VideoDecoder::initializeFilterGraphForStream(
364363 inputs->pad_idx = 0 ;
365364 inputs->next = nullptr ;
366365 char description[512 ];
367- int height = 0 ;
368- int width = 0 ;
369- std::tie (height, width) = getHeightAndWidthFromOptionsOrMetadata (
366+ auto frameDims = getHeightAndWidthFromOptionsOrMetadata (
370367 options, containerMetadata_.streams [streamIndex]);
368+ int height = frameDims.height ;
369+ int width = frameDims.width ;
371370
372371 std::snprintf (
373372 description,
@@ -898,10 +897,10 @@ void VideoDecoder::convertAVFrameToDecodedOutputOnCPU(
898897 torch::Tensor tensor;
899898 if (output.streamType == AVMEDIA_TYPE_VIDEO) {
900899 if (streamInfo.colorConversionLibrary == ColorConversionLibrary::SWSCALE) {
901- int height = 0 ;
902- int width = 0 ;
903- std::tie (height, width) =
900+ auto frameDims =
904901 getHeightAndWidthFromOptionsOrAVFrame (streamInfo.options , *frame);
902+ int height = frameDims.height ;
903+ int width = frameDims.width ;
905904 if (preAllocatedOutputTensor.has_value ()) {
906905 tensor = preAllocatedOutputTensor.value ();
907906 auto shape = tensor.sizes ();
@@ -1315,10 +1314,10 @@ void VideoDecoder::convertFrameToBufferUsingSwsScale(
13151314 enum AVPixelFormat frameFormat =
13161315 static_cast <enum AVPixelFormat>(frame->format );
13171316 StreamInfo& activeStream = streams_[streamIndex];
1318- int outputHeight = 0 ;
1319- int outputWidth = 0 ;
1320- std::tie (outputHeight, outputWidth) =
1317+ auto frameDims =
13211318 getHeightAndWidthFromOptionsOrAVFrame (activeStream.options , *frame);
1319+ int outputHeight = frameDims.height ;
1320+ int outputWidth = frameDims.width ;
13221321 if (activeStream.swsContext .get () == nullptr ) {
13231322 SwsContext* swsContext = sws_getContext (
13241323 frame->width ,
@@ -1384,12 +1383,11 @@ torch::Tensor VideoDecoder::convertFrameToTensorUsingFilterGraph(
13841383 ffmpegStatus =
13851384 av_buffersink_get_frame (filterState.sinkContext , filteredFrame.get ());
13861385 TORCH_CHECK_EQ (filteredFrame->format , AV_PIX_FMT_RGB24);
1387- int height = 0 ;
1388- int width = 0 ;
1389- std::tie (height, width) = getHeightAndWidthFromOptionsOrAVFrame (
1386+ auto frameDims = getHeightAndWidthFromOptionsOrAVFrame (
13901387 streams_[streamIndex].options , *filteredFrame.get ());
1388+ int height = frameDims.height ;
1389+ int width = frameDims.width ;
13911390 std::vector<int64_t > shape = {height, width, 3 };
1392-
13931391 std::vector<int64_t > strides = {filteredFrame->linesize [0 ], 3 , 1 };
13941392 AVFrame* filteredFramePtr = filteredFrame.release ();
13951393 auto deleter = [filteredFramePtr](void *) {
@@ -1413,18 +1411,18 @@ VideoDecoder::~VideoDecoder() {
14131411 }
14141412}
14151413
1416- std::tuple< int , int > getHeightAndWidthFromOptionsOrMetadata (
1414+ FrameDims getHeightAndWidthFromOptionsOrMetadata (
14171415 const VideoDecoder::VideoStreamDecoderOptions& options,
14181416 const VideoDecoder::StreamMetadata& metadata) {
1419- return std::make_tuple (
1417+ return FrameDims (
14201418 options.height .value_or (*metadata.height ),
14211419 options.width .value_or (*metadata.width ));
14221420}
14231421
1424- std::tuple< int , int > getHeightAndWidthFromOptionsOrAVFrame (
1422+ FrameDims getHeightAndWidthFromOptionsOrAVFrame (
14251423 const VideoDecoder::VideoStreamDecoderOptions& options,
14261424 const AVFrame& avFrame) {
1427- return std::make_tuple (
1425+ return FrameDims (
14281426 options.height .value_or (avFrame.height ),
14291427 options.width .value_or (avFrame.width ));
14301428}
0 commit comments