2 Copyright (C) 2012 Carl Hetherington <cth@carlh.net>
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 /** @file src/ffmpeg_decoder.h
21 * @brief A decoder using FFmpeg to decode content.
27 #include <boost/shared_ptr.hpp>
28 #include <boost/optional.hpp>
30 #include <libavcodec/avcodec.h>
31 #include <libpostproc/postprocess.h>
37 struct AVCodecContext;
38 struct AVFilterContext;
39 struct AVFormatContext;
41 struct AVBufferContext;
50 /** @class FFmpegDecoder
51 * @brief A decoder using FFmpeg to decode content.
53 class FFmpegDecoder : public Decoder
56 FFmpegDecoder (boost::shared_ptr<const FilmState>, boost::shared_ptr<const Options>, Job *, Log *, bool, bool);
59 /* Methods to query our input video */
60 float frames_per_second () const;
61 Size native_size () const;
62 int audio_channels () const;
63 int audio_sample_rate () const;
64 AVSampleFormat audio_sample_format () const;
65 int64_t audio_channel_layout () const;
66 bool has_subtitles () const;
68 std::vector<AudioStream> audio_streams () const;
69 std::vector<SubtitleStream> subtitle_streams () const;
74 PixelFormat pixel_format () const;
75 int time_base_numerator () const;
76 int time_base_denominator () const;
77 int sample_aspect_ratio_numerator () const;
78 int sample_aspect_ratio_denominator () const;
80 void setup_general ();
83 void setup_subtitle ();
85 void maybe_add_subtitle ();
87 std::string stream_name (AVStream* s) const;
89 AVFormatContext* _format_context;
91 int _audio_stream; ///< may be < 0 if there is no audio
92 int _subtitle_stream; ///< may be < 0 if there is no subtitle
95 std::vector<AudioStream> _audio_streams;
96 std::vector<SubtitleStream> _subtitle_streams;
98 AVCodecContext* _video_codec_context;
99 AVCodec* _video_codec;
100 AVCodecContext* _audio_codec_context; ///< may be 0 if there is no audio
101 AVCodec* _audio_codec; ///< may be 0 if there is no audio
102 AVCodecContext* _subtitle_codec_context; ///< may be 0 if there is no subtitle
103 AVCodec* _subtitle_codec; ///< may be 0 if there is no subtitle
107 boost::optional<double> _first_video;
108 boost::optional<double> _first_audio;