我正在努力将 QVideoFrame (QT) 转换为 AVFrame 以便对来自网络摄像头的视频进行编码。
QVideoFrame 的文档:http: //qt-project.org/doc/qt-5/qvideoframe.html
我了解图像格式、步幅等的基础知识,但我缺少一些东西。这是我到目前为止所得到的,改编自 libav 示例(https://libav.org/doxygen/release/0.8/libavformat_2output-example_8c-example.html):
static void fill_yuv_image(const QVideoFrame &frame, AVFrame *pict, int frame_index, int width, int height)
{
pict->pts = frame.startTime() * 1000000.0; // time_base is 1/1000000
pict->width = frame.width();
pict->height = frame.height();
pict->format = STREAM_PIX_FMT; //todo: get this from the frame
pict->data[0] = (uint8_t*)frame.bits();
pict->linesize[0] = frame.bytesPerLine();
}
之后我尝试编码:
AVPacket pkt;
int got_packet_ptr = 0;
int success = avcodec_encode_video2(c, &pkt, picture, &got_packet_ptr);
/* if zero size, it means the image was buffered */
if (success == 0) {
/* write the compressed frame in the media file */
ret = av_interleaved_write_frame(oc, &pkt);
} else {
ret = 0;
}
它返回有关步幅不匹配的错误。任何帮助将不胜感激。谢谢!