Basic and untested export option to bounce down to stereo; add encoder test with...
[dcpomatic.git] / src / lib / ffmpeg_encoder.h
1 /*
2     Copyright (C) 2017 Carl Hetherington <cth@carlh.net>
3
4     This file is part of DCP-o-matic.
5
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.
10
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.
15
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/>.
18
19 */
20
21 #ifndef DCPOMATIC_FFMPEG_ENCODER_H
22 #define DCPOMATIC_FFMPEG_ENCODER_H
23
24 #include "encoder.h"
25 #include "event_history.h"
26 #include "audio_mapping.h"
27 extern "C" {
28 #include <libavcodec/avcodec.h>
29 #include <libavformat/avformat.h>
30 }
31
32 class FFmpegEncoder : public Encoder
33 {
34 public:
35         enum Format
36         {
37                 FORMAT_PRORES,
38                 FORMAT_H264
39         };
40
41         FFmpegEncoder (boost::shared_ptr<const Film> film, boost::weak_ptr<Job> job, boost::filesystem::path output, Format format, bool mixdown_to_stereo);
42
43         void go ();
44
45         float current_rate () const;
46         Frame frames_done () const;
47         bool finishing () const {
48                 return false;
49         }
50
51 private:
52         void video (boost::shared_ptr<PlayerVideo>, DCPTime);
53         void audio (boost::shared_ptr<AudioBuffers>, DCPTime);
54         void subtitle (PlayerSubtitles, DCPTimePeriod);
55
56         void setup_video ();
57         void setup_audio ();
58
59         void audio_frame (int size);
60
61         AVCodec* _video_codec;
62         AVCodecContext* _video_codec_context;
63         AVCodec* _audio_codec;
64         AVCodecContext* _audio_codec_context;
65         AVFormatContext* _format_context;
66         AVStream* _video_stream;
67         AVStream* _audio_stream;
68         AVPixelFormat _pixel_format;
69         AVSampleFormat _sample_format;
70         AVDictionary* _video_options;
71         std::string _video_codec_name;
72         std::string _audio_codec_name;
73         AudioMapping _audio_mapping;
74
75         mutable boost::mutex _mutex;
76         DCPTime _last_time;
77
78         EventHistory _history;
79
80         boost::filesystem::path _output;
81
82         boost::shared_ptr<AudioBuffers> _pending_audio;
83
84         static int _video_stream_index;
85         static int _audio_stream_index;
86 };
87
88 #endif