int video_frame_rate,
int audio_frame_rate,
int channels,
- shared_ptr<Log> log,
ExportFormat format,
int x264_crf,
boost::filesystem::path output
, _video_frame_size (video_frame_size)
, _video_frame_rate (video_frame_rate)
, _audio_frame_rate (audio_frame_rate)
- , _log (log)
{
_pixel_format = pixel_format (format);
setup_video ();
setup_audio ();
- avformat_alloc_output_context2 (&_format_context, 0, 0, _output.string().c_str());
+ int r = avformat_alloc_output_context2 (&_format_context, 0, 0, _output.string().c_str());
if (!_format_context) {
- throw runtime_error ("could not allocate FFmpeg format context");
+ throw runtime_error (String::compose("could not allocate FFmpeg format context (%1)", r));
}
_video_stream = avformat_new_stream (_format_context, _video_codec);
throw runtime_error ("could not open FFmpeg video codec");
}
- int r = avcodec_open2 (_audio_codec_context, _audio_codec, 0);
+ r = avcodec_open2 (_audio_codec_context, _audio_codec, 0);
if (r < 0) {
char buffer[256];
av_strerror (r, buffer, sizeof(buffer));
AVFrame* frame = av_frame_alloc ();
DCPOMATIC_ASSERT (frame);
- _pending_images[image->data()[0]] = image;
+ {
+ boost::mutex::scoped_lock lm (_pending_images_mutex);
+ _pending_images[image->data()[0]] = image;
+ }
+
for (int i = 0; i < 3; ++i) {
AVBufferRef* buffer = av_buffer_create(image->data()[i], image->stride()[i] * image->size().height, &buffer_free, this, 0);
frame->buf[i] = av_buffer_ref (buffer);
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);
void
FFmpegFileEncoder::buffer_free2 (uint8_t* data)
{
- _pending_images.erase (data);
+ boost::mutex::scoped_lock lm (_pending_images_mutex);
+ if (_pending_images.find(data) != _pending_images.end()) {
+ _pending_images.erase (data);
+ }
}