Extract common code out into kdm_for_screen()
[dcpomatic.git] / src / lib / ffmpeg_file_encoder.cc
index 8083ac7e7dbab19919b13629292cd8b2716e6acd..e9809008098536ee6591904e2047b378683d22d1 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);
 
@@ -86,6 +87,8 @@ FFmpegFileEncoder::FFmpegFileEncoder (
                _audio_codec_name = "pcm_s24le";
                av_dict_set_int (&_video_options, "crf", x264_crf, 0);
                break;
+       default:
+               DCPOMATIC_ASSERT (false);
        }
 
        setup_video ();
@@ -280,7 +283,6 @@ FFmpegFileEncoder::video (shared_ptr<PlayerVideo> video, DCPTime time)
 
        {
                boost::mutex::scoped_lock lm (_pending_images_mutex);
-               DCPOMATIC_ASSERT (_pending_images.find(image->data()[0]) != _pending_images.end());
                _pending_images[image->data()[0]] = image;
        }
 
@@ -295,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);
@@ -390,6 +393,9 @@ FFmpegFileEncoder::audio_frame (int size)
                DCPOMATIC_ASSERT (false);
        }
 
+       DCPOMATIC_ASSERT (_audio_stream->time_base.num == 1);
+       frame->pts = _audio_frames * _audio_stream->time_base.den / _audio_frame_rate;
+
        AVPacket packet;
        av_init_packet (&packet);
        packet.data = 0;
@@ -410,6 +416,7 @@ FFmpegFileEncoder::audio_frame (int size)
        av_frame_free (&frame);
 
        _pending_audio->trim_start (size);
+       _audio_frames += size;
 }
 
 void