//函数作用:将解码出来的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
用FFmpeg保存JPEG图片
最新推荐文章于 2025-06-20 14:32:55 发布

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

被折叠的 条评论
为什么被折叠?



