[英]encode x264(libx264) raw yuv frame data
我正在尝试使用原始YUV帧数据对MP4视频进行编码,但是我不确定如何填充平面数据(最好不使用ffmpeg这样的其他库)
帧数据已经在I420中进行了编码,不需要转换。
这是我正在尝试做的事情:
const char *frameData = /* Raw frame data */;
x264_t *encoder = x264_encoder_open(¶m);
x264_picture_t imgInput, imgOutput;
x264_picture_alloc(&imgInput, X264_CSP_I420, width, height);
// how can I fill the struct data of imgInput
x264_nal_t *nals;
int i_nals;
int frameSize = x264_encoder_encode(encoder, &nals, &i_nals, &imgInput, &imgOutput);
我发现的等效命令行是:
x264 --output video.mp4 --fps 15 --input-res 1280x800 imgdata_01.raw
但是我不知道该应用程序是如何做到的。
谢谢。
查看libx264 API用法示例 。 本示例使用fread()用来自stdin的实际i420数据填充x264_picture_alloc()分配的帧。 如果您已经在内存中存储了i420数据,并且想要跳过memcpy步骤而不是跳过它,则可以:
为了完成上述答案,这是填充x264_picture_t
图像的示例。
int fillImage(uint8_t* buffer, int width, int height, x264_picture_t*pic){
int ret = x264_picture_alloc(pic, X264_CSP_I420, width, height);
if (ret < 0) return ret;
pic->img.i_plane = 3; // Y, U and V
pic->img.i_stride[0] = width;
// U and V planes are half the size of Y plane
pic->img.i_stride[1] = width / 2;
pic->img.i_stride[2] = width / 2;
int uvsize = ((width + 1) >> 1) * ((height + 1) >> 1);
pic->img.plane[0] = buffer; // Y Plane pointer
pic->img.plane[1] = buffer + (width * height); // U Plane pointer
pic->img.plane[2] = pic->img.plane[1] + uvsize; // V Plane pointer
return ret;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.