File indexing completed on 2024-03-24 04:51:51
0001 /* 0002 SPDX-FileCopyrightText: 2010 Dirk Vanden Boer <dirk.vdb@gmail.com> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #ifndef MOVIEDECODER_H 0008 #define MOVIEDECODER_H 0009 0010 #include <QString> 0011 0012 class QImage; 0013 0014 extern "C" { 0015 #include <libavcodec/avcodec.h> 0016 #include <libavfilter/avfilter.h> 0017 #include <libavfilter/buffersink.h> 0018 #include <libavfilter/buffersrc.h> 0019 #include <libavformat/avformat.h> 0020 } 0021 0022 class FrameDecoder 0023 { 0024 public: 0025 explicit FrameDecoder(const QString &filename, AVFormatContext *pavContext = nullptr); 0026 ~FrameDecoder(); 0027 0028 QString getCodec(); 0029 void seek(int timeInSeconds); 0030 bool decodeVideoFrame(); 0031 void getScaledVideoFrame(int scaledSize, bool maintainAspectRatio, QImage &videoFrame); 0032 0033 int getWidth(); 0034 int getHeight(); 0035 int getDuration(); 0036 0037 void initialize(const QString &filename); 0038 void destroy(); 0039 bool getInitialized(); 0040 0041 private: 0042 bool initializeVideo(); 0043 0044 bool decodeVideoPacket(); 0045 bool getVideoPacket(); 0046 void convertAndScaleFrame(AVPixelFormat format, int scaledSize, bool maintainAspectRatio, int &scaledWidth, int &scaledHeight); 0047 void createAVFrame(AVFrame **avFrame, quint8 **frameBuffer, int width, int height, AVPixelFormat format); 0048 void calculateDimensions(int squareSize, bool maintainAspectRatio, int &destWidth, int &destHeight); 0049 0050 void deleteFilterGraph(); 0051 bool initFilterGraph(enum AVPixelFormat pixfmt, int width, int height); 0052 bool processFilterGraph(AVFrame *dst, const AVFrame *src, enum AVPixelFormat pixfmt, int width, int height); 0053 0054 private: 0055 int m_VideoStream; 0056 AVFormatContext *m_pFormatContext{nullptr}; 0057 AVCodecContext *m_pVideoCodecContext{nullptr}; 0058 #if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(59, 0, 100) 0059 AVCodec *m_pVideoCodec{nullptr}; 0060 #else 0061 const AVCodec *m_pVideoCodec{nullptr}; 0062 #endif 0063 AVFrame *m_pFrame{nullptr}; 0064 quint8 *m_pFrameBuffer{nullptr}; 0065 AVPacket *m_pPacket{nullptr}; 0066 bool m_FormatContextWasGiven; 0067 bool m_AllowSeek; 0068 bool m_initialized; 0069 AVFilterContext *m_bufferSinkContext{nullptr}; 0070 AVFilterContext *m_bufferSourceContext{nullptr}; 0071 AVFilterGraph *m_filterGraph{nullptr}; 0072 AVFrame *m_filterFrame{nullptr}; 0073 int m_lastWidth; 0074 int m_lastHeight; 0075 enum AVPixelFormat m_lastPixfmt; 0076 }; 0077 0078 #endif