用FFmpeg保存JPEG图片

本文介绍如何利用FFmpeg库以指定的质量保存JPEG图片。关键在于设置JPEG编码质量参数m_jpegQuality,该值范围从0到100,数值越高图像质量越好,但文件尺寸也会增大。默认质量设为80。要注意的是,代码需根据YUV数据的格式调整Y、U、V平面的Linesize设置。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

//函数作用:将解码出来的YUV数据保存成JPG图像
//out_file_name -- JPEG图像保存路径
//w, h -- 图像宽高
//linesize -- 图像的Y分量宽度(一般4字节对齐)
//Y, U, V -- 指向图像Y,U,V三个平面的指针
//
int EncodeAndSaveJPEG(const char* out_file_name, int w, int h, int linesize, uint8_t * Y, uint8_t * U, uint8_t * V)
{
    AVFormatContext* pFormatCtx;
    AVOutputFormat* fmt;
    AVStream* video_st;
    AVCodecContext* pCodecCtx;
    AVCodec* pCodec;
    uint8_t* picture_buf;
    AVFrame* picture;
    AVPacket pkt;
    int y_size;
    int got_picture=0;
    int size;
    int ret=0;

    //av_register_all();

#if 0
    //Method 1
    pFormatCtx = avformat_alloc_context();
    //Guess format
    fmt = av_guess_format("mjpeg", NULL, NULL);
    pFormatCtx->oformat = fmt;
    //Output URL
    if (avio_open(&pFormatCtx->pb, out_file_name, AVIO_FLAG_READ_WRITE) < 0){
        fprintf(stderr, "Couldn't open output file.\n");
        return -1;
    }
#else
    //Method 2. More simple
    avformat_alloc_output_contex
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值