Speculative fix for failure to pick up correct audio / subtitle streams.
authorCarl Hetherington <cth@carlh.net>
Sat, 20 Oct 2012 00:03:56 +0000 (01:03 +0100)
committerCarl Hetherington <cth@carlh.net>
Sat, 20 Oct 2012 00:03:56 +0000 (01:03 +0100)
src/lib/ffmpeg_decoder.cc

index 5541883439a753c53d25b53c9eb49d792ce2b3ac..4b0594adddfb0d7893f1ec7b87cb0d19da886c7d 100644 (file)
@@ -106,6 +106,8 @@ FFmpegDecoder::setup_general ()
                throw DecodeError ("could not find stream information");
        }
 
+       /* Find video, audio and subtitle streams and choose the first of each */
+
        for (uint32_t i = 0; i < _format_context->nb_streams; ++i) {
                if (_format_context->streams[i]->codec->codec_type == AVMEDIA_TYPE_VIDEO) {
                        _video_stream = i;
@@ -122,6 +124,30 @@ FFmpegDecoder::setup_general ()
                }
        }
 
+       /* Now override audio and subtitle streams with those from the Film, if it has any */
+
+       if (_fs->audio_stream() != -1) {
+               vector<Stream>::iterator i = _audio_streams.begin ();
+               while (i != _audio_streams.end() && i->id != _fs->audio_stream()) {
+                       ++i;
+               }
+
+               if (i != _audio_streams.end()) {
+                       _audio_stream = _fs->audio_stream ();
+               }
+       }
+
+       if (_fs->subtitle_stream() != -1) {
+               vector<Stream>::iterator i = _subtitle_streams.begin ();
+               while (i != _subtitle_streams.end() && i->id != _fs->subtitle_stream()) {
+                       ++i;
+               }
+
+               if (i != _subtitle_streams.end()) {
+                       _subtitle_stream = _fs->subtitle_stream ();
+               }
+       }
+
        if (_video_stream < 0) {
                throw DecodeError ("could not find video stream");
        }