ffmpeg缓冲区未释放

时间:2013-03-11 00:11:26

标签: ffmpeg buffer release decoder

因此,我为ffmpeg编写了一个基本解码器,它只读取输入帧像素数据(使用RGB 8格式存储),并将其直接放入输出缓冲区。 (还有RGB 8)问题是当我在ffmpeg中使用这个解码器时,它说有1个未释放的缓冲区。(使用ffmpeg -i Test.utah Test.png测试)。不幸的是,我不确定它正在讨论什么缓冲区,因为我没有创建自己的缓冲区。我尝试在解码器关闭方法中释放AVContext的coded_frame缓冲区,但这会导致分段错误。

非常感谢任何帮助。

static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
{
    int ret;           /*Hold return from get_buffer */ 
    int skipSize;      /*Number of dummy bytes to skip per line*/
    int fseek=8;       /*Location of the first pixel*/
    int i=0; int j=0;  /*Output buffer seek index/Input Buffer seek index*/
    const uint8_t *buf = avpkt->data; /*Hold a pointer to the input buffer*/
    AVFrame *pict=data; /*Hold a pointer to the output buffer*/

    /*Set the output pixel format to RGB8*/
    avctx->pix_fmt = AV_PIX_FMT_RGB8;

    /*Get the width and height*/
    bytestream_get_le32(&buf);
    avctx->width=bytestream_get_le16(&buf);
    avctx->height=bytestream_get_le16(&buf);

    /*Release the old buffer*/
    if (pict->data[0]) avctx->release_buffer(avctx, pict);

    /*Aquire a large enough data buffer to hold the decompressed picture*/
    if (ret=ff_get_buffer(avctx, pict) < 0) return ret;
    skipSize=pict->linesize[0] - avctx->width; 

    /*Transfer input buffer to output buffer*/
    for(int y=0;y<avctx->height;y++){
        for(int x=0;x<avctx->width;x++){
            pict->data[0][i]=avpkt->data[fseek+j];
            j++;
            i++;
        }
        i+=skipSize;
    }

    /*Inform ffmpeg the output is a key frame and that it is ready for external usage*/
    pict->pict_type        = AV_PICTURE_TYPE_I;
    pict->key_frame        = 1;
    *got_frame=1;
    return 0;
}

1 个答案:

答案 0 :(得分:1)

您没有为此解码器对象发布.close方法。你是否有一个?在大多数FFmpeg解码器中,它采用codecname_decode_end()的形式。解码完成后调用此方法/函数,使解码器有机会自行清理。

我要去的地方:

decode_frame call #0: no frame held; frame allocated
decode_frame call #1: free frame allocated during call #0; frame allocated
decode_frame call #2: free frame allocated during call #1; frame allocated
[...]
decode_frame call #n: free frame allocated during call #(n-1); frame allocated

但是当它全部完成时,解码器仍然保持在decode_frame调用#n期间分配的帧。 codecname_decode_end()允许解码器释放最后一帧。