diff options
| author | Carl Hetherington <cth@carlh.net> | 2013-07-10 15:04:57 +0100 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2013-07-10 15:04:57 +0100 |
| commit | 611f2241c6732c2c38d87e129e51cf9d8d7a08b8 (patch) | |
| tree | 0c00420654d322856aecb5c6bbaeb483b3db7211 /src/lib/ffmpeg_decoder.cc | |
| parent | ade36b7e120838840d0f645763b8e0814eaf9ee4 (diff) | |
Basic return of subtitles.
Diffstat (limited to 'src/lib/ffmpeg_decoder.cc')
| -rw-r--r-- | src/lib/ffmpeg_decoder.cc | 48 |
1 files changed, 27 insertions, 21 deletions
diff --git a/src/lib/ffmpeg_decoder.cc b/src/lib/ffmpeg_decoder.cc index d8ee278b3..3714c1542 100644 --- a/src/lib/ffmpeg_decoder.cc +++ b/src/lib/ffmpeg_decoder.cc @@ -61,6 +61,7 @@ FFmpegDecoder::FFmpegDecoder (shared_ptr<const Film> f, shared_ptr<const FFmpegC : Decoder (f) , VideoDecoder (f) , AudioDecoder (f) + , SubtitleDecoder (f) , FFmpeg (c) , _subtitle_codec_context (0) , _subtitle_codec (0) @@ -142,27 +143,7 @@ FFmpegDecoder::pass () } else if (_ffmpeg_content->audio_stream() && _packet.stream_index == _ffmpeg_content->audio_stream()->id && _decode_audio) { decode_audio_packet (); } else if (_ffmpeg_content->subtitle_stream() && _packet.stream_index == _ffmpeg_content->subtitle_stream()->id) { -#if 0 - - int got_subtitle; - AVSubtitle sub; - if (avcodec_decode_subtitle2 (_subtitle_codec_context, &sub, &got_subtitle, &_packet) && got_subtitle) { - /* Sometimes we get an empty AVSubtitle, which is used by some codecs to - indicate that the previous subtitle should stop. - */ - if (sub.num_rects > 0) { - shared_ptr<TimedSubtitle> ts; - try { - subtitle (shared_ptr<TimedSubtitle> (new TimedSubtitle (sub))); - } catch (...) { - /* some problem with the subtitle; we probably didn't understand it */ - } - } else { - subtitle (shared_ptr<TimedSubtitle> ()); - } - avsubtitle_free (&sub); - } -#endif + decode_subtitle_packet (); } av_free_packet (&_packet); @@ -489,3 +470,28 @@ FFmpegDecoder::done () const return vd && ad; } +void +FFmpegDecoder::decode_subtitle_packet () +{ + int got_subtitle; + AVSubtitle sub; + if (avcodec_decode_subtitle2 (_subtitle_codec_context, &sub, &got_subtitle, &_packet) < 0 || !got_subtitle) { + return; + } + + /* Sometimes we get an empty AVSubtitle, which is used by some codecs to + indicate that the previous subtitle should stop. + */ + if (sub.num_rects > 0) { + shared_ptr<TimedSubtitle> ts; + try { + subtitle (shared_ptr<TimedSubtitle> (new TimedSubtitle (sub))); + } catch (...) { + /* some problem with the subtitle; we probably didn't understand it */ + } + } else { + subtitle (shared_ptr<TimedSubtitle> ()); + } + + avsubtitle_free (&sub); +} |
