将AVFrame转换为QVideoFrame

时间:2019-12-30 19:59:58

标签: c++ qt ffmpeg

我使用libav阅读视频,并将其显示在QML的QAbstractVideoSurface中。到目前为止,它仍然有效,但是我没有设法使颜色正确。

我的av_read_frame循环如下:

if (frameFinished)
{
                        SwsContext* context = nullptr;
                        context = sws_getContext(_frame->width, _frame->height, (AVPixelFormat)_frame->format, _frame->width, _frame->height, AVPixelFormat::AV_PIX_FMT_RGBA, SWS_BICUBIC, nullptr, nullptr, nullptr);
                        QImage img(_frame->width, _frame->height, QImage::Format_RGBA8888);
                        uint8_t* dstSlice[] = { img.bits() };
                        int dstStride = img.width() * 4;
                        sws_scale(context, _frame->data, _frame->linesize,
                            0, _frame->height, dstSlice, &dstStride);

                        av_packet_unref(&packet);
                        sws_freeContext(context);
}

如果此时我将图像保存到磁盘,则颜色已经错误(一切看起来都是红色的)。 后来,我在视频界面中以QVideoFrame :: Format_ARGB32格式显示图像,颜色再次错误,但是看起来与保存的图像不同(所有看起来都是蓝色的)。

我最近开始尝试使用libav / ffmpeg,所以问题可能出在其他方面,我一点头绪也没有。让我知道,如果您需要更多信息:)

0 个答案:

没有答案