Ignore libxml++ warnings in a nicer way.
[dcpomatic.git] / src / lib / ffmpeg_file_encoder.cc
index e5ea645998ab331993d0de8f83d2a669d15b1659..44ef3f0726d6be3d5b71e0046b1389e8f4e7641d 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);
 
@@ -129,8 +130,9 @@ FFmpegFileEncoder::FFmpegFileEncoder (
                throw runtime_error (String::compose ("could not open FFmpeg audio codec (%1)", buffer));
        }
 
-       if (avio_open_boost (&_format_context->pb, _output, AVIO_FLAG_WRITE) < 0) {
-               throw runtime_error ("could not open FFmpeg output file");
+       r = avio_open_boost (&_format_context->pb, _output, AVIO_FLAG_WRITE);
+       if (r < 0) {
+               throw runtime_error (String::compose("could not open FFmpeg output file %1 (%2)", _output.string(), r));
        }
 
        AVDictionary* options = 0;
@@ -296,7 +298,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 +394,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;
@@ -411,6 +417,7 @@ FFmpegFileEncoder::audio_frame (int size)
        av_frame_free (&frame);
 
        _pending_audio->trim_start (size);
+       _audio_frames += size;
 }
 
 void