[FFmpeg-devel] Creating a AVFrame from a QVideoFrame
Mike Nelson
mike at realrunners.com
Sat Jun 7 15:52:12 CEST 2014
I'm struggling with converting a QVideoFrame (QT) into a AVFrame in order
to encode video coming from a webcam.
Documentation for QVideoFrame:
http://qt-project.org/doc/qt-5/qvideoframe.html
I understand the basics of image formats, stride and such but I'm missing
something. This is what I've got so far, adapted from a libav example (
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();
}
After which I'm attempting to encode:
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;
}
It's returning an error about the stride not matching. Any help would
be greatly appreciated. Thanks!
More information about the ffmpeg-devel
mailing list