[英]YUV420P to JPEG by ffmpeg
My task: Convert YUV Frame data to jpeg images by ffmpeg. What I have: Data of every plane and linesize for each one;我的任务:通过 ffmpeg 将 YUV 帧数据转换为 jpeg 图像。我所拥有的:每个平面的数据和每个平面的线宽;
I tried to create empty AVFrame and fill it's data and linesize with this information, but after encoding it with CODEC_ID_MJPEG codec to images and saving it to files, a havent get correct jpegs.我尝试创建空的 AVFrame 并使用此信息填充它的数据和行大小,但是在使用 CODEC_ID_MJPEG 编解码器将其编码为图像并将其保存到文件后,还没有得到正确的 jpeg。
What I must to do for getting images?我必须做什么才能获取图像?
Maybe you should use jpeglib to do this.也许你应该使用 jpeglib 来做到这一点。 Here's my code这是我的代码
FILE *outfile = fopen(path, "wb+");
if (!outfile)
return 1;
h &= ~15;
struct jpeg_compress_struct cinfo;
struct jpeg_error_mgr jerr;
cinfo.err = jpeg_std_error(&jerr);
jpeg_create_compress(&cinfo);
jpeg_stdio_dest(&cinfo, outfile);
cinfo.image_width = w;
cinfo.image_height = h;
cinfo.input_components = 3;
cinfo.in_color_space = JCS_YCbCr;
jpeg_set_defaults(&cinfo);
jpeg_set_quality(&cinfo, 90, TRUE);
cinfo.dct_method = JDCT_FASTEST;
cinfo.raw_data_in = TRUE;
cinfo.comp_info[0].h_samp_factor = 2;
cinfo.comp_info[0].v_samp_factor = 2;
cinfo.comp_info[1].h_samp_factor = 1;
cinfo.comp_info[1].v_samp_factor = 1;
cinfo.comp_info[2].h_samp_factor = 1;
cinfo.comp_info[2].v_samp_factor = 1;
int i, j;
JSAMPROW y[16], cb[16], cr[16];
JSAMPARRAY p[3];
jpeg_start_compress(&cinfo, TRUE);
p[0] = y;
p[2] = cb;
p[1] = cr;
for (j = 0; j < cinfo.image_height; j += 16) {
for (i = 0; i < 16; i++) {
y[i] = data[0] + line[0]*(i+j);
cr[i/2] = data[1] + line[1]*((i+j)/2);
cb[i/2] = data[2] + line[2]*((i+j)/2);
}
jpeg_write_raw_data(&cinfo, p, 16);
}
jpeg_finish_compress(&cinfo);
fclose(outfile);
jpeg_destroy_compress(&cinfo);
where data
is YUV planar data and line
is linesize.其中data
是 YUV 平面数据, line
是 linesize。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.