summaryrefslogtreecommitdiff
path: root/src
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
parent563ffc8c14b9db24c828c85c6590d0ece9ed19bc (diff)
Basic and untested export option to bounce down to stereo; add encoder test with subs (which fails).
Diffstat (limited to 'src')
-rw-r--r--src/lib/ffmpeg_encoder.cc32
-rw-r--r--src/lib/ffmpeg_encoder.h4
-rw-r--r--src/tools/dcpomatic.cc2
-rw-r--r--src/wx/export_dialog.cc9
-rw-r--r--src/wx/export_dialog.h2
5 files changed, 41 insertions, 8 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;
diff --git a/src/tools/dcpomatic.cc b/src/tools/dcpomatic.cc
index b5f317942..041644d91 100644
--- a/src/tools/dcpomatic.cc
+++ b/src/tools/dcpomatic.cc
@@ -708,7 +708,7 @@ private:
ExportDialog* d = new ExportDialog (this);
if (d->ShowModal() == wxID_OK) {
shared_ptr<TranscodeJob> job (new TranscodeJob (_film));
- job->set_encoder (shared_ptr<FFmpegEncoder> (new FFmpegEncoder (_film, job, d->path(), d->format())));
+ job->set_encoder (shared_ptr<FFmpegEncoder> (new FFmpegEncoder (_film, job, d->path(), d->format(), d->mixdown_to_stereo())));
JobManager::instance()->add (job);
}
d->Destroy ();
diff --git a/src/wx/export_dialog.cc b/src/wx/export_dialog.cc
index 52aa03c20..712ef4a7e 100644
--- a/src/wx/export_dialog.cc
+++ b/src/wx/export_dialog.cc
@@ -48,6 +48,9 @@ ExportDialog::ExportDialog (wxWindow* parent)
add (_("Format"), true);
_format = new wxChoice (this, wxID_ANY);
add (_format);
+ add_spacer ();
+ _mixdown = new wxCheckBox (this, wxID_ANY, _("Mix audio down to stereo"));
+ add (_mixdown, false);
add (_("Output file"), true);
_file = new FilePickerCtrl (this, _("Select output file"), format_filters[0], false);
add (_file);
@@ -82,3 +85,9 @@ ExportDialog::format () const
DCPOMATIC_ASSERT (_format->GetSelection() >= 0 && _format->GetSelection() < FORMATS);
return formats[_format->GetSelection()];
}
+
+bool
+ExportDialog::mixdown_to_stereo () const
+{
+ return _mixdown->GetValue ();
+}
diff --git a/src/wx/export_dialog.h b/src/wx/export_dialog.h
index 239e56829..0406c562f 100644
--- a/src/wx/export_dialog.h
+++ b/src/wx/export_dialog.h
@@ -32,10 +32,12 @@ public:
boost::filesystem::path path () const;
FFmpegEncoder::Format format () const;
+ bool mixdown_to_stereo () const;
private:
void format_changed ();
wxChoice* _format;
+ wxCheckBox* _mixdown;
FilePickerCtrl* _file;
};