From ce17803bf356f3e796dccde43b4cc3656609e7fc Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Sat, 30 Nov 2019 22:34:53 +0100 Subject: [PATCH] More accurate calculation of export video pts; may fix #1663. Also specify audio pts on the way in to the encoder to stop FFmpeg complaining. --- src/lib/ffmpeg_file_encoder.cc | 7 ++++++- src/lib/ffmpeg_file_encoder.h | 2 ++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/lib/ffmpeg_file_encoder.cc b/src/lib/ffmpeg_file_encoder.cc index e5ea64599..7bac7b130 100644 --- a/src/lib/ffmpeg_file_encoder.cc +++ b/src/lib/ffmpeg_file_encoder.cc @@ -63,6 +63,7 @@ FFmpegFileEncoder::FFmpegFileEncoder ( , _video_frame_size (video_frame_size) , _video_frame_rate (video_frame_rate) , _audio_frame_rate (audio_frame_rate) + , _audio_frames (0) { _pixel_format = pixel_format (format); @@ -296,7 +297,8 @@ FFmpegFileEncoder::video (shared_ptr video, DCPTime time) frame->width = image->size().width; frame->height = image->size().height; frame->format = _pixel_format; - frame->pts = time.seconds() / av_q2d (_video_stream->time_base); + DCPOMATIC_ASSERT (_video_stream->time_base.num == 1); + frame->pts = time.get() * _video_stream->time_base.den / DCPTime::HZ; AVPacket packet; av_init_packet (&packet); @@ -391,6 +393,8 @@ FFmpegFileEncoder::audio_frame (int size) DCPOMATIC_ASSERT (false); } + frame->pts = _audio_frames / (av_q2d (_audio_stream->time_base) * _audio_frame_rate); + AVPacket packet; av_init_packet (&packet); packet.data = 0; @@ -411,6 +415,7 @@ FFmpegFileEncoder::audio_frame (int size) av_frame_free (&frame); _pending_audio->trim_start (size); + _audio_frames += size; } void diff --git a/src/lib/ffmpeg_file_encoder.h b/src/lib/ffmpeg_file_encoder.h index 9f1e75b68..57f9135fa 100644 --- a/src/lib/ffmpeg_file_encoder.h +++ b/src/lib/ffmpeg_file_encoder.h @@ -84,6 +84,8 @@ private: int _video_frame_rate; int _audio_frame_rate; + int64_t _audio_frames; + boost::shared_ptr _pending_audio; /** Store of shared_ptr to keep them alive whilst raw pointers into -- 2.30.2