对 x264(libx264) 原始 YUV 帧数据进行编码
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_init() 代替 x264_picture_alloc() 和 x264_picture_clean()。因为您不需要在堆上为帧数据分配内存。
- 填写 x264_picture_t.img 结构字段:
- i_csp = X264_CSP_I420;
- i_plane = 3;
- plane[0] = 指向 Y 平面的指针;
- i_stride[0] = Y 平面的步幅(以字节为单位);
- plane[1] = 指向 U 平面的指针;
- i_stride[1] = U 平面的步幅(以字节为单位);
- plane[2] = 指向 V 平面的指针;
- i_stride[2] = V 平面的步幅(以字节为单位);
为了完成上面的答案,这是一个填充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;
}
相关文章:
- 使用已使用 java 编码的 openssl 解码数据
- 在CRC-16 CCITT中将数据从二进制解码为文本,我应该输入一个码字,使用CRC生成器进行编码
- 解码 c++ 中以 base64 编码的大量数据
- 从编码域中的 MPEG 文件中读取元数据
- 如何在65536字节上编码二进制数据到C 上的WebSocket帧
- 使用ffmpeg中的muxing读取编码数据
- 使用 UDP 协议从 Windows 套接字发送到 Qt 套接字的网络数据包上的结构编码和解码
- 运行长度编码算法[数据压缩].
- 如何使用FFMPEG与C拦截编码的视频数据
- c++如何从硬编码结构中获取数据
- 平面缓冲区:使用 add_myTable(表) 对数据进行编码
- 16字节对齐AAC编码数据
- Windows的unicode数据类型使用什么unicode编码(UTF-8、UTF-16等)
- 如何使用Qt处理JSON中的编码西里尔字母数据
- 对于良好的编码实践,如果我们已经在方法1中验证并且方法1将数据传递给方法2,我们是否仍然需要在方法2中再次验证数据?
- 在C 中编码希伯来数据
- FFmpeg:编码PCM 16音频数据分配错误
- 跨平台UTF-8字符文件数据编码/解码
- Cocos2d-x-从精灵或纹理数据编码base64字符串
- B64在数据不是3的倍数的情况下的编码/解码处理