ffmpeg解码后frame数据存储

方式共有两种,其实存储数据只是为了检测解码后的数据是否正确.

/* retrieve data from GPU to CPU */
            if ((ret = av_hwframe_transfer_data(sw_frame, frame, 0)) < 0) {
                fprintf(stderr, "Error transferring the data to system memory\n");
                goto fail;
            }

方式1

AVIOContext *output_ctx = NULL;

/* open the output stream */
    ret = avio_open(&output_ctx, "test.yuv", AVIO_FLAG_WRITE);
    if (ret < 0) {
        fprintf(stderr, "Error opening the output context: ");
        goto finish;
    }

for (i = 0; i < FF_ARRAY_ELEMS(sw_frame->data) && sw_frame->data[i]; i++)
            for (j = 0; j < (sw_frame->height >> (i > 0)); j++)

{
                int t = FF_ARRAY_ELEMS(sw_frame->data);
                avio_write(output_ctx, sw_frame->data[i] + j * sw_frame->linesize[i], sw_frame->width);
            }

方式2

size = av_image_get_buffer_size((AVPixelFormat)tmp_frame->format, tmp_frame->width, tmp_frame->height, 1);//tmp_frame->format
            buffer = (uint8_t*)av_malloc(size);
            if (!buffer) {
                fprintf(stderr, "Can not alloc buffer\n");
                ret = AVERROR(ENOMEM);
                goto fail;
            }

            ret = av_image_copy_to_buffer(buffer, size, (const uint8_t * const *)tmp_frame->data, (const int *)tmp_frame->linesize, (AVPixelFormat)tmp_frame->format,
                tmp_frame->width, tmp_frame->height, 1);//AV_PIX_FMT_YUV420P    (AVPixelFormat)tmp_frame->format
            if (ret < 0) {
                fprintf(stderr, "Can not copy image to buffer\n");
                goto fail;
            }
            if (isFirst)
            {
                if ((ret = fwrite(buffer, 1, size, output_file)) < 0) {
                    fprintf(stderr, "Failed to dump raw data.\n");
                    goto fail;
                }
                //isFirst = false;
            }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值