summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2017-06-07 20:50:26 +0100
committerCarl Hetherington <cth@carlh.net>2017-06-07 20:50:26 +0100
commit3458d0ec34f08a8eeef9b158f26a476a18548353 (patch)
tree7f0f13eddb5463feb7de9c46d6797f0f56d1e594 /src/lib
parent563ffc8c14b9db24c828c85c6590d0ece9ed19bc (diff)
Basic and untested export option to bounce down to stereo; add encoder test with subs (which fails).
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/ffmpeg_encoder.cc32
-rw-r--r--src/lib/ffmpeg_encoder.h4
2 files changed, 29 insertions, 7 deletions
diff --git a/src/lib/ffmpeg_encoder.cc b/src/lib/ffmpeg_encoder.cc
index 52df6c299..5d06616ee 100644
--- a/src/lib/ffmpeg_encoder.cc
+++ b/src/lib/ffmpeg_encoder.cc
@@ -47,12 +47,11 @@ force_pixel_format (AVPixelFormat, AVPixelFormat out)
return out;
}
-FFmpegEncoder::FFmpegEncoder (shared_ptr<const Film> film, weak_ptr<Job> job, boost::filesystem::path output, Format format)
+FFmpegEncoder::FFmpegEncoder (shared_ptr<const Film> film, weak_ptr<Job> job, boost::filesystem::path output, Format format, bool mixdown_to_stereo)
: Encoder (film, job)
, _video_options (0)
, _history (1000)
, _output (output)
- , _pending_audio (new AudioBuffers (film->audio_channels(), 0))
{
switch (format) {
case FORMAT_PRORES:
@@ -73,6 +72,27 @@ FFmpegEncoder::FFmpegEncoder (shared_ptr<const Film> film, weak_ptr<Job> job, bo
_player->set_always_burn_subtitles (true);
_player->set_play_referenced ();
+
+ int const ch = film->audio_channels ();
+
+ if (mixdown_to_stereo) {
+ _audio_mapping = AudioMapping (ch, 2);
+ float const overall_gain = 2 / (4 + sqrt(2));
+ float const minus_3dB = 1 / sqrt(2);
+ _audio_mapping.set (dcp::LEFT, 0, overall_gain);
+ _audio_mapping.set (dcp::RIGHT, 1, overall_gain);
+ _audio_mapping.set (dcp::CENTRE, 0, overall_gain * minus_3dB);
+ _audio_mapping.set (dcp::CENTRE, 1, overall_gain * minus_3dB);
+ _audio_mapping.set (dcp::LS, 0, overall_gain);
+ _audio_mapping.set (dcp::RS, 0, overall_gain);
+ _pending_audio.reset (new AudioBuffers (2, 0));
+ } else {
+ _audio_mapping = AudioMapping (ch, ch);
+ _pending_audio.reset (new AudioBuffers (ch, 0));
+ for (int i = 0; i < ch; ++i) {
+ _audio_mapping.set (i, i, 1);
+ }
+ }
}
void
@@ -118,8 +138,8 @@ FFmpegEncoder::setup_audio ()
_audio_codec_context->bit_rate = 256 * 1024;
_audio_codec_context->sample_fmt = _sample_format;
_audio_codec_context->sample_rate = _film->audio_frame_rate ();
- _audio_codec_context->channel_layout = av_get_default_channel_layout (_film->audio_channels ());
- _audio_codec_context->channels = _film->audio_channels ();
+ _audio_codec_context->channel_layout = av_get_default_channel_layout (_audio_mapping.output_channels ());
+ _audio_codec_context->channels = _audio_mapping.output_channels ();
}
void
@@ -288,7 +308,7 @@ FFmpegEncoder::video (shared_ptr<PlayerVideo> video, DCPTime time)
void
FFmpegEncoder::audio (shared_ptr<AudioBuffers> audio, DCPTime)
{
- _pending_audio->append (audio);
+ _pending_audio->append (remap (audio, _audio_mapping.output_channels(), _audio_mapping));
int frame_size = _audio_codec_context->frame_size;
if (frame_size == 0) {
@@ -309,7 +329,7 @@ FFmpegEncoder::audio_frame (int size)
AVFrame* frame = av_frame_alloc ();
DCPOMATIC_ASSERT (frame);
- int const channels = _audio_codec_context->channels;
+ int const channels = _pending_audio->channels();
DCPOMATIC_ASSERT (channels);
int const buffer_size = av_samples_get_buffer_size (0, channels, size, _audio_codec_context->sample_fmt, 0);
diff --git a/src/lib/ffmpeg_encoder.h b/src/lib/ffmpeg_encoder.h
index c7929c54f..5ab59c12d 100644
--- a/src/lib/ffmpeg_encoder.h
+++ b/src/lib/ffmpeg_encoder.h
@@ -23,6 +23,7 @@
#include "encoder.h"
#include "event_history.h"
+#include "audio_mapping.h"
extern "C" {
#include <libavcodec/avcodec.h>
#include <libavformat/avformat.h>
@@ -37,7 +38,7 @@ public:
FORMAT_H264
};
- FFmpegEncoder (boost::shared_ptr<const Film> film, boost::weak_ptr<Job> job, boost::filesystem::path output, Format format);
+ FFmpegEncoder (boost::shared_ptr<const Film> film, boost::weak_ptr<Job> job, boost::filesystem::path output, Format format, bool mixdown_to_stereo);
void go ();
@@ -69,6 +70,7 @@ private:
AVDictionary* _video_options;
std::string _video_codec_name;
std::string _audio_codec_name;
+ AudioMapping _audio_mapping;
mutable boost::mutex _mutex;
DCPTime _last_time;