ffmpeg 缓冲区未释放

标签 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;
}

最佳答案

您没有为此解码器对象发布 .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()允许解码器释放最后一帧。

关于ffmpeg 缓冲区未释放,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15329332/

相关文章:

ffmpeg - 结合具有特定持续时间的多个视频

Emacs - 每 5 秒自动保存一次缓冲区

android - react-native-config 在发布版本中不起作用

repository - 快照、候选发布和发布之间有什么区别?

iphone - 如何防止在发布构建与发布构建中使用 Settings.bundle调试构建?

FFMPEG 忽略设置用户代理或其他 header 的尝试

drupal - ffserver 与 drupal 兼容吗?

ffmpeg - 使用 FFMPEG 将 H264 流式传输到 Android

java - java中简单的stdin读取

c - 设置程序调试缓冲区溢出系统