From 521bb8570ae37e3710cf0d9cdb78e19bf1ed9463 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Sat, 20 Oct 2012 01:03:56 +0100 Subject: [PATCH] Speculative fix for failure to pick up correct audio / subtitle streams. --- src/lib/ffmpeg_decoder.cc | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/lib/ffmpeg_decoder.cc b/src/lib/ffmpeg_decoder.cc index 554188343..4b0594add 100644 --- a/src/lib/ffmpeg_decoder.cc +++ b/src/lib/ffmpeg_decoder.cc @@ -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::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::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"); } -- 2.30.2