@@ -193,7 +193,7 @@ VideoDecoder::BatchDecodedOutput::BatchDecodedOutput(
193193 const StreamMetadata& metadata)
194194 : ptsSeconds(torch::empty({numFrames}, {torch::kFloat64 })),
195195 durationSeconds (torch::empty({numFrames}, {torch::kFloat64 })) {
196- int height, width;
196+ int height = 0 , width = 0 ;
197197 std::tie (height, width) =
198198 getHeightAndWidthFromOptionsOrMetadata (options, metadata);
199199 frames = allocateEmptyHWCTensor (height, width, options.device , numFrames);
@@ -359,12 +359,10 @@ void VideoDecoder::initializeFilterGraphForStream(
359359 inputs->pad_idx = 0 ;
360360 inputs->next = nullptr ;
361361 char description[512 ];
362- int width = activeStream.codecContext ->width ;
363- int height = activeStream.codecContext ->height ;
364- if (options.height .has_value () && options.width .has_value ()) {
365- width = *options.width ;
366- height = *options.height ;
367- }
362+ int height = 0 , width = 0 ;
363+ std::tie (height, width) = getHeightAndWidthFromOptionsOrMetadata (
364+ options, containerMetadata_.streams [streamIndex]);
365+
368366 std::snprintf (
369367 description,
370368 sizeof (description),
@@ -862,7 +860,7 @@ VideoDecoder::DecodedOutput VideoDecoder::convertAVFrameToDecodedOutput(
862860 convertAVFrameToDecodedOutputOnCuda (
863861 streamInfo.options .device ,
864862 streamInfo.options ,
865- streamInfo. codecContext . get () ,
863+ containerMetadata_. streams [streamIndex] ,
866864 rawOutput,
867865 output,
868866 preAllocatedOutputTensor);
@@ -1309,8 +1307,9 @@ void VideoDecoder::convertFrameToBufferUsingSwsScale(
13091307 enum AVPixelFormat frameFormat =
13101308 static_cast <enum AVPixelFormat>(frame->format );
13111309 StreamInfo& activeStream = streams_[streamIndex];
1312- int outputWidth = activeStream.options .width .value_or (frame->width );
1313- int outputHeight = activeStream.options .height .value_or (frame->height );
1310+ int outputHeight = 0 , outputWidth = 0 ;
1311+ std::tie (outputHeight, outputWidth) =
1312+ getHeightAndWidthFromOptionsOrAVFrame (activeStream.options , frame);
13141313 if (activeStream.swsContext .get () == nullptr ) {
13151314 SwsContext* swsContext = sws_getContext (
13161315 frame->width ,
0 commit comments