On Tue, 07 Apr 2009 09:06:21 -0400, Marc Mason <[email protected]> wrote:
I'm not sure how to convince avcodec_decode_video() to output an uncompressed picture to a user-supplied buffer.
 avctx.get_buffer is set to avcodec_default_get_buffer() by default.
Do I need to provide my own function? Do I also need to provide release_buffer? reget_buffer? get_format? other?

get_buffer and release_buffer are all you need. I think this is only guaranteed to work if the codec has the CODEC_CAP_DR1 flag.

The main problem is in avcodec_default_get_buffer, where a buffer is allocated for each uncompressed component.

   for(i=0; i<4 && size[i]; i++) {
     const int h_shift= i==0 ? 0 : h_chroma_shift;
     const int v_shift= i==0 ? 0 : v_chroma_shift;
     buf->linesize[i]= picture.linesize[i];
     buf->base[i]= av_malloc(size[i]+16); //FIXME 16

#0  avcodec_default_get_buffer at libavcodec/utils.c:298
#1  0x005669cf in ff_mjpeg_decode_sof at libavcodec/mjpegdec.c:334
#2  0x0056ac38 in ff_mjpeg_decode_frame at libavcodec/mjpegdec.c:1396

I'm confused...

Well, your analysis is correct. AVPicture stores planar pixel formats with each plane in a separate buffer. If you want to use one chunk of memory (for instance, a shared memory region) you will need to write your own rather complicated allocation routine. The trick is that depending on the format, there will be lots of strange requirements for alignment of the start of the buffer, the linesize of each buffer, and possible padding rows and columns to allow decoders to write outside of the bounds of the frame. If you write a generic get_buffer it will look just as ugly as you see in utils.c and might need to change for different versions of libav. One reliable way to get the planes aligned properly is to use a custom av_malloc which looks at a global flag to determine when to use malloc and when to use your special memory region. But, this isn't threadsafe unless you use some mutexes (which might hurt performance) or thread-local-storage for the flag.

If you need a non-planar image and the codec is using planar, then you will need to copy the image data anyway and there's no point in allocating a custom buffer for the codec to use.

Hope that helps clear stuff up.

--
Michael Conrad
IntelliTree Solutions llc.
513-552-6362
[email protected]
_______________________________________________
libav-user mailing list
[email protected]
https://lists.mplayerhq.hu/mailman/listinfo/libav-user

Reply via email to