digiKam
Loading...
Searching...
No Matches
videothumbdecoder_p.h
Go to the documentation of this file.
1/* ============================================================
2 *
3 * This file is a part of digiKam project
4 * https://www.digikam.org
5 *
6 * Date : 2016-04-21
7 * Description : video thumbnails extraction based on ffmpeg
8 *
9 * SPDX-FileCopyrightText: 2010 by Dirk Vanden Boer <dirk dot vdb at gmail dot com>
10 * SPDX-FileCopyrightText: 2016-2018 by Maik Qualmann <metzpinguin at gmail dot com>
11 * SPDX-FileCopyrightText: 2016-2024 by Gilles Caulier <caulier dot gilles at gmail dot com>
12 *
13 * SPDX-License-Identifier: GPL-2.0-or-later
14 *
15 * ============================================================ */
16
17#pragma once
18
19#include "videothumbdecoder.h"
20
21// FFMpeg includes
22
23extern "C"
24{
25#include <libswscale/swscale.h>
26#include <libavcodec/avcodec.h>
27#include <libavutil/imgutils.h>
28#include <libavformat/avformat.h>
29#include <libavfilter/avfilter.h>
30#include <libavfilter/buffersrc.h>
31#include <libavfilter/buffersink.h>
32}
33
34namespace Digikam
35{
36
37class Q_DECL_HIDDEN VideoThumbDecoder::Private
38{
39public:
40
41 Private() = default;
42 ~Private() = default;
43
44public:
45
46 int videoStream = -1;
47 AVFormatContext* pFormatContext = nullptr;
48 AVCodecContext* pVideoCodecContext = nullptr;
49 AVCodecParameters* pVideoCodecParameters = nullptr;
50
51#ifndef HAVE_FFMPEG_VERSION5
52
53 AVCodec* pVideoCodec = nullptr;
54
55#else // ffmpeg >= 5
56
57 const AVCodec* pVideoCodec = nullptr;
58
59#endif
60
61 AVStream* pVideoStream = nullptr;
62 AVFrame* pFrame = nullptr;
63 quint8* pFrameBuffer = nullptr;
64 AVPacket* pPacket = nullptr;
65 bool allowSeek = true;
66 bool initialized = false;
67 AVFilterContext* bufferSinkContext = nullptr;
68 AVFilterContext* bufferSourceContext = nullptr;
69 AVFilterGraph* filterGraph = nullptr;
70 AVFrame* filterFrame = nullptr;
71 int lastWidth = 0;
72 int lastHeight = 0;
73 enum AVPixelFormat lastPixfmt = AV_PIX_FMT_NONE;
74
75public:
76
77 bool initializeVideo();
78 bool getVideoPacket();
79 bool decodeVideoPacket() const;
80
81 void convertAndScaleFrame(AVPixelFormat format,
82 int scaledSize,
83 bool maintainAspectRatio,
84 int& scaledWidth,
85 int& scaledHeight);
86
87 bool processFilterGraph(AVFrame* const dst,
88 const AVFrame* const src,
89 enum AVPixelFormat pixfmt,
90 int width,
91 int height);
92
93 void deleteFilterGraph();
94
95private:
96
97 bool initFilterGraph(enum AVPixelFormat pixfmt, int width, int height);
98
99 void calculateDimensions(int squareSize,
100 bool maintainAspectRatio,
101 int& destWidth,
102 int& destHeight);
103
104 void createAVFrame(AVFrame** const avFrame,
105 quint8** const frameBuffer,
106 int width,
107 int height,
108 AVPixelFormat format);
109
110 // cppcheck-suppress unusedPrivateFunction
111 int decodeVideoNew(AVCodecContext* const avContext,
112 AVFrame* const avFrame,
113 int* gotFrame,
114 AVPacket* const avPacket) const;
115};
116
117} // namespace Digikam
Definition videothumbdecoder_p.h:38
Definition videothumbdecoder.h:31
Definition datefolderview.cpp:34