X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Flib%2Fencoder.cc;h=910d7c58e535cba24edd1d54fcc6c05906ba7608;hb=71ea64782f215c605877f5c231a2a8b1838fe8bd;hp=07ce8f3bc20c2aa35b43a7f9646da5db0b123ac6;hpb=6a8f6bb77ab0a0e0b44bf3bd1cadbe7d55b1b632;p=dcpomatic.git diff --git a/src/lib/encoder.cc b/src/lib/encoder.cc index 07ce8f3bc..910d7c58e 100644 --- a/src/lib/encoder.cc +++ b/src/lib/encoder.cc @@ -42,6 +42,7 @@ using std::stringstream; using std::vector; using std::list; using std::cout; +using std::make_pair; using namespace boost; int const Encoder::_history_size = 25; @@ -65,7 +66,7 @@ Encoder::Encoder (shared_ptr f, shared_ptr o) /* Create sound output files with .tmp suffixes; we will rename them if and when we complete. */ - for (int i = 0; i < _film->audio_channels(); ++i) { + for (int i = 0; i < dcp_audio_channels (_film->audio_channels()); ++i) { SF_INFO sf_info; sf_info.samplerate = dcp_audio_sample_rate (_film->audio_stream()->sample_rate()); /* We write mono files */ @@ -136,7 +137,7 @@ void Encoder::process_end () { #if HAVE_SWRESAMPLE - if (_film->audio_stream() && _swr_context) { + if (_film->audio_stream() && _film->audio_stream()->channels() && _swr_context) { shared_ptr out (new AudioBuffers (_film->audio_stream()->channels(), 256)); @@ -163,7 +164,7 @@ Encoder::process_end () close_sound_files (); /* Rename .wav.tmp files to .wav */ - for (int i = 0; i < _film->audio_channels(); ++i) { + for (int i = 0; i < dcp_audio_channels (_film->audio_channels()); ++i) { if (boost::filesystem::exists (_opt->multichannel_audio_out_path (i, false))) { boost::filesystem::remove (_opt->multichannel_audio_out_path (i, false)); } @@ -207,6 +208,12 @@ Encoder::process_end () _film->log()->log (String::compose ("Local encode failed (%1)", e.what ())); } } + + /* Now do links (or copies on windows) to duplicate frames */ + for (list >::iterator i = _links_required.begin(); i != _links_required.end(); ++i) { + link (_opt->frame_out_path (i->first, false), _opt->frame_out_path (i->second, false)); + link (_opt->hash_out_path (i->first, false), _opt->hash_out_path (i->second, false)); + } } /** @return an estimate of the current number of frames we are encoding per second, @@ -305,9 +312,11 @@ Encoder::process_video (shared_ptr image, bool same, boost::shared_ptrframe_out_path (_last_real_frame.get(), false), _opt->frame_out_path (_video_frame, false)); - link (_opt->hash_out_path (_last_real_frame.get(), false), _opt->hash_out_path (_video_frame, false)); + /* Use the last frame that we encoded. We need to postpone doing the actual link, + as on windows the link is really a copy and the reference frame might not have + finished encoding yet. + */ + _links_required.push_back (make_pair (_last_real_frame.get(), _video_frame)); } else { /* Queue this new frame for encoding */ pair const s = Filter::ffmpeg_strings (_film->filters()); @@ -316,7 +325,7 @@ Encoder::process_video (shared_ptr image, bool same, boost::shared_ptrout_size, _opt->padding, _film->subtitle_offset(), _film->subtitle_scale(), _film->scaler(), _video_frame, _film->frames_per_second(), s.second, - Config::instance()->colour_lut_index (), Config::instance()->j2k_bandwidth (), + _film->colour_lut(), _film->j2k_bandwidth(), _film->log() ) )); @@ -341,6 +350,7 @@ Encoder::process_audio (shared_ptr data) if (this_range.second < required_range.first || required_range.second < this_range.first) { /* No part of this audio is within the required range */ + _audio_frame += data->frames(); return; } else if (required_range.first >= this_range.first && required_range.first < this_range.second) { /* Trim start */ @@ -380,6 +390,22 @@ Encoder::process_audio (shared_ptr data) } #endif + if (_film->audio_channels() == 1) { + /* We need to switch things around so that the mono channel is on + the centre channel of a 5.1 set (with other channels silent). + */ + + shared_ptr b (new AudioBuffers (6, data->frames ())); + b->make_silent (libdcp::LEFT); + b->make_silent (libdcp::RIGHT); + memcpy (b->data()[libdcp::CENTRE], data->data()[0], data->frames() * sizeof(float)); + b->make_silent (libdcp::LFE); + b->make_silent (libdcp::LS); + b->make_silent (libdcp::RS); + + data = b; + } + write_audio (data); _audio_frame += data->frames (); @@ -388,7 +414,7 @@ Encoder::process_audio (shared_ptr data) void Encoder::write_audio (shared_ptr audio) { - for (int i = 0; i < _film->audio_channels(); ++i) { + for (int i = 0; i < audio->channels(); ++i) { sf_write_float (_sound_files[i], audio->data(i), audio->frames()); }