X-Git-Url: https://git.carlh.net/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2Flib%2Fffmpeg_encoder.cc;h=d4f0b4b472612bb7ee449bd7b51bad00d81fd9f6;hb=f70a51a840f90b1585c64050cde8a298007300f8;hp=fc0d5eab26350f8ee6d257043b9ff2da12a64bf4;hpb=0a1aa72f11b7d5109caaa5d3ae0068e18dea6b56;p=dcpomatic.git diff --git a/src/lib/ffmpeg_encoder.cc b/src/lib/ffmpeg_encoder.cc index fc0d5eab2..d4f0b4b47 100644 --- a/src/lib/ffmpeg_encoder.cc +++ b/src/lib/ffmpeg_encoder.cc @@ -18,26 +18,25 @@ */ + +#include "butler.h" +#include "cross.h" #include "ffmpeg_encoder.h" #include "film.h" +#include "image.h" #include "job.h" +#include "log.h" #include "player.h" #include "player_video.h" -#include "log.h" -#include "image.h" -#include "cross.h" -#include "butler.h" #include "compose.hpp" #include #include "i18n.h" + using std::cout; using std::list; using std::make_shared; -using std::map; -using std::pair; -using std::runtime_error; using std::shared_ptr; using std::string; using std::weak_ptr; @@ -48,6 +47,7 @@ using namespace dcpomatic; using namespace boost::placeholders; #endif + /** @param key Key to use to encrypt MP4 outputs */ FFmpegEncoder::FFmpegEncoder ( shared_ptr film, @@ -108,7 +108,7 @@ FFmpegEncoder::FFmpegEncoder ( } _butler = std::make_shared( - _film, _player, map, _output_audio_channels, bind(&PlayerVideo::force, _1, FFmpegFileEncoder::pixel_format(format)), VideoRange::VIDEO, true, false + _film, _player, map, _output_audio_channels, bind(&PlayerVideo::force, FFmpegFileEncoder::pixel_format(format)), VideoRange::VIDEO, Image::Alignment::PADDED, false, false ); } @@ -161,7 +161,7 @@ FFmpegEncoder::go () auto const video_frame = DCPTime::from_frames (1, _film->video_frame_rate ()); int const audio_frames = video_frame.frames_round(_film->audio_frame_rate()); - float* interleaved = new float[_output_audio_channels * audio_frames]; + std::vector interleaved(_output_audio_channels * audio_frames); auto deinterleaved = make_shared(_output_audio_channels, audio_frames); int const gets_per_frame = _film->three_d() ? 2 : 1; for (DCPTime i; i < _film->length(); i += video_frame) { @@ -176,14 +176,17 @@ FFmpegEncoder::go () for (int j = 0; j < gets_per_frame; ++j) { Butler::Error e; - auto v = _butler->get_video (true, &e); + auto v = _butler->get_video (Butler::Behaviour::BLOCKING, &e); _butler->rethrow (); - if (!v.first) { - throw DecodeError(String::compose("Error during decoding: %1", e.summary())); - } - auto fe = encoder->get (v.first->eyes()); - if (fe) { - fe->video(v.first, v.second); + if (v.first) { + auto fe = encoder->get (v.first->eyes()); + if (fe) { + fe->video(v.first, v.second - reel->from); + } + } else { + if (e.code != Butler::Error::Code::FINISHED) { + throw DecodeError(String::compose("Error during decoding: %1", e.summary())); + } } } @@ -201,9 +204,9 @@ FFmpegEncoder::go () waker.nudge (); - _butler->get_audio (interleaved, audio_frames); + _butler->get_audio (Butler::Behaviour::BLOCKING, interleaved.data(), audio_frames); /* XXX: inefficient; butler interleaves and we deinterleave again */ - float* p = interleaved; + float* p = interleaved.data(); for (int j = 0; j < audio_frames; ++j) { for (int k = 0; k < _output_audio_channels; ++k) { deinterleaved->data(k)[j] = *p++; @@ -211,7 +214,6 @@ FFmpegEncoder::go () } encoder->audio (deinterleaved); } - delete[] interleaved; for (auto i: file_encoders) { i.flush (); @@ -273,11 +275,11 @@ FFmpegEncoder::FileEncoderSet::get (Eyes eyes) const eyes = Eyes::BOTH; } else if (eyes == Eyes::RIGHT) { /* ...and ignore the right eye.*/ - return shared_ptr(); + return {}; } } - map >::const_iterator i = _encoders.find (eyes); + auto i = _encoders.find (eyes); DCPOMATIC_ASSERT (i != _encoders.end()); return i->second; }