More accurate calculation of export video pts; may fix #1663.
authorCarl Hetherington <cth@carlh.net>
Sat, 30 Nov 2019 21:34:53 +0000 (22:34 +0100)
committerCarl Hetherington <cth@carlh.net>
Sat, 30 Nov 2019 21:34:53 +0000 (22:34 +0100)
Also specify audio pts on the way in to the encoder to stop FFmpeg
complaining.

src/lib/ffmpeg_file_encoder.cc
src/lib/ffmpeg_file_encoder.h

index e5ea645998ab331993d0de8f83d2a669d15b1659..7bac7b1302bb1860218386a559b1eb8658bf0506 100644 (file)
@@ -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<PlayerVideo> 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
index 9f1e75b686b76f32d67778a36403c0f77704ff07..57f9135fa5e88e0a272ca8e601663374caebfd87 100644 (file)
@@ -84,6 +84,8 @@ private:
        int _video_frame_rate;
        int _audio_frame_rate;
 
+       int64_t _audio_frames;
+
        boost::shared_ptr<AudioBuffers> _pending_audio;
 
        /** Store of shared_ptr<Image> to keep them alive whilst raw pointers into