我正在用C ++编写应用程序,我想将从网络摄像头获取的yuv
图片转换为x265_picture
,以便将其编码为hevc
。我按照http://x265.readthedocs.org/en/default/api.html#introduction上的教程进行了操作。但是,您无法将yuv
转换为x265_picture
。如何实现这一目标?
x265_param *param = x265_param_alloc();
x265_param_default_preset(param, "ultrafast", "zerolatency");
x265_param_parse(param, "fps", "30");
x265_param_parse(param, "input-res", "352x288"); //wxh
x265_param_parse(param, "bframes", "0");
x265_param_parse(param, "rc-lookahead", "20");
x265_param_parse(param, "repeat-headers", "1");
x265_picture *pic_in = x265_picture_alloc();
x265_picture *pic_out = x265_picture_alloc();
x265_picture_init(param, pic_in);
x265_nal *pp_nal;
uint32_t pi_nal;
x265_encoder *encoder = x265_encoder_open(param);
x265_encoder_encode(encoder, &pp_nal, &pi_nal, pic_in, pic_out);
答案 0 :(得分:0)
通过defaut x265将颜色空间类型设置为i420
(别名yuv 4:2:0平面),您可以检查打印它:
x265_picture_init(param, pic_in);
fprintf(stderr,"colorSpace:%s\n", x265_source_csp_names[pic_in->colorSpace]);
为了将输入x265_picture结构链接到i420
缓冲区,您应该使用以下内容:
pic_in->stride[0] = param->sourceWidth;
pic_in->stride[1] = pic_in->stride[0] >> x265_cli_csps[pic_in->colorSpace].width[1];
pic_in->stride[2] = pic_in->stride[0] >> x265_cli_csps[pic_in->colorSpace].width[2];
pic_in->planes[0] = i420_buffer;
pic_in->planes[1] = (char*)pic_in->planes[0] + pic_in->stride[0] * param->sourceHeight;
pic_in->planes[2] = (char*)pic_in->planes[1] + pic_in->stride[1] * (param->sourceHeight >> x265_cli_csps[pic_in->colorSpace].height[1]);
如果您的网络摄像头的yuv
格式是另一种,您可以设置颜色空间类型(如果libx265支持它),或使用libyuv转换为i420
格式。< / p>