author | unC0Rr |
Wed, 15 May 2024 10:05:13 +0200 | |
changeset 16013 | 2e529b1a9d5b |
parent 15834 | 8fd36e1b66ed |
permissions | -rw-r--r-- |
7897 | 1 |
/* |
2 |
* Hedgewars, a free turn based strategy game |
|
11046 | 3 |
* Copyright (c) 2004-2015 Andrey Korotaev <unC0Rr@gmail.com> |
7897 | 4 |
* |
5 |
* This program is free software; you can redistribute it and/or modify |
|
6 |
* it under the terms of the GNU General Public License as published by |
|
7 |
* the Free Software Foundation; version 2 of the License |
|
8 |
* |
|
9 |
* This program is distributed in the hope that it will be useful, |
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 |
* GNU General Public License for more details. |
|
13 |
* |
|
14 |
* You should have received a copy of the GNU General Public License |
|
15 |
* along with this program; if not, write to the Free Software |
|
10108
c68cf030eded
update FSF address. note: two sdl include files (by Sam Lantinga) still have the old FSF address in their copyright - but I ain't gonna touch their copyright headers
sheepluva
parents:
9998
diff
changeset
|
16 |
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
7897 | 17 |
*/ |
18 |
||
19 |
#include "LibavInteraction.h" |
|
20 |
||
11852 | 21 |
#ifdef VIDEOREC |
7897 | 22 |
extern "C" |
23 |
{ |
|
11298
9fcdf0969d53
Update libav API, keeping forward and backward compatibility
Vittorio Giovara <vittorio.giovara@gmail.com>
parents:
11046
diff
changeset
|
24 |
#include "libavcodec/avcodec.h" |
7897 | 25 |
#include "libavformat/avformat.h" |
11298
9fcdf0969d53
Update libav API, keeping forward and backward compatibility
Vittorio Giovara <vittorio.giovara@gmail.com>
parents:
11046
diff
changeset
|
26 |
#include "libavutil/avutil.h" |
7897 | 27 |
} |
28 |
||
29 |
#include <QVector> |
|
30 |
#include <QList> |
|
31 |
#include <QComboBox> |
|
32 |
||
33 |
#include "HWApplication.h" |
|
34 |
||
11298
9fcdf0969d53
Update libav API, keeping forward and backward compatibility
Vittorio Giovara <vittorio.giovara@gmail.com>
parents:
11046
diff
changeset
|
35 |
// compatibility section |
11356
ac423fd2b9a3
libavinteraction: Adjust version guard for av_codec_is_encoder()
Vittorio Giovara <vittorio.giovara@gmail.com>
parents:
11299
diff
changeset
|
36 |
#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(54, 8, 0) |
ac423fd2b9a3
libavinteraction: Adjust version guard for av_codec_is_encoder()
Vittorio Giovara <vittorio.giovara@gmail.com>
parents:
11299
diff
changeset
|
37 |
#define av_codec_is_encoder(x) x->encode |
ac423fd2b9a3
libavinteraction: Adjust version guard for av_codec_is_encoder()
Vittorio Giovara <vittorio.giovara@gmail.com>
parents:
11299
diff
changeset
|
38 |
#endif |
ac423fd2b9a3
libavinteraction: Adjust version guard for av_codec_is_encoder()
Vittorio Giovara <vittorio.giovara@gmail.com>
parents:
11299
diff
changeset
|
39 |
|
11298
9fcdf0969d53
Update libav API, keeping forward and backward compatibility
Vittorio Giovara <vittorio.giovara@gmail.com>
parents:
11046
diff
changeset
|
40 |
#if LIBAVCODEC_VERSION_MAJOR < 55 |
9fcdf0969d53
Update libav API, keeping forward and backward compatibility
Vittorio Giovara <vittorio.giovara@gmail.com>
parents:
11046
diff
changeset
|
41 |
#define AVCodecID CodecID |
9fcdf0969d53
Update libav API, keeping forward and backward compatibility
Vittorio Giovara <vittorio.giovara@gmail.com>
parents:
11046
diff
changeset
|
42 |
#endif |
9fcdf0969d53
Update libav API, keeping forward and backward compatibility
Vittorio Giovara <vittorio.giovara@gmail.com>
parents:
11046
diff
changeset
|
43 |
|
9fcdf0969d53
Update libav API, keeping forward and backward compatibility
Vittorio Giovara <vittorio.giovara@gmail.com>
parents:
11046
diff
changeset
|
44 |
#if LIBAVFORMAT_VERSION_MAJOR < 54 |
9fcdf0969d53
Update libav API, keeping forward and backward compatibility
Vittorio Giovara <vittorio.giovara@gmail.com>
parents:
11046
diff
changeset
|
45 |
#define avformat_find_stream_info(x, y) av_find_stream_info(x) |
9fcdf0969d53
Update libav API, keeping forward and backward compatibility
Vittorio Giovara <vittorio.giovara@gmail.com>
parents:
11046
diff
changeset
|
46 |
#define avformat_close_input(x) av_close_input_file(*(x)) |
9fcdf0969d53
Update libav API, keeping forward and backward compatibility
Vittorio Giovara <vittorio.giovara@gmail.com>
parents:
11046
diff
changeset
|
47 |
#endif |
9fcdf0969d53
Update libav API, keeping forward and backward compatibility
Vittorio Giovara <vittorio.giovara@gmail.com>
parents:
11046
diff
changeset
|
48 |
|
9fcdf0969d53
Update libav API, keeping forward and backward compatibility
Vittorio Giovara <vittorio.giovara@gmail.com>
parents:
11046
diff
changeset
|
49 |
#if LIBAVUTIL_VERSION_MAJOR < 54 |
9fcdf0969d53
Update libav API, keeping forward and backward compatibility
Vittorio Giovara <vittorio.giovara@gmail.com>
parents:
11046
diff
changeset
|
50 |
#define AVPixelFormat PixelFormat |
9fcdf0969d53
Update libav API, keeping forward and backward compatibility
Vittorio Giovara <vittorio.giovara@gmail.com>
parents:
11046
diff
changeset
|
51 |
#define AV_PIX_FMT_YUV420P PIX_FMT_YUV420P |
9429
7a97a554ac80
libavinteraction: fix typo and and compiling with modern libav
koda
parents:
9107
diff
changeset
|
52 |
#endif |
7a97a554ac80
libavinteraction: fix typo and and compiling with modern libav
koda
parents:
9107
diff
changeset
|
53 |
|
7897 | 54 |
struct Codec |
55 |
{ |
|
11298
9fcdf0969d53
Update libav API, keeping forward and backward compatibility
Vittorio Giovara <vittorio.giovara@gmail.com>
parents:
11046
diff
changeset
|
56 |
AVCodecID id; |
7897 | 57 |
bool isAudio; |
58 |
QString shortName; // used for identification |
|
59 |
QString longName; // used for displaying to user |
|
14630
957db6db1a49
Clean up code a bit in LibavInteraction
Wuzzy <Wuzzy2@mail.ru>
parents:
13286
diff
changeset
|
60 |
bool isRecommended; |
7897 | 61 |
}; |
62 |
||
63 |
struct Format |
|
64 |
{ |
|
65 |
QString shortName; |
|
66 |
QString longName; |
|
14630
957db6db1a49
Clean up code a bit in LibavInteraction
Wuzzy <Wuzzy2@mail.ru>
parents:
13286
diff
changeset
|
67 |
bool isRecommended; |
7897 | 68 |
QString extension; |
69 |
QVector<Codec*> codecs; |
|
70 |
}; |
|
71 |
||
72 |
QList<Codec> codecs; |
|
73 |
QMap<QString,Format> formats; |
|
74 |
||
75 |
// test if given format supports given codec |
|
15834 | 76 |
#if LIBAVCODEC_VERSION_MAJOR >= 59 |
77 |
bool FormatQueryCodec(const AVOutputFormat *ofmt, enum AVCodecID codec_id) |
|
78 |
#else |
|
11298
9fcdf0969d53
Update libav API, keeping forward and backward compatibility
Vittorio Giovara <vittorio.giovara@gmail.com>
parents:
11046
diff
changeset
|
79 |
bool FormatQueryCodec(AVOutputFormat *ofmt, enum AVCodecID codec_id) |
15834 | 80 |
#endif |
7897 | 81 |
{ |
82 |
#if LIBAVFORMAT_VERSION_MAJOR >= 54 |
|
83 |
return avformat_query_codec(ofmt, codec_id, FF_COMPLIANCE_NORMAL) == 1; |
|
84 |
#else |
|
85 |
if (ofmt->codec_tag) |
|
86 |
return !!av_codec_get_tag(ofmt->codec_tag, codec_id); |
|
87 |
return codec_id == ofmt->video_codec || codec_id == ofmt->audio_codec; |
|
88 |
#endif |
|
89 |
} |
|
90 |
||
91 |
LibavInteraction::LibavInteraction() : QObject() |
|
92 |
{ |
|
15834 | 93 |
#if LIBAVCODEC_VERSION_MAJOR < 59 |
7897 | 94 |
// initialize libav and register all codecs and formats |
95 |
av_register_all(); |
|
15834 | 96 |
#endif |
7897 | 97 |
|
98 |
// get list of all codecs |
|
15834 | 99 |
#if LIBAVCODEC_VERSION_MAJOR >= 59 |
100 |
const AVCodec* pCodec = NULL; |
|
101 |
void* i = 0; |
|
102 |
while ((pCodec = av_codec_iterate(&i))) |
|
103 |
#else |
|
7897 | 104 |
AVCodec* pCodec = NULL; |
8065 | 105 |
while ((pCodec = av_codec_next(pCodec))) |
15834 | 106 |
#endif |
7897 | 107 |
{ |
108 |
if (!av_codec_is_encoder(pCodec)) |
|
109 |
continue; |
|
110 |
||
111 |
if (pCodec->type != AVMEDIA_TYPE_VIDEO && pCodec->type != AVMEDIA_TYPE_AUDIO) |
|
112 |
continue; |
|
113 |
||
114 |
// this encoders seems to be buggy |
|
115 |
if (strcmp(pCodec->name, "rv10") == 0 || strcmp(pCodec->name, "rv20") == 0) |
|
116 |
continue; |
|
117 |
||
14631
92ebe33c5eb6
VideoRec: Hide libaom-av1 codec in frontend, it's experimental
Wuzzy <Wuzzy2@mail.ru>
parents:
14630
diff
changeset
|
118 |
// this encoder is experimental (as of Jan 17, 2019) |
92ebe33c5eb6
VideoRec: Hide libaom-av1 codec in frontend, it's experimental
Wuzzy <Wuzzy2@mail.ru>
parents:
14630
diff
changeset
|
119 |
if (strcmp(pCodec->name, "libaom-av1") == 0) |
92ebe33c5eb6
VideoRec: Hide libaom-av1 codec in frontend, it's experimental
Wuzzy <Wuzzy2@mail.ru>
parents:
14630
diff
changeset
|
120 |
continue; |
92ebe33c5eb6
VideoRec: Hide libaom-av1 codec in frontend, it's experimental
Wuzzy <Wuzzy2@mail.ru>
parents:
14630
diff
changeset
|
121 |
|
7897 | 122 |
// doesn't support stereo sound |
123 |
if (strcmp(pCodec->name, "real_144") == 0) |
|
124 |
continue; |
|
125 |
||
126 |
if (!pCodec->long_name || strlen(pCodec->long_name) == 0) |
|
127 |
continue; |
|
128 |
||
129 |
if (pCodec->type == AVMEDIA_TYPE_VIDEO) |
|
130 |
{ |
|
131 |
if (pCodec->supported_framerates != NULL) |
|
132 |
continue; |
|
133 |
||
134 |
// check if codec supports yuv 4:2:0 format |
|
135 |
if (!pCodec->pix_fmts) |
|
136 |
continue; |
|
137 |
bool yuv420Supported = false; |
|
11299
64ad779be7bf
Specify the enum type for Pixel and Sample formats
Vittorio Giovara <vittorio.giovara@gmail.com>
parents:
11298
diff
changeset
|
138 |
for (const enum AVPixelFormat* pfmt = pCodec->pix_fmts; *pfmt != -1; pfmt++) |
11298
9fcdf0969d53
Update libav API, keeping forward and backward compatibility
Vittorio Giovara <vittorio.giovara@gmail.com>
parents:
11046
diff
changeset
|
139 |
if (*pfmt == AV_PIX_FMT_YUV420P) |
7897 | 140 |
{ |
141 |
yuv420Supported = true; |
|
142 |
break; |
|
143 |
} |
|
144 |
if (!yuv420Supported) |
|
145 |
continue; |
|
146 |
} |
|
147 |
if (pCodec->type == AVMEDIA_TYPE_AUDIO) |
|
148 |
{ |
|
149 |
// check if codec supports signed 16-bit format |
|
150 |
if (!pCodec->sample_fmts) |
|
151 |
continue; |
|
152 |
bool s16Supported = false; |
|
11299
64ad779be7bf
Specify the enum type for Pixel and Sample formats
Vittorio Giovara <vittorio.giovara@gmail.com>
parents:
11298
diff
changeset
|
153 |
for (const enum AVSampleFormat* pfmt = pCodec->sample_fmts; *pfmt != -1; pfmt++) |
7897 | 154 |
if (*pfmt == AV_SAMPLE_FMT_S16) |
155 |
{ |
|
156 |
s16Supported = true; |
|
157 |
break; |
|
158 |
} |
|
159 |
if (!s16Supported) |
|
160 |
continue; |
|
161 |
} |
|
162 |
// add codec to list of codecs |
|
163 |
codecs.push_back(Codec()); |
|
164 |
Codec & codec = codecs.back(); |
|
165 |
codec.id = pCodec->id; |
|
166 |
codec.isAudio = pCodec->type == AVMEDIA_TYPE_AUDIO; |
|
167 |
codec.shortName = pCodec->name; |
|
168 |
codec.longName = pCodec->long_name; |
|
169 |
||
14630
957db6db1a49
Clean up code a bit in LibavInteraction
Wuzzy <Wuzzy2@mail.ru>
parents:
13286
diff
changeset
|
170 |
codec.isRecommended = false; |
7897 | 171 |
if (strcmp(pCodec->name, "libx264") == 0) |
172 |
{ |
|
173 |
codec.longName = "H.264/MPEG-4 Part 10 AVC (x264)"; |
|
14630
957db6db1a49
Clean up code a bit in LibavInteraction
Wuzzy <Wuzzy2@mail.ru>
parents:
13286
diff
changeset
|
174 |
codec.isRecommended = true; |
7897 | 175 |
} |
176 |
else if (strcmp(pCodec->name, "libxvid") == 0) |
|
177 |
{ |
|
178 |
codec.longName = "MPEG-4 Part 2 (Xvid)"; |
|
14630
957db6db1a49
Clean up code a bit in LibavInteraction
Wuzzy <Wuzzy2@mail.ru>
parents:
13286
diff
changeset
|
179 |
codec.isRecommended = true; |
7897 | 180 |
} |
181 |
else if (strcmp(pCodec->name, "libmp3lame") == 0) |
|
182 |
{ |
|
183 |
codec.longName = "MP3 (MPEG audio layer 3) (LAME)"; |
|
14630
957db6db1a49
Clean up code a bit in LibavInteraction
Wuzzy <Wuzzy2@mail.ru>
parents:
13286
diff
changeset
|
184 |
codec.isRecommended = true; |
7897 | 185 |
} |
186 |
else |
|
187 |
codec.longName = pCodec->long_name; |
|
188 |
||
189 |
if (strcmp(pCodec->name, "mpeg4") == 0 || strcmp(pCodec->name, "ac3_fixed") == 0) |
|
14630
957db6db1a49
Clean up code a bit in LibavInteraction
Wuzzy <Wuzzy2@mail.ru>
parents:
13286
diff
changeset
|
190 |
codec.isRecommended = true; |
7897 | 191 |
} |
192 |
||
193 |
// get list of all formats |
|
15834 | 194 |
#if LIBAVCODEC_VERSION_MAJOR >= 59 |
195 |
const AVOutputFormat* pFormat = NULL; |
|
196 |
i = 0; |
|
197 |
while ((pFormat = av_muxer_iterate(&i))) |
|
198 |
#else |
|
7897 | 199 |
AVOutputFormat* pFormat = NULL; |
8065 | 200 |
while ((pFormat = av_oformat_next(pFormat))) |
15834 | 201 |
#endif |
7897 | 202 |
{ |
203 |
if (!pFormat->extensions) |
|
204 |
continue; |
|
205 |
||
206 |
// skip some strange formats to not confuse users |
|
207 |
if (strstr(pFormat->long_name, "raw")) |
|
208 |
continue; |
|
209 |
||
210 |
Format format; |
|
211 |
bool hasVideoCodec = false; |
|
212 |
for (QList<Codec>::iterator codec = codecs.begin(); codec != codecs.end(); ++codec) |
|
213 |
{ |
|
214 |
if (!FormatQueryCodec(pFormat, codec->id)) |
|
215 |
continue; |
|
216 |
format.codecs.push_back(&*codec); |
|
217 |
if (!codec->isAudio) |
|
218 |
hasVideoCodec = true; |
|
219 |
} |
|
220 |
if (!hasVideoCodec) |
|
221 |
continue; |
|
222 |
||
223 |
QString ext(pFormat->extensions); |
|
224 |
ext.truncate(strcspn(pFormat->extensions, ",")); |
|
225 |
format.extension = ext; |
|
226 |
format.shortName = pFormat->name; |
|
227 |
format.longName = QString("%1 (*.%2)").arg(pFormat->long_name).arg(ext); |
|
228 |
||
14630
957db6db1a49
Clean up code a bit in LibavInteraction
Wuzzy <Wuzzy2@mail.ru>
parents:
13286
diff
changeset
|
229 |
format.isRecommended = strcmp(pFormat->name, "mp4") == 0 || strcmp(pFormat->name, "avi") == 0; |
7897 | 230 |
|
231 |
formats[pFormat->name] = format; |
|
232 |
} |
|
233 |
} |
|
234 |
||
235 |
void LibavInteraction::fillFormats(QComboBox * pFormats) |
|
236 |
{ |
|
237 |
// first insert recomended formats |
|
238 |
foreach(const Format & format, formats) |
|
14630
957db6db1a49
Clean up code a bit in LibavInteraction
Wuzzy <Wuzzy2@mail.ru>
parents:
13286
diff
changeset
|
239 |
if (format.isRecommended) |
7897 | 240 |
pFormats->addItem(format.longName, format.shortName); |
241 |
||
242 |
// remember where to place separator between recomended and other formats |
|
243 |
int sep = pFormats->count(); |
|
244 |
||
245 |
// insert remaining formats |
|
246 |
foreach(const Format & format, formats) |
|
14630
957db6db1a49
Clean up code a bit in LibavInteraction
Wuzzy <Wuzzy2@mail.ru>
parents:
13286
diff
changeset
|
247 |
if (!format.isRecommended) |
7897 | 248 |
pFormats->addItem(format.longName, format.shortName); |
249 |
||
250 |
// insert separator if necessary |
|
251 |
if (sep != 0 && sep != pFormats->count()) |
|
252 |
pFormats->insertSeparator(sep); |
|
253 |
} |
|
254 |
||
255 |
void LibavInteraction::fillCodecs(const QString & fmt, QComboBox * pVCodecs, QComboBox * pACodecs) |
|
256 |
{ |
|
257 |
Format & format = formats[fmt]; |
|
258 |
||
259 |
// first insert recomended codecs |
|
260 |
foreach(Codec * codec, format.codecs) |
|
261 |
{ |
|
14630
957db6db1a49
Clean up code a bit in LibavInteraction
Wuzzy <Wuzzy2@mail.ru>
parents:
13286
diff
changeset
|
262 |
if (codec->isRecommended) |
7897 | 263 |
{ |
264 |
if (codec->isAudio) |
|
265 |
pACodecs->addItem(codec->longName, codec->shortName); |
|
266 |
else |
|
267 |
pVCodecs->addItem(codec->longName, codec->shortName); |
|
268 |
} |
|
269 |
} |
|
270 |
||
271 |
// remember where to place separators between recomended and other codecs |
|
272 |
int vsep = pVCodecs->count(); |
|
273 |
int asep = pACodecs->count(); |
|
274 |
||
275 |
// insert remaining codecs |
|
276 |
foreach(Codec * codec, format.codecs) |
|
277 |
{ |
|
14630
957db6db1a49
Clean up code a bit in LibavInteraction
Wuzzy <Wuzzy2@mail.ru>
parents:
13286
diff
changeset
|
278 |
if (!codec->isRecommended) |
7897 | 279 |
{ |
280 |
if (codec->isAudio) |
|
281 |
pACodecs->addItem(codec->longName, codec->shortName); |
|
282 |
else |
|
283 |
pVCodecs->addItem(codec->longName, codec->shortName); |
|
284 |
} |
|
285 |
} |
|
286 |
||
287 |
// insert separators if necessary |
|
288 |
if (vsep != 0 && vsep != pVCodecs->count()) |
|
289 |
pVCodecs->insertSeparator(vsep); |
|
290 |
if (asep != 0 && asep != pACodecs->count()) |
|
291 |
pACodecs->insertSeparator(asep); |
|
292 |
} |
|
293 |
||
294 |
QString LibavInteraction::getExtension(const QString & format) |
|
295 |
{ |
|
296 |
return formats[format].extension; |
|
297 |
} |
|
298 |
||
299 |
// get information abaout file (duration, resolution etc) in multiline string |
|
300 |
QString LibavInteraction::getFileInfo(const QString & filepath) |
|
301 |
{ |
|
302 |
AVFormatContext* pContext = NULL; |
|
303 |
QByteArray utf8path = filepath.toUtf8(); |
|
304 |
if (avformat_open_input(&pContext, utf8path.data(), NULL, NULL) < 0) |
|
305 |
return ""; |
|
306 |
if (avformat_find_stream_info(pContext, NULL) < 0) |
|
307 |
return ""; |
|
308 |
||
309 |
int s = float(pContext->duration)/AV_TIME_BASE; |
|
12239
8db93a3a29dc
Use standard units and abbreviations in frontend
Wuzzy <almikes@aol.com>
parents:
11852
diff
changeset
|
310 |
//: Duration in minutes and seconds (SI units) |
8db93a3a29dc
Use standard units and abbreviations in frontend
Wuzzy <almikes@aol.com>
parents:
11852
diff
changeset
|
311 |
QString desc = tr("Duration: %1min %2s").arg(s/60).arg(s%60) + "\n"; |
7897 | 312 |
for (int i = 0; i < (int)pContext->nb_streams; i++) |
313 |
{ |
|
314 |
AVStream* pStream = pContext->streams[i]; |
|
315 |
if (!pStream) |
|
316 |
continue; |
|
15834 | 317 |
#if LIBAVCODEC_VERSION_MAJOR >= 59 |
318 |
const AVCodec *st_codec = avcodec_find_decoder(pContext->streams[i]->codecpar->codec_id); |
|
319 |
AVCodecContext* pCodec = avcodec_alloc_context3(st_codec); |
|
320 |
avcodec_parameters_to_context(pCodec, pContext->streams[i]->codecpar); |
|
321 |
#else |
|
7897 | 322 |
AVCodecContext* pCodec = pContext->streams[i]->codec; |
15834 | 323 |
#endif |
7897 | 324 |
if (!pCodec) |
325 |
continue; |
|
326 |
||
13286
1fbf2ac1f13e
Videos frontend page: Locale-aware text formatting
Wuzzy <Wuzzy2@mail.ru>
parents:
13226
diff
changeset
|
327 |
|
15834 | 328 |
#if LIBAVCODEC_VERSION_MAJOR >= 59 |
329 |
const AVCodec* pDecoder = avcodec_find_decoder(pCodec->codec_id); |
|
330 |
#else |
|
13286
1fbf2ac1f13e
Videos frontend page: Locale-aware text formatting
Wuzzy <Wuzzy2@mail.ru>
parents:
13226
diff
changeset
|
331 |
AVCodec* pDecoder = avcodec_find_decoder(pCodec->codec_id); |
15834 | 332 |
#endif |
13286
1fbf2ac1f13e
Videos frontend page: Locale-aware text formatting
Wuzzy <Wuzzy2@mail.ru>
parents:
13226
diff
changeset
|
333 |
QString decoderName = pDecoder ? pDecoder->name : tr("unknown"); |
7897 | 334 |
if (pCodec->codec_type == AVMEDIA_TYPE_VIDEO) |
335 |
{ |
|
336 |
if (pStream->avg_frame_rate.den) |
|
337 |
{ |
|
338 |
float fps = float(pStream->avg_frame_rate.num)/pStream->avg_frame_rate.den; |
|
13286
1fbf2ac1f13e
Videos frontend page: Locale-aware text formatting
Wuzzy <Wuzzy2@mail.ru>
parents:
13226
diff
changeset
|
339 |
//: Video metadata. %1 = video width, %2 = video height, %3 = frames per second = %4 = decoder name |
1fbf2ac1f13e
Videos frontend page: Locale-aware text formatting
Wuzzy <Wuzzy2@mail.ru>
parents:
13226
diff
changeset
|
340 |
desc += QString(tr("Video: %1x%2, %3 FPS, %4")).arg(pCodec->width).arg(pCodec->height).arg(QLocale().toString(fps, 'f', 2)).arg(decoderName); |
1fbf2ac1f13e
Videos frontend page: Locale-aware text formatting
Wuzzy <Wuzzy2@mail.ru>
parents:
13226
diff
changeset
|
341 |
} |
1fbf2ac1f13e
Videos frontend page: Locale-aware text formatting
Wuzzy <Wuzzy2@mail.ru>
parents:
13226
diff
changeset
|
342 |
else |
1fbf2ac1f13e
Videos frontend page: Locale-aware text formatting
Wuzzy <Wuzzy2@mail.ru>
parents:
13226
diff
changeset
|
343 |
{ |
1fbf2ac1f13e
Videos frontend page: Locale-aware text formatting
Wuzzy <Wuzzy2@mail.ru>
parents:
13226
diff
changeset
|
344 |
//: Video metadata. %1 = video width, %2 = video height, %3 = decoder name |
1fbf2ac1f13e
Videos frontend page: Locale-aware text formatting
Wuzzy <Wuzzy2@mail.ru>
parents:
13226
diff
changeset
|
345 |
desc += QString(tr("Video: %1x%2, %3")).arg(pCodec->width).arg(pCodec->height).arg(decoderName); |
7897 | 346 |
} |
347 |
} |
|
348 |
else if (pCodec->codec_type == AVMEDIA_TYPE_AUDIO) |
|
13286
1fbf2ac1f13e
Videos frontend page: Locale-aware text formatting
Wuzzy <Wuzzy2@mail.ru>
parents:
13226
diff
changeset
|
349 |
{ |
7897 | 350 |
desc += tr("Audio: "); |
13286
1fbf2ac1f13e
Videos frontend page: Locale-aware text formatting
Wuzzy <Wuzzy2@mail.ru>
parents:
13226
diff
changeset
|
351 |
desc += decoderName; |
1fbf2ac1f13e
Videos frontend page: Locale-aware text formatting
Wuzzy <Wuzzy2@mail.ru>
parents:
13226
diff
changeset
|
352 |
} |
7897 | 353 |
else |
354 |
continue; |
|
355 |
desc += "\n"; |
|
356 |
} |
|
357 |
AVDictionaryEntry* pComment = av_dict_get(pContext->metadata, "comment", NULL, 0); |
|
358 |
if (pComment) |
|
13226
4028d7f85233
Make video metadata strings translatable in frontend
Wuzzy <Wuzzy2@mail.ru>
parents:
12239
diff
changeset
|
359 |
{ |
4028d7f85233
Make video metadata strings translatable in frontend
Wuzzy <Wuzzy2@mail.ru>
parents:
12239
diff
changeset
|
360 |
// Video comment. We expect a simple key value storage in a particular format |
4028d7f85233
Make video metadata strings translatable in frontend
Wuzzy <Wuzzy2@mail.ru>
parents:
12239
diff
changeset
|
361 |
// and parse it here so the key names can be localized. |
4028d7f85233
Make video metadata strings translatable in frontend
Wuzzy <Wuzzy2@mail.ru>
parents:
12239
diff
changeset
|
362 |
desc += QString("\n"); |
4028d7f85233
Make video metadata strings translatable in frontend
Wuzzy <Wuzzy2@mail.ru>
parents:
12239
diff
changeset
|
363 |
QStringList strings = QString(pComment->value).split('\n'); |
4028d7f85233
Make video metadata strings translatable in frontend
Wuzzy <Wuzzy2@mail.ru>
parents:
12239
diff
changeset
|
364 |
QString sPlayer, sTheme, sMap, sRecord; |
4028d7f85233
Make video metadata strings translatable in frontend
Wuzzy <Wuzzy2@mail.ru>
parents:
12239
diff
changeset
|
365 |
for(int i=0; i < strings.count(); i++) |
4028d7f85233
Make video metadata strings translatable in frontend
Wuzzy <Wuzzy2@mail.ru>
parents:
12239
diff
changeset
|
366 |
{ |
4028d7f85233
Make video metadata strings translatable in frontend
Wuzzy <Wuzzy2@mail.ru>
parents:
12239
diff
changeset
|
367 |
QString s = strings.at(i); |
4028d7f85233
Make video metadata strings translatable in frontend
Wuzzy <Wuzzy2@mail.ru>
parents:
12239
diff
changeset
|
368 |
// Original key names are in English, like: |
4028d7f85233
Make video metadata strings translatable in frontend
Wuzzy <Wuzzy2@mail.ru>
parents:
12239
diff
changeset
|
369 |
// Key: Value |
4028d7f85233
Make video metadata strings translatable in frontend
Wuzzy <Wuzzy2@mail.ru>
parents:
12239
diff
changeset
|
370 |
if (s.startsWith("Player: ")) |
4028d7f85233
Make video metadata strings translatable in frontend
Wuzzy <Wuzzy2@mail.ru>
parents:
12239
diff
changeset
|
371 |
sPlayer = QString(s.mid(8)); |
4028d7f85233
Make video metadata strings translatable in frontend
Wuzzy <Wuzzy2@mail.ru>
parents:
12239
diff
changeset
|
372 |
else if (s.startsWith("Theme: ")) |
4028d7f85233
Make video metadata strings translatable in frontend
Wuzzy <Wuzzy2@mail.ru>
parents:
12239
diff
changeset
|
373 |
sTheme = QString(s.mid(7)); |
4028d7f85233
Make video metadata strings translatable in frontend
Wuzzy <Wuzzy2@mail.ru>
parents:
12239
diff
changeset
|
374 |
else if (s.startsWith("Map: ")) |
4028d7f85233
Make video metadata strings translatable in frontend
Wuzzy <Wuzzy2@mail.ru>
parents:
12239
diff
changeset
|
375 |
sMap = QString(s.mid(5)); |
4028d7f85233
Make video metadata strings translatable in frontend
Wuzzy <Wuzzy2@mail.ru>
parents:
12239
diff
changeset
|
376 |
else if (s.startsWith("Record: ")) |
4028d7f85233
Make video metadata strings translatable in frontend
Wuzzy <Wuzzy2@mail.ru>
parents:
12239
diff
changeset
|
377 |
sRecord = QString(s.mid(8)); |
4028d7f85233
Make video metadata strings translatable in frontend
Wuzzy <Wuzzy2@mail.ru>
parents:
12239
diff
changeset
|
378 |
} |
4028d7f85233
Make video metadata strings translatable in frontend
Wuzzy <Wuzzy2@mail.ru>
parents:
12239
diff
changeset
|
379 |
if(!sPlayer.isNull()) |
4028d7f85233
Make video metadata strings translatable in frontend
Wuzzy <Wuzzy2@mail.ru>
parents:
12239
diff
changeset
|
380 |
desc += QString(tr("Player: %1")).arg(sPlayer) + "\n"; |
4028d7f85233
Make video metadata strings translatable in frontend
Wuzzy <Wuzzy2@mail.ru>
parents:
12239
diff
changeset
|
381 |
if(!sTheme.isNull()) |
4028d7f85233
Make video metadata strings translatable in frontend
Wuzzy <Wuzzy2@mail.ru>
parents:
12239
diff
changeset
|
382 |
desc += QString(tr("Theme: %1")).arg(sTheme) + "\n"; |
4028d7f85233
Make video metadata strings translatable in frontend
Wuzzy <Wuzzy2@mail.ru>
parents:
12239
diff
changeset
|
383 |
if(!sMap.isNull()) |
4028d7f85233
Make video metadata strings translatable in frontend
Wuzzy <Wuzzy2@mail.ru>
parents:
12239
diff
changeset
|
384 |
desc += QString(tr("Map: %1")).arg(sMap) + "\n"; |
4028d7f85233
Make video metadata strings translatable in frontend
Wuzzy <Wuzzy2@mail.ru>
parents:
12239
diff
changeset
|
385 |
if(!sRecord.isNull()) |
4028d7f85233
Make video metadata strings translatable in frontend
Wuzzy <Wuzzy2@mail.ru>
parents:
12239
diff
changeset
|
386 |
//: As in ‘recording’ |
4028d7f85233
Make video metadata strings translatable in frontend
Wuzzy <Wuzzy2@mail.ru>
parents:
12239
diff
changeset
|
387 |
desc += QString(tr("Record: %1")).arg(sRecord); |
4028d7f85233
Make video metadata strings translatable in frontend
Wuzzy <Wuzzy2@mail.ru>
parents:
12239
diff
changeset
|
388 |
} |
7897 | 389 |
avformat_close_input(&pContext); |
390 |
return desc; |
|
391 |
} |
|
392 |
||
393 |
#else |
|
394 |
LibavInteraction::LibavInteraction() : QObject() |
|
395 |
{ |
|
396 |
||
397 |
} |
|
398 |
||
399 |
void LibavInteraction::fillFormats(QComboBox * pFormats) |
|
400 |
{ |
|
401 |
Q_UNUSED(pFormats); |
|
402 |
} |
|
403 |
||
404 |
void LibavInteraction::fillCodecs(const QString & format, QComboBox * pVCodecs, QComboBox * pACodecs) |
|
405 |
{ |
|
406 |
Q_UNUSED(format); |
|
407 |
Q_UNUSED(pVCodecs); |
|
408 |
Q_UNUSED(pACodecs); |
|
409 |
} |
|
410 |
||
411 |
QString LibavInteraction::getExtension(const QString & format) |
|
412 |
{ |
|
413 |
Q_UNUSED(format); |
|
414 |
||
415 |
return QString(); |
|
416 |
} |
|
417 |
||
418 |
QString LibavInteraction::getFileInfo(const QString & filepath) |
|
419 |
{ |
|
420 |
Q_UNUSED(filepath); |
|
421 |
||
422 |
return QString(); |
|
423 |
} |
|
424 |
#endif |
|
425 |
||
426 |
LibavInteraction & LibavInteraction::instance() |
|
427 |
{ |
|
428 |
static LibavInteraction instance; |
|
429 |
return instance; |
|
430 |
} |