@@ -494,16 +494,27 @@ void VideoDecoder::addVideoStream(
494494 videoStreamOptions.device .type () == torch::kCPU ||
495495 videoStreamOptions.device .type () == torch::kCUDA ,
496496 " Invalid device type: " + videoStreamOptions.device .str ());
497+
497498 addStream (streamIndex, AVMEDIA_TYPE_VIDEO, videoStreamOptions.device );
498499
500+ auto & streamMetadata =
501+ containerMetadata_.allStreamMetadata [activeStreamIndex_];
502+
503+ if (seekMode_ == SeekMode::approximate &&
504+ !streamMetadata.averageFps .has_value ()) {
505+ throw std::runtime_error (
506+ " Seek mode is approximate, but stream " +
507+ std::to_string (activeStreamIndex_) +
508+ " does not have an average fps in its metadata." );
509+ }
510+
499511 auto & streamInfo = streamInfos_[activeStreamIndex_];
512+ streamInfo.videoStreamOptions = videoStreamOptions;
500513 streamInfo.codecContext ->thread_count =
501514 videoStreamOptions.ffmpegThreadCount .value_or (0 );
502515
503- containerMetadata_.allStreamMetadata [activeStreamIndex_].width =
504- streamInfo.codecContext ->width ;
505- containerMetadata_.allStreamMetadata [activeStreamIndex_].height =
506- streamInfo.codecContext ->height ;
516+ streamMetadata.width = streamInfo.codecContext ->width ;
517+ streamMetadata.height = streamInfo.codecContext ->height ;
507518
508519 // By default, we want to use swscale for color conversion because it is
509520 // faster. However, it has width requirements, so we may need to fall back
0 commit comments