Debian Codegraph @

src/album/imageengine/movieservice.h

raw
1 /*
2 * Copyright (C) 2020 ~ 2021 Uniontech Software Technology Co., Ltd.
3 *
4 * Author: ZhangYong <[email protected]>
5 *
6 * Maintainer: ZhangYong <[email protected]>
7 *
8 * This program is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or
11 * any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 */
21 #ifndef MOVIESERVICE_H
22 #define MOVIESERVICE_H
23
24 #include <QObject>
25 #include <QMap>
26 #include <QUrl>
27 #include <QFileInfo>
28 #include <QMutex>
29
30 #include "baseutils.h"
31 #include <libffmpegthumbnailer/videothumbnailerc.h>
32
33 typedef video_thumbnailer *(*mvideo_thumbnailer_create)();
34 typedef void (*mvideo_thumbnailer_destroy)(video_thumbnailer *thumbnailer);
35 /* create image_data structure */
36 typedef image_data *(*mvideo_thumbnailer_create_image_data)(void);
37 /* destroy image_data structure */
38 typedef void (*mvideo_thumbnailer_destroy_image_data)(image_data *data);
39 typedef int (*mvideo_thumbnailer_generate_thumbnail_to_buffer)(video_thumbnailer *thumbnailer, const char *movie_filename, image_data *generated_image_data);
40
41
42 struct MovieInfo {
43 bool valid;
44 QString title;
45 QString fileType;
46 QString resolution;
47 QString filePath;
48 QString creation;
49
50 // rotation in metadata, this affects width/height
51 int raw_rotate;
52 qint64 fileSize;
53 qint64 duration;
54 int width = -1;
55 int height = -1;
56
57 //3.4添加视频信息
58 //视频流信息
59 int vCodecID;
60 qint64 vCodeRate;
61 int fps;
62 float proportion;
63 //音频流信息
64 int aCodeID;
65 qint64 aCodeRate;
66 int aDigit;
67 int channels;
68 int sampling;
69
70 // static struct MovieInfo parseFromFile(const QFileInfo &fi, bool *ok = nullptr);
71 QString durationStr() const
72 {
73 return utils::base::Time2str(duration);
74 }
75
76 QString videoCodec() const
77 {
78 return utils::base::videoIndex2str(vCodecID);
79 }
80
81 QString audioCodec() const
82 {
83 return utils::base::audioIndex2str(aCodeID);
84 }
85
86 QString sizeStr() const
87 {
88 auto K = 1024;
89 auto M = 1024 * K;
90 auto G = 1024 * M;
91 if (fileSize > G) {
92 return QString("%1G").arg((double)fileSize / G, 0, 'f', 1);
93 } else if (fileSize > M) {
94 return QString("%1M").arg((double)fileSize / M, 0, 'f', 1);
95 } else if (fileSize > K) {
96 return QString("%1K").arg((double)fileSize / K, 0, 'f', 1);
97 }
98 return QString("%1").arg(fileSize);
99 }
100 };
101
102 class MovieService: public QObject
103 {
104 Q_OBJECT
105 public:
106 static MovieService *instance(QObject *parent = nullptr);
107 ~MovieService();
108
109 //获取视频信息
110 MovieInfo getMovieInfo(const QUrl &url);
111 //获取视频首帧图片
112 QImage getMovieCover(const QUrl &url);
113 private:
114 struct MovieInfo parseFromFile(const QFileInfo &fi);
115 explicit MovieService(QObject *parent = nullptr);
116 void initThumb();
117 void initFFmpeg();
118 QString libPath(const QString &strlib);
119 private slots:
120
121 signals:
122 public:
123
124 private:
125 QMutex m_queuqMutex;
126 static MovieService *m_movieService;
127 bool m_bInitThumb = false;
128 bool m_initFFmpeg = false;
129
130 video_thumbnailer *m_video_thumbnailer = nullptr;
131 image_data *m_image_data = nullptr;
132
133 mvideo_thumbnailer_create m_creat_video_thumbnailer = nullptr;
134 mvideo_thumbnailer_destroy m_mvideo_thumbnailer_destroy = nullptr;
135 mvideo_thumbnailer_create_image_data m_mvideo_thumbnailer_create_image_data = nullptr;
136 mvideo_thumbnailer_destroy_image_data m_mvideo_thumbnailer_destroy_image_data = nullptr;
137 mvideo_thumbnailer_generate_thumbnail_to_buffer m_mvideo_thumbnailer_generate_thumbnail_to_buffer = nullptr;
138 };
139
140 #endif // MOVIESERVICE_H