@@ -100,6 +100,26 @@ void SingleStreamDecoder::initializeDecoder() {
100100 " Failed to find stream info: " ,
101101 getFFMPEGErrorStringFromErrorCode (status));
102102
103+ if (formatContext_->duration > 0 ) {
104+ AVRational defaultTimeBase{1 , AV_TIME_BASE};
105+ containerMetadata_.durationSecondsFromHeader =
106+ ptsToSeconds (formatContext_->duration , defaultTimeBase);
107+ }
108+
109+ if (formatContext_->bit_rate > 0 ) {
110+ containerMetadata_.bitRate = formatContext_->bit_rate ;
111+ }
112+
113+ int bestVideoStream = getBestStreamIndex (AVMEDIA_TYPE_VIDEO);
114+ if (bestVideoStream >= 0 ) {
115+ containerMetadata_.bestVideoStreamIndex = bestVideoStream;
116+ }
117+
118+ int bestAudioStream = getBestStreamIndex (AVMEDIA_TYPE_AUDIO);
119+ if (bestAudioStream >= 0 ) {
120+ containerMetadata_.bestAudioStreamIndex = bestAudioStream;
121+ }
122+
103123 for (unsigned int i = 0 ; i < formatContext_->nb_streams ; i++) {
104124 AVStream* avStream = formatContext_->streams [i];
105125 StreamMetadata streamMetadata;
@@ -149,34 +169,10 @@ void SingleStreamDecoder::initializeDecoder() {
149169 containerMetadata_.numAudioStreams ++;
150170 }
151171
152- containerMetadata_.allStreamMetadata .push_back (streamMetadata);
153- }
154-
155- if (formatContext_->duration > 0 ) {
156- AVRational defaultTimeBase{1 , AV_TIME_BASE};
157- containerMetadata_.durationSecondsFromHeader =
158- ptsToSeconds (formatContext_->duration , defaultTimeBase);
159- }
160-
161- if (formatContext_->bit_rate > 0 ) {
162- containerMetadata_.bitRate = formatContext_->bit_rate ;
163- }
164-
165- int bestVideoStream = getBestStreamIndex (AVMEDIA_TYPE_VIDEO);
166- if (bestVideoStream >= 0 ) {
167- containerMetadata_.bestVideoStreamIndex = bestVideoStream;
168- }
172+ streamMetadata.durationSecondsFromContainer =
173+ containerMetadata_.durationSecondsFromHeader ;
169174
170- int bestAudioStream = getBestStreamIndex (AVMEDIA_TYPE_AUDIO);
171- if (bestAudioStream >= 0 ) {
172- containerMetadata_.bestAudioStreamIndex = bestAudioStream;
173- }
174-
175- if (containerMetadata_.durationSecondsFromHeader .has_value ()) {
176- for (auto & streamMetadata : containerMetadata_.allStreamMetadata ) {
177- streamMetadata.durationSecondsFromContainer =
178- containerMetadata_.durationSecondsFromHeader ;
179- }
175+ containerMetadata_.allStreamMetadata .push_back (streamMetadata);
180176 }
181177
182178 if (seekMode_ == SeekMode::exact) {
0 commit comments