From e77d52e94af1f4bed7a615d27b35ddc933abe0ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B5=AE=E7=94=9F=E8=8B=A5=E6=A2=A6?= <1070753498@qq.com> Date: Thu, 24 Aug 2023 20:34:56 +0800 Subject: [PATCH] =?UTF-8?q?fix=20nv21;=20=E4=BF=AE=E6=94=B9=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E4=BF=A1=E6=81=AF=E6=89=93=E5=8D=B0=E8=BE=93=E5=87=BA?= =?UTF-8?q?=EF=BC=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ffmpeg/formatcontext.cpp | 43 ++++++++++++---------------- ffmpeg/formatcontext.h | 2 ++ ffmpeg/frame.cc | 1 - ffmpeg/gpu/bufferref.cc | 2 +- ffmpeg/gpu/hardwaredecode.cc | 4 +-- ffmpeg/player.cpp | 1 + ffmpeg/videorender/openglrender.cc | 4 +-- ffmpeg/videorender/shader/video.frag | 4 +-- 8 files changed, 28 insertions(+), 33 deletions(-) diff --git a/ffmpeg/formatcontext.cpp b/ffmpeg/formatcontext.cpp index 5cfdc8f..25fc01f 100644 --- a/ffmpeg/formatcontext.cpp +++ b/ffmpeg/formatcontext.cpp @@ -78,26 +78,6 @@ class FormatContext::FormatContextPrivate } } - void printMetaData() - { - AVDictionaryEntry *tag = nullptr; - while (nullptr != (tag = av_dict_get(formatCtx->metadata, "", tag, AV_DICT_IGNORE_SUFFIX))) { - qDebug() << tag->key << QString::fromUtf8(tag->value); - } - } - - void printInformation() - { - qInfo() << tr("AV Format Name: ") << formatCtx->iformat->name; - QTime time(QTime::fromMSecsSinceStartOfDay(formatCtx->duration / 1000)); - qInfo() << QObject::tr("Duration:") << time.toString("hh:mm:ss.zzz"); - - if (formatCtx->pb) { - // FIXME hack, ffplay maybe should not use avio_feof() to test for the end - formatCtx->pb->eof_reached = 0; - } - } - FormatContext *q_ptr; AVFormatContext *formatCtx = nullptr; @@ -276,10 +256,10 @@ bool FormatContext::findStream() SET_ERROR_CODE(ret); return false; } - qDebug() << "The video file contains the number of stream information:" - << d_ptr->formatCtx->nb_streams; - d_ptr->printInformation(); - d_ptr->printMetaData(); + if (d_ptr->formatCtx->pb) { + // FIXME hack, ffplay maybe should not use avio_feof() to test for the end + d_ptr->formatCtx->pb->eof_reached = 0; + } d_ptr->findStreamIndex(); return true; } @@ -409,6 +389,21 @@ bool FormatContext::seek(int index, qint64 timestamp) ERROR_RETURN(ret) } +void FormatContext::printFileInfo() +{ + Q_ASSERT(d_ptr->formatCtx != nullptr); + qInfo() << "AV Format Name:" << d_ptr->formatCtx->iformat->name; + QTime time(QTime::fromMSecsSinceStartOfDay(d_ptr->formatCtx->duration / 1000)); + qInfo() << "Duration:" << time.toString("hh:mm:ss.zzz"); + + // Metadata + AVDictionaryEntry *tag = nullptr; + while (nullptr + != (tag = av_dict_get(d_ptr->formatCtx->metadata, "", tag, AV_DICT_IGNORE_SUFFIX))) { + qInfo() << tag->key << QString::fromUtf8(tag->value); + } +} + void FormatContext::dumpFormat() { Q_ASSERT(d_ptr->formatCtx != nullptr); diff --git a/ffmpeg/formatcontext.h b/ffmpeg/formatcontext.h index 4e442b0..d8e227e 100644 --- a/ffmpeg/formatcontext.h +++ b/ffmpeg/formatcontext.h @@ -64,6 +64,8 @@ class FFMPEG_EXPORT FormatContext : public QObject [[nodiscard]] auto coverImage() const -> QImage &; + void printFileInfo(); + void dumpFormat(); auto avFormatContext() -> AVFormatContext *; diff --git a/ffmpeg/frame.cc b/ffmpeg/frame.cc index f648600..f497f43 100644 --- a/ffmpeg/frame.cc +++ b/ffmpeg/frame.cc @@ -99,7 +99,6 @@ void Frame::copyPropsFrom(Frame *src) d_ptr->frame->key_frame = srcFrame->key_frame; d_ptr->frame->width = srcFrame->width; d_ptr->frame->height = srcFrame->height; - d_ptr->frame->format = srcFrame->format; } auto Frame::imageAlloc(const QSize &size, AVPixelFormat pix_fmt, int align) -> bool diff --git a/ffmpeg/gpu/bufferref.cc b/ffmpeg/gpu/bufferref.cc index f56854c..59b95b9 100644 --- a/ffmpeg/gpu/bufferref.cc +++ b/ffmpeg/gpu/bufferref.cc @@ -35,7 +35,7 @@ bool BufferRef::hwdeviceCtxCreate(AVHWDeviceType hwDeviceType) { auto ret = av_hwdevice_ctx_create(&d_ptr->bufferRef, hwDeviceType, nullptr, nullptr, 0); if (ret < 0) { - qWarning() << "Failed to create specified HW device."; + qWarning() << "Failed to create Gpu device context: " << hwDeviceType; SET_ERROR_CODE(ret); return false; } diff --git a/ffmpeg/gpu/hardwaredecode.cc b/ffmpeg/gpu/hardwaredecode.cc index 70a9034..270dae2 100644 --- a/ffmpeg/gpu/hardwaredecode.cc +++ b/ffmpeg/gpu/hardwaredecode.cc @@ -5,7 +5,6 @@ #include #include #include -#include #include @@ -66,8 +65,7 @@ bool HardWareDecode::initPixelFormat(const AVCodec *decoder) } for (AVHWDeviceType type : qAsConst(d_ptr->hwDeviceTypes)) { hw_pix_fmt = Utils::getPixelFormat(decoder, type); - if (hw_pix_fmt != AV_PIX_FMT_NONE - && VideoFrameConverter::isSupportedInput_pix_fmt(hw_pix_fmt)) { + if (hw_pix_fmt != AV_PIX_FMT_NONE) { d_ptr->hwDeviceType = type; break; } diff --git a/ffmpeg/player.cpp b/ffmpeg/player.cpp index 9867876..52b9bf4 100644 --- a/ffmpeg/player.cpp +++ b/ffmpeg/player.cpp @@ -278,6 +278,7 @@ bool Player::initAvCodec() } d_ptr->isopen = true; + d_ptr->formatCtx->printFileInfo(); d_ptr->formatCtx->dumpFormat(); return true; } diff --git a/ffmpeg/videorender/openglrender.cc b/ffmpeg/videorender/openglrender.cc index e4cfce1..ad2ed1c 100644 --- a/ffmpeg/videorender/openglrender.cc +++ b/ffmpeg/videorender/openglrender.cc @@ -477,11 +477,11 @@ void OpenglRender::updateNV12() glBindTexture(GL_TEXTURE_2D, d_ptr->textureUV); glTexImage2D(GL_TEXTURE_2D, 0, - GL_LUMINANCE_ALPHA, //GL_RG, GL_LUMINANCE_ALPHA + GL_RG, // GL_RG GL_LUMINANCE_ALPHA frame->width / 2, frame->height / 2, 0, - GL_LUMINANCE_ALPHA, //GL_RG, GL_LUMINANCE_ALPHA + GL_RG, // GL_RG GL_LUMINANCE_ALPHA GL_UNSIGNED_BYTE, frame->data[1]); } diff --git a/ffmpeg/videorender/shader/video.frag b/ffmpeg/videorender/shader/video.frag index 577ea9b..6a149b9 100644 --- a/ffmpeg/videorender/shader/video.frag +++ b/ffmpeg/videorender/shader/video.frag @@ -46,10 +46,10 @@ void main() } else if (format == 23 || format == 159) { // NV12 P010LE yuv.x = texture(tex_y, TexCord).r; yuv.y = texture(tex_uv, TexCord).r; - yuv.z = texture(tex_uv, TexCord).a; + yuv.z = texture(tex_uv, TexCord).g; } else if (format == 24) { // NV21 yuv.x = texture(tex_y, TexCord).r; - yuv.y = texture(tex_uv, TexCord).a; + yuv.y = texture(tex_uv, TexCord).g; yuv.z = texture(tex_uv, TexCord).r; } else if (format == 25) { // ARGB FragColor = texture(tex_rgba, TexCord).gbar;