抓图的话当然可以用QImage来实现,但是得先把yuv图像转成图像再通过QImage保持,比较麻烦。这里直接通过ffmpeg从视频流中抓取图片,也就是在yuv渲染之前抓取。
整个takeSnapshot函数如下所示
void QHSnapshoter::takeSnapshot(AVFrame *frame, std::string filePath)
{
AVFrame *avFrame=frame;
int width=frame->width;
int height=frame->height;
AVFormatContext *formatContext=nullptr;
avformat_alloc_output_context2(&formatContext, nullptr, nullptr, filePath.c_str());
if(!formatContext)
{
std::cout<<"could not alloc output format from file extension!"<<std::endl;
}
AVCodec *codec = avcodec_find_encoder(AV_CODEC_ID_MJPEG);
if(!cod