[Libav-user] how to use own buffers for input data with av_read_frame()

Jan Pohanka xhpohanka at gmail.com
Thu Aug 30 08:34:06 CEST 2012


I'm implementing support for hardware video decoder on DM365 and I have  
some problems with buffers. I have simple testing application with  
following code (simplified)

avformat_open_input(&fctx, filename, NULL, NULL);
codec = avcodec_find_decoder_by_name("libdm365_h264");
ret = avcodec_open(avctx, codec)
picture = avcodec_alloc_frame();
for (i = 0; i < 500; i++) {
     int nb;
     char fname[32];

     if (av_read_frame(fctx, &pkt) < 0)

     nb = avcodec_decode_video2(avctx, picture, &got_pic, &pkt);
     if (nb < 0) {
         av_log(avctx, AV_LOG_ERROR, "error in decoding\n");
         goto decode_cleanup;
     printf("Decoded frame: %d\n", i);
     sprintf(fname, "frame%02d.jpg", i);
     save_image(picture, avctx->pix_fmt, avctx->width, avctx->height,  

The problem is that the decoder needs to have both input and output data  
in a buffer which is continuous in physical memory. I can fulfill this  
constraint for the output data (AVFrame *picture) because the buffer is  
allocated by codec itself so I can use my own allocator there.
Unfortunately I do not know how to handle data of AVPacktet pkt, which are  
filled in by av_read_frame() - these are allocated by av_malloc which  
fallbacks to malloc and the buffers probably won't be continuous.

I see two solutions here, but I'm not happy with neither of them:
- copy the whole packet to the continuous buffer (but this will  
significantly slower the application)
- provide own av_malloc wrapper that will use my own allocator (many  
things from libav* internals will be also allocated there and this is not  
exactly what I want)

Do please someone know some more elegant solution?

with best regards

Tato zpráva byla vytvořena převratným poštovním klientem Opery:  

More information about the Libav-user mailing list