1

我正在用 C++ 编写一个应用程序,我想yuv将从网络摄像头获取的图片转换x265_picturehevc. 我按照http://x265.readthedocs.org/en/default/api.html#introduction上的教程进行操作。但是没有关于如何转换yuvx265_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);
4

1 回答 1

1

通过默认 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格式。

于 2015-09-21T11:43:36.383 回答