2 Copyright (C) 2017-2018 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/>.
22 #ifndef DCPOMATIC_FFMPEG_FILE_ENCODER_H
23 #define DCPOMATIC_FFMPEG_FILE_ENCODER_H
27 #include "event_history.h"
28 #include "audio_mapping.h"
32 DCPOMATIC_DISABLE_WARNINGS
34 #include <libavcodec/avcodec.h>
35 #include <libavformat/avformat.h>
37 DCPOMATIC_ENABLE_WARNINGS
40 class ExportAudioStream;
43 class FFmpegFileEncoder
47 dcp::Size video_frame_size,
52 bool audio_stream_per_channel,
54 boost::filesystem::path output
57 ~FFmpegFileEncoder ();
59 void video (std::shared_ptr<PlayerVideo>, dcpomatic::DCPTime);
60 void audio (std::shared_ptr<AudioBuffers>);
61 void subtitle (PlayerText, dcpomatic::DCPTimePeriod);
65 static AVPixelFormat pixel_format (ExportFormat format);
71 void audio_frame (int size);
73 static void buffer_free(void* opaque, uint8_t* data);
74 void buffer_free2(uint8_t* data);
76 AVCodec const * _video_codec = nullptr;
77 AVCodecContext* _video_codec_context = nullptr;
78 std::vector<std::shared_ptr<ExportAudioStream>> _audio_streams;
79 bool _audio_stream_per_channel;
80 AVFormatContext* _format_context = nullptr;
81 AVStream* _video_stream = nullptr;
82 AVPixelFormat _pixel_format;
83 AVSampleFormat _sample_format;
84 AVDictionary* _video_options = nullptr;
85 std::string _video_codec_name;
86 std::string _audio_codec_name;
89 boost::filesystem::path _output;
90 dcp::Size _video_frame_size;
91 int _video_frame_rate;
92 int _audio_frame_rate;
94 int64_t _audio_frames = 0;
96 std::shared_ptr<AudioBuffers> _pending_audio;
98 /** Store of shared_ptr<Image> to keep them alive whilst raw pointers into
99 their data have been passed to FFmpeg.
101 std::map<uint8_t*, std::shared_ptr<const Image>> _pending_images;
102 boost::mutex _pending_images_mutex;
104 static int _video_stream_index;
105 static int _audio_stream_index_base;