Remove in-place translations support.
[dcpomatic.git] / src / lib / ffmpeg_file_encoder.cc
index 6799d09b4b6b66a306774a9f511bbe6341726f12..6d1ad68f79bb79d939e4baf25991b792ef4bbaa9 100644 (file)
@@ -229,16 +229,16 @@ FFmpegFileEncoder::FFmpegFileEncoder (
 
        switch (format) {
        case ExportFormat::PRORES_4444:
-               _sample_format = AV_SAMPLE_FMT_S16;
+               _sample_format = AV_SAMPLE_FMT_S32;
                _video_codec_name = "prores_ks";
-               _audio_codec_name = "pcm_s16le";
+               _audio_codec_name = "pcm_s24le";
                av_dict_set(&_video_options, "profile", "4", 0);
                av_dict_set(&_video_options, "threads", "auto", 0);
                break;
        case ExportFormat::PRORES_HQ:
-               _sample_format = AV_SAMPLE_FMT_S16;
+               _sample_format = AV_SAMPLE_FMT_S32;
                _video_codec_name = "prores_ks";
-               _audio_codec_name = "pcm_s16le";
+               _audio_codec_name = "pcm_s24le";
                av_dict_set (&_video_options, "profile", "3", 0);
                av_dict_set (&_video_options, "threads", "auto", 0);
                break;
@@ -281,6 +281,7 @@ FFmpegFileEncoder::~FFmpegFileEncoder ()
        _audio_streams.clear ();
        avcodec_close (_video_codec_context);
        avio_close (_format_context->pb);
+       _format_context->pb = nullptr;
        avformat_free_context (_format_context);
 }
 
@@ -382,18 +383,22 @@ FFmpegFileEncoder::flush ()
                        throw EncodeError (N_("avcodec_receive_packet"), N_("FFmpegFileEncoder::flush"), r);
                } else {
                        packet->stream_index = _video_stream_index;
+                       packet->duration = _video_stream->time_base.den / _video_frame_rate;
                        av_interleaved_write_frame (_format_context, packet.get());
                }
 
                flushed_audio = true;
-               for (auto i: _audio_streams) {
+               for (auto const& i: _audio_streams) {
                        if (!i->flush()) {
                                flushed_audio = false;
                        }
                }
        }
 
-       av_write_trailer (_format_context);
+       auto const r = av_write_trailer(_format_context);
+       if (r) {
+               throw EncodeError(N_("av_write_trailer"), N_("FFmpegFileEncoder::flush"), r);
+       }
 }
 
 
@@ -436,6 +441,7 @@ FFmpegFileEncoder::video (shared_ptr<PlayerVideo> video, DCPTime time)
                throw EncodeError (N_("avcodec_receive_packet"), N_("FFmpegFileEncoder::video"), r);
        } else if (r >= 0) {
                packet->stream_index = _video_stream_index;
+               packet->duration = _video_stream->time_base.den / _video_frame_rate;
                av_interleaved_write_frame (_format_context, packet.get());
        }
 }