1 /* ============================================================
2 *
3 * This file is a part of digiKam project
4 * https://www.digikam.org
5 *
6 * Date : 2017-05-25
7 * Description : a tool to generate video slideshow from images.
8 *
9 * Copyright (C) 2017-2021 by Gilles Caulier <caulier dot gilles at gmail dot com>
10 *
11 * This program is free software; you can redistribute it
12 * and/or modify it under the terms of the GNU General
13 * Public License as published by the Free Software Foundation;
14 * either version 2, or (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * ============================================================ */
22
23 #include "vidslidesettings.h"
24
25 // Qt includes
26
27 #include <QStandardPaths>
28
29 // KDE includes
30
31 #include <klocalizedstring.h>
32 #include <kconfiggroup.h>
33
34 namespace Digikam
35 {
36
VidSlideSettings()37 VidSlideSettings::VidSlideSettings()
38 : selMode (IMAGES),
39 transition (TransitionMngr::None),
40 imgFrames (125),
41 abitRate (64000),
42 vbitRate (VBR12),
43 vStandard (PAL),
44 vType (BLUERAY),
45 vCodec (X264),
46 vFormat (MP4),
47 vEffect (EffectMngr::None),
48 conflictRule (FileSaveConflictBox::OVERWRITE),
49 outputDir (QUrl::fromLocalFile(QStandardPaths::writableLocation(QStandardPaths::MoviesLocation))),
50 outputPlayer (INTERNAL)
51 {
52 }
53
~VidSlideSettings()54 VidSlideSettings::~VidSlideSettings()
55 {
56 }
57
readSettings(KConfigGroup & group)58 void VidSlideSettings::readSettings(KConfigGroup& group)
59 {
60 selMode = (Selection)group.readEntry("SelMode",
61 (int)IMAGES);
62 imgFrames = group.readEntry("ImgFrames",
63 125);
64 vStandard = (VidStd)group.readEntry("VStandard",
65 (int)PAL);
66 vbitRate = (VidBitRate)group.readEntry("VBitRate",
67 (int)VBR12);
68 vCodec = (VidCodec)group.readEntry("VCodec",
69 (int)X264);
70 vType = (VidType)group.readEntry("VType",
71 (int)BLUERAY);
72 vFormat = (VidFormat)group.readEntry("VFormat",
73 (int)MP4);
74 vEffect = (EffectMngr::EffectType)group.readEntry("VEffect",
75 (int)EffectMngr::None);
76 abitRate = group.readEntry("ABitRate",
77 64000);
78 transition = (TransitionMngr::TransType)group.readEntry("Transition",
79 (int)TransitionMngr::None);
80 conflictRule = (FileSaveConflictBox::ConflictRule)group.readEntry("ConflictRule",
81 (int)FileSaveConflictBox::OVERWRITE);
82 outputDir = group.readEntry("OutputDir",
83 QUrl::fromLocalFile(QStandardPaths::writableLocation(QStandardPaths::MoviesLocation)));
84 outputPlayer = (VidPlayer)group.readEntry("OutputPlayer",
85 (int)INTERNAL);
86 }
87
writeSettings(KConfigGroup & group)88 void VidSlideSettings::writeSettings(KConfigGroup& group)
89 {
90 group.writeEntry("SelMode", (int)selMode);
91 group.writeEntry("ImgFrames", imgFrames);
92 group.writeEntry("VStandard", (int)vStandard);
93 group.writeEntry("VBitRate", (int)vbitRate);
94 group.writeEntry("VCodec", (int)vCodec);
95 group.writeEntry("VType", (int)vType);
96 group.writeEntry("VFormat", (int)vFormat);
97 group.writeEntry("VEffect", (int)vEffect);
98 group.writeEntry("Transition", (int)transition);
99 group.writeEntry("ABitRate", abitRate);
100 group.writeEntry("ConflictRule", (int)conflictRule);
101 group.writeEntry("OutputDir", outputDir);
102 group.writeEntry("OutputPlayer", (int)outputPlayer);
103 }
104
videoSize() const105 QSize VidSlideSettings::videoSize() const
106 {
107 return videoSizeFromType(vType);
108 }
109
videoSizeFromType(VidType type)110 QSize VidSlideSettings::videoSizeFromType(VidType type)
111 {
112 QSize s;
113
114 switch (type)
115 {
116 case QVGA:
117 {
118 s = QSize(320, 180);
119 break;
120 }
121
122 case VCD1:
123 {
124 s = QSize(352, 240);
125 break;
126 }
127
128 case VCD2:
129 {
130 s = QSize(352, 288);
131 break;
132 }
133
134 case CVD1:
135 {
136 s = QSize(352, 480);
137 break;
138 }
139
140 case CVD2:
141 {
142 s = QSize(352, 576);
143 break;
144 }
145
146 case HVGA:
147 {
148 s = QSize(480, 270);
149 break;
150 }
151
152 case SVCD1:
153 {
154 s = QSize(480, 480);
155 break;
156 }
157
158 case SDTV1:
159 {
160 s = QSize(528, 480);
161 break;
162 }
163
164 case SDTV2:
165 {
166 s = QSize(544, 480);
167 break;
168 }
169
170 case EDTV1:
171 {
172 s = QSize(544, 576);
173 break;
174 }
175
176 case SVCD2:
177 {
178 s = QSize(480, 576);
179 break;
180 }
181
182 case EGA:
183 {
184 s = QSize(640, 350);
185 break;
186 }
187
188 case VGA:
189 {
190 s = QSize(640, 480);
191 break;
192 }
193
194 case SDTV3:
195 {
196 s = QSize(704, 480);
197 break;
198 }
199
200 case EDTV2:
201 {
202 s = QSize(704, 576);
203 break;
204 }
205
206 case DVD1:
207 {
208 s = QSize(720, 480);
209 break;
210 }
211
212 case DVD2:
213 {
214 s = QSize(720, 576);
215 break;
216 }
217
218 case WVGA:
219 {
220 s = QSize(800, 450);
221 break;
222 }
223
224 case SVGA:
225 {
226 s = QSize(800, 600);
227 break;
228 }
229
230 case DVGA:
231 {
232 s = QSize(960, 640);
233 break;
234 }
235
236 case XVGA:
237 {
238 s = QSize(1024, 576);
239 break;
240 }
241
242 case HDTV:
243 {
244 s = QSize(1280, 720);
245 break;
246 }
247
248 case WXGA1:
249 {
250 s = QSize(1280, 768);
251 break;
252 }
253
254 case WXGA2:
255 {
256 s = QSize(1280, 800);
257 break;
258 }
259
260 case SXGA:
261 {
262 s = QSize(1280, 1024);
263 break;
264 }
265
266 case SXGAPLUS:
267 {
268 s = QSize(1400, 1050);
269 break;
270 }
271
272 case WSXGA:
273 {
274 s = QSize(1440, 900);
275 break;
276 }
277
278 case UXGA:
279 {
280 s = QSize(1600, 1200);
281 break;
282 }
283
284 case HDPLUS:
285 {
286 s = QSize(1600, 900);
287 break;
288 }
289
290 case WSXGAPLUS:
291 {
292 s = QSize(1680, 1050);
293 break;
294 }
295
296 case WUXGA:
297 {
298 s = QSize(1920, 1200);
299 break;
300 }
301
302 case TXGA:
303 {
304 s = QSize(1920, 1440);
305 break;
306 }
307
308 case QXGA:
309 {
310 s = QSize(2048, 1536);
311 break;
312 }
313
314 case UWFHD:
315 {
316 s = QSize(2560, 1080);
317 break;
318 }
319
320 case WQHD:
321 {
322 s = QSize(2560, 1440);
323 break;
324 }
325
326 case WQXGA:
327 {
328 s = QSize(2560, 1600);
329 break;
330 }
331
332 case QSXGA:
333 {
334 s = QSize(2560, 2048);
335 break;
336 }
337
338 case QSXGAPLUS:
339 {
340 s = QSize(2800, 2100);
341 break;
342 }
343
344 case WQXGAPLUS:
345 {
346 s = QSize(3200, 1800);
347 break;
348 }
349
350 case WQSXGA:
351 {
352 s = QSize(3200, 2048);
353 break;
354 }
355
356 case QUXGA:
357 {
358 s = QSize(3200, 2400);
359 break;
360 }
361
362 case UHD4K:
363 {
364 s = QSize(3840, 2160);
365 break;
366 }
367
368 case WQUXGA:
369 {
370 s = QSize(3840, 2400);
371 break;
372 }
373
374 case HXGA:
375 {
376 s = QSize(4096, 3072);
377 break;
378 }
379
380 case UHD5K:
381 {
382 s = QSize(5120, 2880);
383 break;
384 }
385
386 case WHXGA:
387 {
388 s = QSize(5120, 3200);
389 break;
390 }
391
392 case HSXGA:
393 {
394 s = QSize(5120, 4096);
395 break;
396 }
397
398 case UHD6K:
399 {
400 s = QSize(6016, 3384);
401 break;
402 }
403
404 case WHSXGA:
405 {
406 s = QSize(6400, 4096);
407 break;
408 }
409
410 case HUXGA:
411 {
412 s = QSize(6400, 4800);
413 break;
414 }
415
416 case UHD8K:
417 {
418 s = QSize(7680, 4320);
419 break;
420 }
421
422 case WHUXGA:
423 {
424 s = QSize(7680, 4800);
425 break;
426 }
427
428 case UW10K:
429 {
430 s = QSize(10240, 4320);
431 break;
432 }
433
434 case UW16K:
435 {
436 s = QSize(15360, 8640);
437 break;
438 }
439
440 default: // BLUERAY
441 {
442 s = QSize(1920, 1080);
443 break;
444 }
445 }
446
447 return s;
448 }
449
isVideoTVFormat(VidType type)450 bool VidSlideSettings::isVideoTVFormat(VidType type)
451 {
452 switch (type)
453 {
454 case VCD1:
455 case VCD2:
456 case CVD1:
457 case CVD2:
458 case SVCD1:
459 case SDTV1:
460 case SDTV2:
461 case EDTV1:
462 case SVCD2:
463 case SDTV3:
464 case EDTV2:
465 case DVD1:
466 case DVD2:
467 case HDTV:
468 case BLUERAY:
469 case UHD4K:
470 case UHD8K:
471 {
472 return true;
473 }
474
475 default:
476 {
477 return false;
478 }
479 }
480 }
481
videoTypeNames()482 QMap<VidSlideSettings::VidType, QString> VidSlideSettings::videoTypeNames()
483 {
484 QMap<VidType, QString> types;
485
486 types[QVGA] = i18nc("Video Type: QVGA", "QVGA - 320x180 - 16:9");
487 types[VCD1] = i18nc("Video Type: VCD1", "VCD - 352x240 - 7:5");
488 types[VCD2] = i18nc("Video Type: VCD2", "VCD - 352x288 - 6:5");
489 types[CVD1] = i18nc("Video Type: CVD1", "CVD - 352x480 - 4:3");
490 types[CVD2] = i18nc("Video Type: CVD2", "CVD - 352x576 - 16:9");
491 types[HVGA] = i18nc("Video Type: HVGA", "HVGA - 480x270 - 16:9");
492 types[SVCD1] = i18nc("Video Type: SVCD1", "SVCD - 480x480 - 1:1");
493 types[SDTV1] = i18nc("Video Type: SDTV1", "SDTV - 528x480 - 11:10");
494 types[SDTV2] = i18nc("Video Type: SDTV2", "SDTV - 544x480 - 17:15");
495 types[EDTV1] = i18nc("Video Type: EDTV1", "EDTV - 544x576 - 17:18");
496 types[SVCD2] = i18nc("Video Type: SVCD2", "SVCD - 480x576 - 5:6");
497 types[EGA] = i18nc("Video Type: EGA", "EGA - 640x350 - 16:9");
498 types[VGA] = i18nc("Video Type: VGA", "VGA - 640x480 - 4:3");
499 types[SDTV3] = i18nc("Video Type: SDTV3", "SDTV - 704x480 - 22:15");
500 types[EDTV2] = i18nc("Video Type: EDTV2", "EDTV - 704x576 - 11:9");
501 types[DVD1] = i18nc("Video Type: DVD", "DVD - 720x480 - 3:2");
502 types[DVD2] = i18nc("Video Type: DVD", "DVD - 720x576 - 5:4");
503 types[WVGA] = i18nc("Video Type: WVGA", "WVGA - 800x450 - 16:9");
504 types[SVGA] = i18nc("Video Type: SVGA", "SVGA - 800x600 - 4:3");
505 types[DVGA] = i18nc("Video Type: DVGA", "DVGA - 960x640 - 3:2");
506 types[XVGA] = i18nc("Video Type: XVGA", "XVGA - 1024x576 - 16:9");
507 types[HDTV] = i18nc("Video Type: HDTV", "HDTV - 1280x720 - 16:9");
508 types[WXGA1] = i18nc("Video Type: WXGA1", "WXGA - 1280x768 - 5:3");
509 types[WXGA2] = i18nc("Video Type: WXGA2", "WXGA - 1280x800 - 8:5");
510 types[SXGA] = i18nc("Video Type: SXGA", "SXGA - 1280x1024 - 5:4");
511 types[SXGAPLUS] = i18nc("Video Type: SXGAPLUS", "SXGAPLUS - 1400x1050 - 4:3");
512 types[WSXGA] = i18nc("Video Type: WSXGA", "WSXGA - 1440x900 - 8:5");
513 types[HDPLUS] = i18nc("Video Type: HDPLUS", "HDPLUS - 1600x900 - 16:9");
514 types[WSXGAPLUS] = i18nc("Video Type: WSXGAPLUS", "WSXGAPLUS - 1680x1050 - 8:5");
515 types[UXGA] = i18nc("Video Type: UXGA", "UXGA - 1600x1200 - 4:3");
516 types[BLUERAY] = i18nc("Video Type: BLUERAY", "BLUERAY - 1920x1080 - 16:9");
517 types[WUXGA] = i18nc("Video Type: WUXGA", "WUXGA - 1920x1200 - 8:5");
518 types[TXGA] = i18nc("Video Type: TXGA", "TXGA - 1920x1440 - 7:5");
519 types[QXGA] = i18nc("Video Type: QXGA", "QXGA - 2048x1536 - 4:3");
520 types[UWFHD] = i18nc("Video Type: UWFHD", "UWFHD - 2560x1080 - 21:9");
521 types[WQHD] = i18nc("Video Type: WQHD", "WQHD - 2560x1440 - 16:9");
522 types[WQXGA] = i18nc("Video Type: WQXGA", "WQXGA - 2560x1600 - 8:5");
523 types[QSXGA] = i18nc("Video Type: QSXGA", "QSXGA - 2560x2048 - 5:4");
524 types[QSXGAPLUS] = i18nc("Video Type: QSXGAPLUS", "QSXGAPLUS - 2800x2100 - 4:3");
525 types[WQXGAPLUS] = i18nc("Video Type: WQXGAPLUS", "WQXGAPLUS - 3200x1800 - 16:9");
526 types[WQSXGA] = i18nc("Video Type: WQSXGA", "WQSXGA - 3200x2048 - 25:16");
527 types[QUXGA] = i18nc("Video Type: QUXGA", "QUXGA - 3200x2400 - 4:3");
528 types[UHD4K] = i18nc("Video Type: UHD4K", "UHD4K - 3840x2160 - 16:9");
529 types[WQUXGA] = i18nc("Video Type: WQUXGA", "WQUXGA - 3840x2400 - 8:5");
530 types[HXGA] = i18nc("Video Type: HXGA", "HXGA - 4096x3072 - 4:3");
531 types[UHD5K] = i18nc("Video Type: UHD5K", "UHD5K - 5120x2880 - 16:9");
532 types[WHXGA] = i18nc("Video Type: WHXGA", "WHXGA - 5120x3200 - 8:5");
533 types[HSXGA] = i18nc("Video Type: HSXGA", "HSXGA - 5120x4096 - 5:4");
534 types[UHD6K] = i18nc("Video Type: UHD6K", "UHD6K - 6016x3384 - 16:9");
535 types[WHSXGA] = i18nc("Video Type: WHSXGA", "WHSXGA - 6400x4096 - 25:16");
536 types[HUXGA] = i18nc("Video Type: HUXGA", "HUXGA - 6400x4800 - 4:3");
537 types[UHD8K] = i18nc("Video Type: UHD8K", "UHD8K - 7680x4320 - 16:9");
538 types[WHUXGA] = i18nc("Video Type: WHUXGA", "WHUXGA - 7680x4800 - 8:5");
539 types[UW10K] = i18nc("Video Type: UW10K", "UW10K - 10240x4320 - 21:9");
540 types[UW16K] = i18nc("Video Type: UW16K", "UW16K - 15360x8640 - 16:9");
541
542 return types;
543 }
544
videoBitRate() const545 int VidSlideSettings::videoBitRate() const
546 {
547 int b;
548
549 switch (vbitRate)
550 {
551 case VBR04:
552 {
553 b = 400000;
554 break;
555 }
556
557 case VBR05:
558 {
559 b = 500000;
560 break;
561 }
562
563 case VBR10:
564 {
565 b = 1000000;
566 break;
567 }
568
569 case VBR15:
570 {
571 b = 1500000;
572 break;
573 }
574
575 case VBR20:
576 {
577 b = 2000000;
578 break;
579 }
580
581 case VBR25:
582 {
583 b = 2500000;
584 break;
585 }
586
587 case VBR30:
588 {
589 b = 3000000;
590 break;
591 }
592
593 case VBR40:
594 {
595 b = 4000000;
596 break;
597 }
598
599 case VBR45:
600 {
601 b = 4500000;
602 break;
603 }
604
605 case VBR50:
606 {
607 b = 5000000;
608 break;
609 }
610
611 case VBR60:
612 {
613 b = 6000000;
614 break;
615 }
616
617 case VBR80:
618 {
619 b = 8000000;
620 break;
621 }
622
623 default: // VBR12
624 {
625 b = 1200000;
626 break;
627 }
628 }
629
630 return b;
631 }
632
videoFrameRate() const633 qreal VidSlideSettings::videoFrameRate() const
634 {
635 qreal fr;
636
637 switch (vStandard)
638 {
639 case NTSC:
640 {
641 fr = 29.97;
642 break;
643 }
644
645 default: // PAL
646 {
647 fr = 25.0;
648 break;
649 }
650 }
651
652 return fr;
653 }
654
videoCodec() const655 QString VidSlideSettings::videoCodec() const
656 {
657 QString cod;
658
659 switch (vCodec)
660 {
661 case MJPEG:
662 {
663 cod = QLatin1String("mjpeg");
664 break;
665 }
666
667 case MPEG2:
668 {
669 cod = QLatin1String("mpeg2video");
670 break;
671 }
672
673 case MPEG4:
674 {
675 cod = QLatin1String("mpeg4");
676 break;
677 }
678
679 case WEBMVP8:
680 {
681 cod = QLatin1String("libvpx");
682 break;
683 }
684
685 case FLASH:
686 {
687 cod = QLatin1String("flv");
688 break;
689 }
690
691 case THEORA:
692 {
693 cod = QLatin1String("libtheora");
694 break;
695 }
696
697 case WMV7:
698 {
699 cod = QLatin1String("wm1");
700 break;
701 }
702
703 case WMV8:
704 {
705 cod = QLatin1String("wm2");
706 break;
707 }
708
709 case WMV9:
710 {
711 cod = QLatin1String("wm3");
712 break;
713 }
714
715 default: // X264
716 {
717 cod = QLatin1String("libx264");
718 break;
719 }
720 }
721
722 return cod;
723 }
724
videoFormat() const725 QString VidSlideSettings::videoFormat() const
726 {
727 QString frm;
728
729 switch (vFormat)
730 {
731 case AVI:
732 {
733 frm = QLatin1String("avi");
734 break;
735 }
736
737 case MKV:
738 {
739 frm = QLatin1String("mkv");
740 break;
741 }
742
743 case MPG:
744 {
745 frm = QLatin1String("mpg");
746 break;
747 }
748
749 default: // MP4
750 {
751 frm = QLatin1String("mp4");
752 break;
753 }
754 }
755
756 return frm;
757 }
758
videoBitRateNames()759 QMap<VidSlideSettings::VidBitRate, QString> VidSlideSettings::videoBitRateNames()
760 {
761 QMap<VidBitRate, QString> br;
762
763 br[VBR04] = i18nc("Video Bit Rate 400000", "400k");
764 br[VBR05] = i18nc("Video Bit Rate 500000", "500k");
765 br[VBR10] = i18nc("Video Bit Rate 1000000", "1000k");
766 br[VBR12] = i18nc("Video Bit Rate 1200000", "1200k");
767 br[VBR15] = i18nc("Video Bit Rate 1500000", "1500k");
768 br[VBR20] = i18nc("Video Bit Rate 2000000", "2000k");
769 br[VBR25] = i18nc("Video Bit Rate 2500000", "2500k");
770 br[VBR30] = i18nc("Video Bit Rate 3000000", "3000k");
771 br[VBR40] = i18nc("Video Bit Rate 4000000", "4000k");
772 br[VBR45] = i18nc("Video Bit Rate 4500000", "4500k");
773 br[VBR50] = i18nc("Video Bit Rate 5000000", "5000k");
774 br[VBR60] = i18nc("Video Bit Rate 6000000", "6000k");
775 br[VBR80] = i18nc("Video Bit Rate 8000000", "8000k");
776
777 return br;
778 }
779
videoStdNames()780 QMap<VidSlideSettings::VidStd, QString> VidSlideSettings::videoStdNames()
781 {
782 QMap<VidStd, QString> std;
783
784 std[PAL] = i18nc("Video Standard PAL", "PAL - 25 FPS");
785 std[NTSC] = i18nc("Video Standard NTSC", "NTSC - 29.97 FPS");
786
787 return std;
788 }
789
videoCodecNames()790 QMap<VidSlideSettings::VidCodec, QString> VidSlideSettings::videoCodecNames()
791 {
792 QMap<VidCodec, QString> codecs;
793
794 // NOTE: Some video codecs are currently disabled due to QtAV incompatibility
795 // with bits rate, frames rate, or video sizes. This need some investiguations.
796
797 codecs[X264] = i18nc("Video Codec X264", "High Quality H.264 AVC/MPEG-4 AVC");
798 codecs[MPEG4] = i18nc("Video Codec MPEG4", "DivX/XVid/MPEG-4");
799 codecs[MPEG2] = i18nc("Video Codec MPEG2", "MPEG-2 Video");
800 /*
801 codecs[MJPEG] = i18nc("Video Codec MJPEG", "Motion JPEG");
802 codecs[WEBMVP8] = i18nc("Video Codec WEBMVP8", "WebM-VP8");
803 codecs[THEORA] = i18nc("Video Codec THEORA", "Theora-VP3");
804 codecs[FLASH] = i18nc("Video Codec FLASH", "Flash Video/Sorenson H.263");
805 codecs[WMV7] = i18nc("Video Codec WMV7", "Window Media Video 7");
806 codecs[WMV8] = i18nc("Video Codec WMV8", "Window Media Video 8");
807 codecs[WMV9] = i18nc("Video Codec WMV9", "Window Media Video 9");
808 */
809 return codecs;
810 }
811
videoFormatNames()812 QMap<VidSlideSettings::VidFormat, QString> VidSlideSettings::videoFormatNames()
813 {
814 QMap<VidFormat, QString> frm;
815
816 frm[AVI] = i18nc("Video Standard AVI", "AVI - Audio Video Interleave");
817 frm[MKV] = i18nc("Video Standard MKV", "MKV - Matroska");
818 frm[MP4] = i18nc("Video Standard MP4", "MP4 - MPEG-4");
819 frm[MPG] = i18nc("Video Standard MPG", "MPG - MPEG-2");
820
821 return frm;
822 }
823
videoPlayerNames()824 QMap<VidSlideSettings::VidPlayer, QString> VidSlideSettings::videoPlayerNames()
825 {
826 QMap<VidPlayer, QString> pla;
827
828 pla[NOPLAYER] = i18nc("Video Effect NOPLAYER", "None");
829 pla[INTERNAL] = i18nc("Video Standard INTERNAL", "Internal");
830 pla[DESKTOP] = i18nc("Video Standard DESKTOP", "Default from Desktop");
831
832 return pla;
833 }
834
835 } // namespace Digikam
836