Primitive subtitle export feature.
[dcpomatic.git] / src / lib / ffmpeg_encoder.h
index 5e6dcecf75d1ee556314d9ff8cddea1f49d12752..df2dcfcc866f5a7535c697274244dd4a3a02d6fa 100644 (file)
@@ -1,5 +1,5 @@
 /*
-    Copyright (C) 2017 Carl Hetherington <cth@carlh.net>
+    Copyright (C) 2017-2018 Carl Hetherington <cth@carlh.net>
 
     This file is part of DCP-o-matic.
 
 #include "encoder.h"
 #include "event_history.h"
 #include "audio_mapping.h"
-extern "C" {
-#include <libavcodec/avcodec.h>
-#include <libavformat/avformat.h>
-}
-#include <boost/thread/condition.hpp>
+#include "ffmpeg_file_encoder.h"
 
 class Butler;
 
 class FFmpegEncoder : public Encoder
 {
 public:
-       enum Format
-       {
-               FORMAT_PRORES,
-               FORMAT_H264
-       };
-
-       FFmpegEncoder (boost::shared_ptr<const Film> film, boost::weak_ptr<Job> job, boost::filesystem::path output, Format format, bool mixdown_to_stereo);
+       FFmpegEncoder (
+               boost::shared_ptr<const Film> film,
+               boost::weak_ptr<Job> job,
+               boost::filesystem::path output,
+               ExportFormat format,
+               bool mixdown_to_stereo,
+               bool split_reels,
+               int x264_crf
+#ifdef DCPOMATIC_VARIANT_SWAROOP
+               , boost::optional<dcp::Key> key
+               , boost::optional<std::string> id
+#endif
+               );
 
        void go ();
 
-       float current_rate () const;
+       boost::optional<float> current_rate () const;
        Frame frames_done () const;
        bool finishing () const {
                return false;
        }
 
 private:
-       void video (boost::shared_ptr<PlayerVideo>, DCPTime);
-       void audio (boost::shared_ptr<AudioBuffers>, DCPTime);
-       void subtitle (PlayerSubtitles, DCPTimePeriod);
-
-       void setup_video ();
-       void setup_audio ();
-
-       void audio_frame (int size);
-
-       AVCodec* _video_codec;
-       AVCodecContext* _video_codec_context;
-       AVCodec* _audio_codec;
-       AVCodecContext* _audio_codec_context;
-       AVFormatContext* _format_context;
-       AVStream* _video_stream;
-       AVStream* _audio_stream;
-       AVPixelFormat _pixel_format;
-       AVSampleFormat _sample_format;
-       AVDictionary* _video_options;
-       std::string _video_codec_name;
-       std::string _audio_codec_name;
-       int _output_audio_channels;
 
-       mutable boost::mutex _mutex;
-       DCPTime _last_time;
+       class FileEncoderSet
+       {
+       public:
+               FileEncoderSet (
+                       dcp::Size video_frame_size,
+                       int video_frame_rate,
+                       int audio_frame_rate,
+                       int channels,
+                       ExportFormat,
+                       int x264_crf,
+                       bool three_d,
+                       boost::filesystem::path output,
+                       std::string extension
+#ifdef DCPOMATIC_VARIANT_SWAROOP
+                       , boost::optional<dcp::Key> key
+                       , boost::optional<std::string> id
+#endif
+                       );
 
-       EventHistory _history;
+               boost::shared_ptr<FFmpegFileEncoder> get (Eyes eyes) const;
+               void flush ();
+               void audio (boost::shared_ptr<AudioBuffers>);
 
-       boost::filesystem::path _output;
+       private:
+               std::map<Eyes, boost::shared_ptr<FFmpegFileEncoder> > _encoders;
+       };
 
-       boost::shared_ptr<AudioBuffers> _pending_audio;
+       std::list<FileEncoderSet> _file_encoders;
+       int _output_audio_channels;
 
-       mutable boost::mutex _queue_mutex;
-       boost::condition _queue_full;
-       std::list<std::pair<boost::shared_ptr<PlayerVideo>, DCPTime> > _queue;
+       mutable boost::mutex _mutex;
+       dcpomatic::DCPTime _last_time;
 
-       boost::shared_ptr<Butler> _butler;
+       EventHistory _history;
 
-       static int _video_stream_index;
-       static int _audio_stream_index;
+       boost::shared_ptr<Butler> _butler;
 };
 
 #endif