AVFrame* frame = av_frame_alloc ();
DCPOMATIC_ASSERT (frame);
+ _pending_images[image->data()[0]] = image;
for (int i = 0; i < 3; ++i) {
- size_t const size = image->stride()[i] * image->sample_size(i).height;
- AVBufferRef* buffer = av_buffer_alloc (size);
- DCPOMATIC_ASSERT (buffer);
- /* XXX: inefficient */
- memcpy (buffer->data, image->data()[i], size);
+ 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->data[i] = buffer->data;
frame->linesize[i] = image->stride()[i];
boost::mutex::scoped_lock lm (_mutex);
return _last_time.frames_round (_film->video_frame_rate ());
}
+
+void
+FFmpegEncoder::buffer_free (void* opaque, uint8_t* data)
+{
+ reinterpret_cast<FFmpegEncoder*>(opaque)->buffer_free2(data);
+}
+
+void
+FFmpegEncoder::buffer_free2 (uint8_t* data)
+{
+ _pending_images.erase (data);
+}
void audio_frame (int size);
+ static void buffer_free(void* opaque, uint8_t* data);
+ void buffer_free2(uint8_t* data);
+
AVCodec* _video_codec;
AVCodecContext* _video_codec_context;
AVCodec* _audio_codec;
boost::shared_ptr<Butler> _butler;
+ /** Store of shared_ptr<Image> to keep them alive whilst raw pointers into
+ their data have been passed to FFmpeg.
+ */
+ std::map<uint8_t*, boost::shared_ptr<const Image> > _pending_images;
+
static int _video_stream_index;
static int _audio_stream_index;
};