我很难将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;
}
它返回了一个关于步幅不匹配的错误。任何帮助将不胜感激。谢谢!