2 Copyright (C) 2017 Carl Hetherington <cth@carlh.net>
4 This file is part of DCP-o-matic.
6 DCP-o-matic is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 DCP-o-matic is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with DCP-o-matic. If not, see <http://www.gnu.org/licenses/>.
21 #ifndef DCPOMATIC_FFMPEG_ENCODER_H
22 #define DCPOMATIC_FFMPEG_ENCODER_H
25 #include "event_history.h"
26 #include "audio_mapping.h"
28 #include <libavcodec/avcodec.h>
29 #include <libavformat/avformat.h>
31 #include <boost/thread/condition.hpp>
35 class FFmpegEncoder : public Encoder
44 FFmpegEncoder (boost::shared_ptr<const Film> film, boost::weak_ptr<Job> job, boost::filesystem::path output, Format format, bool mixdown_to_stereo);
48 float current_rate () const;
49 Frame frames_done () const;
50 bool finishing () const {
55 void video (boost::shared_ptr<PlayerVideo>, DCPTime);
56 void audio (boost::shared_ptr<AudioBuffers>, DCPTime);
57 void subtitle (PlayerSubtitles, DCPTimePeriod);
62 void audio_frame (int size);
64 AVCodec* _video_codec;
65 AVCodecContext* _video_codec_context;
66 AVCodec* _audio_codec;
67 AVCodecContext* _audio_codec_context;
68 AVFormatContext* _format_context;
69 AVStream* _video_stream;
70 AVStream* _audio_stream;
71 AVPixelFormat _pixel_format;
72 AVSampleFormat _sample_format;
73 AVDictionary* _video_options;
74 std::string _video_codec_name;
75 std::string _audio_codec_name;
76 int _output_audio_channels;
78 mutable boost::mutex _mutex;
81 EventHistory _history;
83 boost::filesystem::path _output;
85 boost::shared_ptr<AudioBuffers> _pending_audio;
87 mutable boost::mutex _queue_mutex;
88 boost::condition _queue_full;
89 std::list<std::pair<boost::shared_ptr<PlayerVideo>, DCPTime> > _queue;
91 boost::shared_ptr<Butler> _butler;
93 static int _video_stream_index;
94 static int _audio_stream_index;