From d33678b8e64de795becd3fa336dbbb099c691f58 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Thu, 24 Aug 2023 15:44:32 +0200 Subject: Set up packet duration correctly when encoding using FFmpeg (#2588). It seems strange that this is necessary (maybe I'm missing some other way that the packet duration is supposed to be set up). Without this, when the mov muxer writes the trak tags it uses an incorrect length value because the length value is calculated from trk->end_pts, which in turn is calculated from the last-seen pts + the duration of the last packet. If that packet is marked as length 0 the length of the track is 1 frame short, so the export is missing a frame. --- src/lib/ffmpeg_file_encoder.cc | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/lib') diff --git a/src/lib/ffmpeg_file_encoder.cc b/src/lib/ffmpeg_file_encoder.cc index 32a0e0f86..f96a9458e 100644 --- a/src/lib/ffmpeg_file_encoder.cc +++ b/src/lib/ffmpeg_file_encoder.cc @@ -383,6 +383,7 @@ 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()); } @@ -438,6 +439,7 @@ FFmpegFileEncoder::video (shared_ptr 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()); } } -- cgit v1.2.3