-
Notifications
You must be signed in to change notification settings - Fork 34
/
Copy pathMediaEditor.cpp
12963 lines (12381 loc) · 679 KB
/
MediaEditor.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
Copyright (c) 2023-2024 CodeWin
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include <application.h>
#include <imgui.h>
#include <imgui_helper.h>
#include <imgui_extra_widget.h>
#include <imgui_json.h>
#include <implot.h>
#include <ImGuiFileDialog.h>
#include <portable-file-dialogs.h>
#include <ImGuiTabWindow.h>
#include <ImMaskCreator.h>
#if IMGUI_VULKAN_SHADER
#include <Histogram_vulkan.h>
#include <Waveform_vulkan.h>
#include <CIE_vulkan.h>
#include <Vector_vulkan.h>
#endif
#include <FileSystemUtils.h>
#include <ThreadUtils.h>
#include <MatUtilsImVecHelper.h>
#include "MecProject.h"
#include "MediaTimeline.h"
#include "EventStackFilter.h"
#include "MediaEncoder.h"
#include "HwaccelManager.h"
#include "TextureManager.h"
#include "FFUtils.h"
#include "MatUtils.h"
#include "FontManager.h"
#include "Logger.h"
#include "DebugHelper.h"
#include <sstream>
#include <iomanip>
#include <getopt.h>
#if !IMGUI_APPLICATION_PLATFORM_SDL2
#include <SDL.h>
#endif
//#define DEBUG_IMGUI
#define DEFAULT_MAIN_VIEW_WIDTH 1680
#define DEFAULT_MAIN_VIEW_HEIGHT 1024
#ifdef __APPLE__
#define DEFAULT_FONT_NAME ""
#elif defined(_WIN32)
#define DEFAULT_FONT_NAME ""
#elif defined(__linux__)
#define DEFAULT_FONT_NAME ""
#else
#define DEFAULT_FONT_NAME ""
#endif
using namespace MediaTimeline;
static const std::map<float, float> audio_bar_seg = {
{66.f, 0.4f},
{86.f, 0.2f},
{96.f, 0.f}
};
typedef struct _output_format
{
std::string name;
std::string suffix;
} output_format;
static const output_format OutFormats[] =
{
{"QuickTime", "mov"},
{"MP4 (MPEG-4 Part 14)", "mp4"},
{"Matroska", "mkv"},
{"Material eXchange Format", "mxf"},
{"MPEG-2 Transport Stream", "ts"},
{"WebM", "webm"},
//{"PNG", "png"},
//{"TIFF", "tiff"}
};
typedef struct _output_codec
{
std::string name;
std::string codec;
} output_codec;
static const output_codec OutputVideoCodec[] =
{
{"H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10", "h264"},
{"H.265 / HEVC", "hevc"},
{"Apple ProRes", "prores"},
{"VP9", "vp9"},
{"DPX (Digital Picture Exchange) image", "dpx"},
{"OpenEXR image", "exr"},
{"VC3/DNxHD", "dnxhd"},
{"Uncompressed", ""},
};
static const output_codec OutputVideoCodecUncompressed[] =
{
{"RGB 10-bit", "r210"},
{"YUV packed 4:2:0", "yuv4"},
{"YUV Packed 4:4:4", "v308"},
{"YUV packed QT 4:4:4:4", "v408"},
{"YUV 4:2:2 10-bit", "v210"},
{"YUV 4:4:4 10-bit", "v410"},
{"YUV 4:1:1 12-bit", "y41p"},
{"Packed MS 4:4:4:4", "ayuv"},
};
static const output_codec OutputAudioCodec[] =
{
{"Advanced Audio Coding AAC", "aac"},
{"ATSC A/52A AC-3", "ac3"},
{"ATSC A/52 E-AC-3", "eac3"},
{"MPEG audio layer 3", "mp3"},
{"MPEG audio layer 2", "mp2"},
{"Apple Lossless Audio Codec", "alac"},
{"PCM", ""}
};
static const output_codec OutputAudioCodecPCM[] =
{
{"PCM signed 16-bit little-endian", "pcm_s16le"},
{"PCM signed 16-bit big-endian", "pcm_s16be"},
{"PCM signed 24-bit little-endian", "pcm_s24le"},
{"PCM signed 24-bit big-endian", "pcm_s24be"},
{"PCM signed 32-bit little-endian", "pcm_s32le"},
{"PCM signed 32-bit big-endian", "pcm_s32be"},
{"PCM 32-bit floating point little-endian", "pcm_f32le"},
{"PCM 32-bit floating point big-endian", "pcm_f32be"},
};
typedef struct _output_color
{
std::string name;
std::string desc;
int tag;
} output_color;
static const output_color ColorSpace[] =
{
{"sRGB", "RGB / IEC 61966-2-1 / YZX / ST 428-1", AVCOL_SPC_RGB},
{"BT 709", "ITU-R BT1361 / xvYCC709", AVCOL_SPC_BT709},
//{"None", "", AVCOL_SPC_UNSPECIFIED},
//{"Reserved", "", AVCOL_SPC_RESERVED},
{"FCC", "Federal Regulations 73.682", AVCOL_SPC_FCC},
{"BT 470 BG", "BT601-6 625 / BT1358 625 / BT1700 625 PAL & SECAM / xvYCC601", AVCOL_SPC_BT470BG},
{"SMPTE 170M", "BT601-6 525 / BT1358 525 / BT1700 NTSC", AVCOL_SPC_SMPTE170M},
{"SMPTE 240M", "SMPTE170M and D65 white point", AVCOL_SPC_SMPTE240M},
{"YCGCO", "Dirac / VC-2 and H.264 FRext / ITU-T SG16", AVCOL_SPC_YCGCO},
{"BT 2020 NCL", "ITU-R BT2020 non-constant luminance", AVCOL_SPC_BT2020_NCL},
{"BT 2020 CL", "ITU-R BT2020 constant luminance", AVCOL_SPC_BT2020_CL},
{"SMPTE 2085", "SMPTE 2085, Y'D'zD'x", AVCOL_SPC_SMPTE2085},
{"Chroma derived NCL", "Chromaticity-derived non-constant luminance", AVCOL_SPC_CHROMA_DERIVED_NCL},
{"Chroma derived CL", "Chromaticity-derived constant luminance", AVCOL_SPC_CHROMA_DERIVED_CL},
{"ICTCP", "ITU-R BT.2100-0, ICtCp", AVCOL_SPC_ICTCP},
};
static const output_color ColorTransfer[] =
{
//{"Reserved0", "", AVCOL_TRC_RESERVED0},
{"BT 709", "ITU-R BT709 / BT1361", AVCOL_TRC_BT709},
//{"None", "", AVCOL_TRC_UNSPECIFIED},
//{"Reserved1", "", AVCOL_TRC_RESERVED},
{"Gamma 22", "ITU-R BT470M / ITU-R BT1700 625 PAL & SECAM", AVCOL_TRC_GAMMA22},
{"Gamma 28", "ITU-R BT470BG", AVCOL_TRC_GAMMA28},
{"SMPTE 170M", "ITU-R BT601-6 525 or 625/BT1358 525 or 625/BT1700 NTSC", AVCOL_TRC_SMPTE170M},
{"SMPTE 240M", "SMPTE170M and D65 white point", AVCOL_TRC_SMPTE240M},
{"Linear", "Linear transfer characteristics", AVCOL_TRC_LINEAR},
{"Log", "Logarithmic transfer characteristic (100:1)", AVCOL_TRC_LOG},
{"Log sqrt", "Logarithmic transfer characteristic (316 : 1)", AVCOL_TRC_LOG_SQRT},
{"IEC 61966", "IEC 61966-2-4", AVCOL_TRC_IEC61966_2_4},
{"BT1361 ECG", "ITU-R BT1361 Extended Colour Gamut", AVCOL_TRC_BT1361_ECG},
{"IEC 61966-2-1", "IEC 61966-2-1 sRGB or sYCC", AVCOL_TRC_IEC61966_2_1},
{"BT 2020 10", "ITU-R BT2020 10-bit system", AVCOL_TRC_BT2020_10},
{"BT 2020 12", "ITU-R BT2020 12-bit system", AVCOL_TRC_BT2020_12},
{"SMPTE 2084", "SMPTE ST 2084 10/12/14/16 bit systems", AVCOL_TRC_SMPTE2084},
{"SMPTE 428", "SMPTE ST 428-1", AVCOL_TRC_SMPTE428},
{"ARIB STD B67", "ARIB STD-B67/Hybrid log-gamma", AVCOL_TRC_ARIB_STD_B67},
};
static const char* x264_profile[] = { "baseline", "main", "high", "high10", "high422", "high444" };
static const char* x264_preset[] = { "ultrafast", "superfast", "veryfast", "faster", "fast", "medium", "slow", "slower", "veryslow", "placebo" };
static const char* x264_tune[] = { "film", "animation", "grain", "stillimage", "psnr", "ssim", "fastdecode", "zerolatency" };
static const char* x265_profile[] = { "main", "main10", "mainstillpicture" };
static const char* x265_preset[] = { "ultrafast", "superfast", "veryfast", "faster", "fast", "medium", "slow", "slower", "veryslow", "placebo" };
static const char* x265_tune[] = { "psnr", "ssim", "grain", "zerolatency", "fastdecode" };
static const char* v264_profile[] = { "auto", "baseline", "main", "high", "extended" };
static const char* v265_profile[] = { "auto", "main", "main10" };
static const char* resolution_items[] = { "Custom", "720x480 NTSC", "720x576 PAL", "1280x720 HD", "1920x1080 HD", "3840x2160 UHD", "7680x3420 8K UHD"};
static const char* pixel_aspect_items[] = { "Custom", "Square", "16:9", "4:3", "Cinemascope", "Academy Standard", "Academy Flat" }; // Cinemascope=2.35:1 Academy Standard=1.37:1 Academy Flat=1.85:1
static const char* frame_rate_items[] = { "Custom", "23.976", "24", "25", "29.97", "30", "50", "59.94", "60", "100", "120" };
static const char* audio_sample_rate_items[] = { "8k", "16k", "32k", "44.1k", "48k", "96k" };
static const char* audio_channels_items[] = { "Mono", "Stereo", "Surround Stereo 5.1", "Surround Stereo 7.1", "Surround Stereo 10.1", "Surround Stereo 12.1"};
static const char* audio_format_items[] = { "16bit Short", "32bit Float", "64bit Double" };
static const char* color_system_items[] = { "NTSC", "EBU", "SMPTE", "SMPTE 240M", "APPLE", "wRGB", "CIE1931", "Rec709", "Rec2020", "DCIP3" };
static const char* cie_system_items[] = { "XYY", "UCS", "LUV" };
static const char* audio_vector_mode_items[] = { "Lissajous", "Lissajous XY", "Polar"};
static const char * font_bold_list[] = {
"Regular",
"Light",
"Bold"
};
static const char * font_italic_list[] = {
"None",
"Italic",
//"Oblique"
};
static const std::vector<std::string> ConfigureTabNames = {
"System",
"Timeline",
"Text"
};
static const std::vector<std::string> ControlPanelTabNames = {
ICON_MEDIA_BANK " Media",
ICON_MEDIA_FILTERS " Filters",
ICON_MEDIA_TRANS " Transitions",
ICON_MEDIA_OUTPUT " Output"
};
static const std::vector<std::string> ControlPanelTabTooltips =
{
"Media Bank",
"Filter Bank",
"Transition Bank",
"Media Output"
};
static const std::vector<std::string> MediaBankTabNames = {
ICON_MD_AUTO_AWESOME_MOTION " Bank",
ICON_MD_FOLDER_OPEN " Browser"
};
static const std::vector<std::string> MediaBankTabTooltips = {
"Bank",
"File Browser"
};
static const std::vector<std::string> MainWindowTabNames = {
ICON_MEDIA_PREVIEW " Preview",
ICON_AUDIO_MIXING " Mixing",
#ifdef ENABLE_BACKGROUND_TASK
ICON_NODE " Tasks",
#endif
};
static const std::vector<std::string> MainWindowTabTooltips =
{
"Media Preview",
"Audio Mixing",
"Background Tasks",
};
enum MainPage : int
{
MAIN_PAGE_PREVIEW = 0,
MAIN_PAGE_MIXING,
MAIN_PAGE_BGTASK,
MAIN_PAGE_CLIP_EDITOR,
};
#define SCOPE_VIDEO_HISTOGRAM (1<<0)
#define SCOPE_VIDEO_WAVEFORM (1<<1)
#define SCOPE_VIDEO_CIE (1<<2)
#define SCOPE_VIDEO_VECTOR (1<<3)
#define SCOPE_AUDIO_WAVE (1<<4)
#define SCOPE_AUDIO_VECTOR (1<<5)
#define SCOPE_AUDIO_FFT (1<<6)
#define SCOPE_AUDIO_DB (1<<7)
#define SCOPE_AUDIO_DB_LEVEL (1<<8)
#define SCOPE_AUDIO_SPECTROGRAM (1<<9)
static const char* ScopeWindowTabIcon[] = {
ICON_HISTOGRAM,
ICON_WAVEFORM,
ICON_CIE,
ICON_VECTOR,
ICON_WAVE,
ICON_AUDIOVECTOR,
ICON_FFT,
ICON_DB,
ICON_DB_LEVEL,
ICON_SPECTROGRAM,
};
static const char* ScopeWindowTabNames[] = {
ICON_HISTOGRAM " Video Histogram",
ICON_WAVEFORM " Video Waveform",
ICON_CIE " Video CIE",
ICON_VECTOR " Video Vector",
ICON_WAVE " Audio Wave",
ICON_AUDIOVECTOR " Audio Vector",
ICON_FFT " Audio FFT",
ICON_DB " Audio dB",
ICON_DB_LEVEL " Audio dB Level",
ICON_SPECTROGRAM " Audio Spectrogram"
};
static const std::vector<std::string> TextEditorTabNames = {
"Clip Style",
"Track Style",
};
static const char* VideoAttributeScaleType[] = {
"Fit",
"Crop",
"Fill",
"Stretch",
};
static const char* VideoPreviewScale[] = {
"1:1",
"1/2",
"1/4",
"1/8",
};
static const char* VideoPrecision[] = {
"General(8bit)",
"High Precision(float 32bit)",
};
// Add by Jimmy, Start
typedef struct _method_property
{
std::string name;
std::string icon;
uint32_t meaning;
} method_property;
static const method_property SortMethodItems[] = {
{"Import Date", ICON_SORT_ID, 0},
{"Media Type", ICON_SORT_TYPE, 0},
{"Media Name", ICON_SORT_NAME, 0}
};
static const method_property FilterMethodItems[] = {
{"All", ICON_FILTER_NONE, 0},
{"Video", ICON_MEDIA_VIDEO, MEDIA_VIDEO},
{"Audio", ICON_MEDIA_AUDIO, MEDIA_AUDIO},
{"Image", ICON_MEDIA_IMAGE, MEDIA_SUBTYPE_VIDEO_IMAGE},
{"Text", ICON_MEDIA_TEXT, MEDIA_TEXT}
};
// Add by Jimmy, End
const std::string ffilters = "All Support Files (" + video_file_dis + " " + audio_file_dis + " " + image_file_dis + " " + text_file_dis + ")" + "{" +
video_file_suffix + "," + audio_file_suffix + "," + image_file_suffix + "," + text_file_suffix + "}" + "," +
video_filter + "," +
audio_filter + "," +
image_filter + "," +
text_filter + "," +
".*";
const std::string abbr_ffilters = "All Support Files{" + video_file_suffix + "," + audio_file_suffix + "," + image_file_suffix + "}";
const std::string pfilters = "Project files (*.mep){.mep},.*";
const std::string FILE_DLG_USERDATAS__PROJECT_SAVE = "ProjectSave";
const std::string FILE_DLG_USERDATAS__PROJECT_SAVE_THEN_NEW = "ProjectSaveThenNew";
const std::string FILE_DLG_USERDATAS__PROJECT_SAVE_THEN_QUIT = "ProjectSaveThenQuit";
struct ImageSequenceSetting
{
bool bPng {true};
bool bJpg {true};
bool bBmp {true};
bool bTif {true};
bool bTga {false};
bool bWebP {false};
// more...
MediaCore::Ratio frame_rate {25000, 1000};
};
struct MediaEditorSettings
{
std::string UILanguage {"Default"}; // UI Language
float TopViewHeight {0.6}; // Top view height percentage
float BottomViewHeight {0.4}; // Bottom view height percentage
float ControlPanelWidth {0.3}; // Control panel view width percentage
float MainViewWidth {0.7}; // Main view width percentage
bool BottomViewExpanded {true}; // Timeline view expanded
bool VideoFilterCurveExpanded {true}; // Video filter curve view expanded
bool VideoTransitionCurveExpanded {true}; // Video Transition curve view expanded
bool AudioFilterCurveExpanded {true}; // Audio filter curve view expanded
bool AudioTransitionCurveExpanded {true}; // audio Transition curve view expanded
bool TextCurveExpanded {true}; // Text curve view expanded
float OldBottomViewHeight {0.4}; // Old Bottom view height, recorde at non-expanded
bool showMeters {true}; // show fps/GPU usage at top right of windows
bool powerSaving {false}; // power saving mode of imgui in low refresh rate
int MediaBankViewType {0}; // Media bank view type, 0 = Media bank, 1 = embedded browser
bool HardwareCodec {true}; // try HW codec
bool isCustomVideoFrameSize {false}; // current frame size is custom
int VideoWidth {1920}; // timeline Media Width
int VideoHeight {1080}; // timeline Media Height
float PreviewScale {0.5}; // timeline Media Video Preview scale
bool isCustomVideoFrameRate {false}; // current frame rate is custom
MediaCore::Ratio VideoFrameRate {25000, 1000};// timeline frame rate
bool isCustomPixelAspectRatio {false}; // current pixel aspect ratio is custom
MediaCore::Ratio PixelAspectRatio {1, 1}; // timeline pixel aspect ratio
int ColorSpaceIndex {1}; // timeline color space default is bt 709
int ColorTransferIndex {0}; // timeline color transfer default is bt 709
int VideoFrameCacheSize {10}; // timeline video cache size
int VideoPrecision {0}; // timelime video precision, 0 = low(8bit) 1 = high(float 32bit)
int AudioChannels {2}; // timeline audio channels
int AudioSampleRate {44100}; // timeline audio sample rate
int AudioFormat {2}; // timeline audio format 0=unknown 1=s16 2=f32
std::string project_path; // Editor Recently project file path
int BankViewStyle {1}; // Bank view style type, 0 = icons, 1 = tree vide, and ...
bool ShowHelpTooltips {false}; // Show UI help tool tips
// clip filter editor layout
float video_clip_timeline_height {0.5}; // video clip filter view timelime height
float video_clip_timeline_width {0.5}; // video clip filter view timeline width
float video_clip_attribute_height {0.5}; // video clip filter view attribute height, attribute mode only
// clip filter editor layout
float audio_clip_timeline_height {0.5}; // audio clip filter view timelime height
float audio_clip_timeline_width {0.5}; // audio clip filter view timeline width
bool ExpandScope {true};
bool SeparateScope {false};
// Histogram Scope tools
bool HistogramLog {false};
bool HistogramSplited {true};
bool HistogramYRGB {true};
float HistogramScale {0.05};
// Waveform Scope tools
bool WaveformMirror {true};
bool WaveformSeparate {false};
bool WaveformShowY {false};
float WaveformIntensity {10.0};
#if IMGUI_VULKAN_SHADER
// CIE Scope tools
int CIEColorSystem {ImGui::Rec709system};
int CIEMode {ImGui::XYY};
int CIEGamuts {ImGui::Rec2020system};
#else
int CIEColorSystem {0};
int CIEMode {0};
int CIEGamuts {0};
#endif
float CIEContrast {0.75};
float CIEIntensity {0.5};
bool CIECorrectGamma {false};
bool CIEShowColor {true};
// Vector Scope tools
float VectorIntensity {0.5};
// Audio Wave Scale setting
float AudioWaveScale {1.0};
// Audio Vector Setting
float AudioVectorScale {1.0};
int AudioVectorMode {LISSAJOUS};
// Audio FFT Scale setting
float AudioFFTScale {1.0};
// Audio dB Scale setting
float AudioDBScale {1.0};
// Audio dB Level setting
int AudioDBLevelShort {1};
// Audio Spectrogram setting
float AudioSpectrogramOffset {0.0};
float AudioSpectrogramLight {1.0};
// Scope view
int ScopeWindowIndex {0}; // default video histogram
int ScopeWindowExpandIndex {4}; // default audio waveform
// Image sequence
ImageSequenceSetting image_sequence;
// Text configure
std::string FontName {DEFAULT_FONT_NAME};
bool FontScaleLink {true};
float FontScaleX {1.0f};
float FontScaleY {1.0f};
float FontSpacing {1.0f};
float FontAngle {0.0f};
float FontOutlineWidth {1.0f};
int FontAlignment {2};
int FontItalic {0};
int FontBold {0};
bool FontUnderLine {false};
bool FontStrikeOut {false};
float FontPosOffsetX {0};
float FontPosOffsetY {0};
int FontBorderType {1};
float FontShadowDepth {0.0f};
ImVec4 FontPrimaryColor {1, 1, 1, 1};
ImVec4 FontOutlineColor {0, 0, 0, 1};
ImVec4 FontBackColor {0, 0, 0, 1};
// Output configure
int OutputFormatIndex {0};
// Output video configure
int OutputVideoCodecIndex {0};
int OutputVideoCodecTypeIndex {0};
int OutputVideoCodecProfileIndex {-1};
int OutputVideoCodecPresetIndex {-1};
int OutputVideoCodecTuneIndex {-1};
int OutputVideoCodecCompressionIndex {-1}; // image format compression
bool OutputVideoSettingAsTimeline {true};
int OutputVideoResolutionIndex {-1};
int OutputVideoResolutionWidth {-1}; // custom setting
int OutputVideoResolutionHeight {-1}; // custom setting
int OutputVideoPixelAspectRatioIndex {-1};
MediaCore::Ratio OutputVideoPixelAspectRatio {1, 1};// custom setting
int OutputVideoFrameRateIndex {-1};
MediaCore::Ratio OutputVideoFrameRate {25000, 1000};// custom setting
int OutputColorSpaceIndex {-1};
int OutputColorTransferIndex {-1};
int OutputVideoBitrateStrategyindex {0}; // 0=cbr 1:vbr default cbr
int OutputVideoBitrate {-1};
int OutputVideoGOPSize {-1};
int OutputVideoBFrames {0};
// Output audio configure
int OutputAudioCodecIndex {0};
int OutputAudioCodecTypeIndex {0};
bool OutputAudioSettingAsTimeline {true};
int OutputAudioSampleRateIndex {3}; // 44100
int OutputAudioSampleRate {44100}; // custom setting
int OutputAudioChannelsIndex {1};
int OutputAudioChannels {2}; // custom setting
MediaEditorSettings() {}
void SyncSettingsFromTimeline(TimeLine* tl)
{
auto& hMediaSettings = tl->mhMediaSettings;
VideoWidth = hMediaSettings->VideoOutWidth();
VideoHeight = hMediaSettings->VideoOutHeight();
VideoFrameRate = hMediaSettings->VideoOutFrameRate();
PreviewScale = tl->mPreviewScale;
AudioChannels = hMediaSettings->AudioOutChannels();
AudioSampleRate = hMediaSettings->AudioOutSampleRate();
auto renderPcmFormat = MatUtils::ImDataType2PcmFormat(hMediaSettings->AudioOutDataType());
if (renderPcmFormat == MediaCore::AudioRender::PcmFormat::UNKNOWN)
throw std::runtime_error("Audio output data type is NOT SUPPORTED as render pcm format!");
AudioFormat = (int)renderPcmFormat;
}
};
static MEC::Project::Holder g_hProject;
static SysUtils::ThreadPoolExecutor::Holder g_hBgtaskExctor;
static std::string ini_file = "Media_Editor.ini";
static std::string icon_file;
static std::vector<std::string> import_url; // import file url from system drag
static short main_mon = 0;
static TimeLine * timeline = nullptr;
static ImTextureID codewin_texture = nullptr;
static ImTextureID logo_texture = nullptr;
static std::thread * g_loading_project_thread {nullptr};
static std::thread * g_loading_plugin_thread {nullptr};
static std::thread * g_env_scan_thread {nullptr};
static float g_project_loading_percentage {0};
static bool g_plugin_loading {false};
static bool g_plugin_loaded {false};
static bool g_project_loading {false};
static float g_plugin_loading_percentage {0};
static int g_plugin_loading_current_index {0};
static std::string g_plugin_loading_message;
static bool g_env_scanned = false;
static bool g_env_scanning = false;
static ImGui::TabLabelStyle * tab_style = &ImGui::TabLabelStyle::Get();
static MediaEditorSettings g_media_editor_settings;
static MediaEditorSettings g_new_setting;
static bool g_vidEncSelChanged = true;
static std::vector<MediaCore::MediaEncoder::Description> g_currVidEncDescList;
static bool g_audEncSelChanged = true;
static std::vector<MediaCore::MediaEncoder::Description> g_currAudEncDescList;
static std::string g_encoderConfigErrorMessage;
static bool quit_save_confirm = true;
static bool project_need_save = false;
static bool project_changed = false;
static bool mouse_hold = false;
static uint32_t scope_flags = 0xFFFFFFFF;
static bool set_context_in_splash = false;
static ImGuiFileDialog embedded_filedialog; // Media Finder, embedded filedialog
static int ConfigureIndex = 0; // default timeline setting
static int ControlPanelIndex = 0; // default Media Bank window
static int BottomWindowIndex = 0; // default Media Timeline window, no other view so far
static int MainWindowIndex = MAIN_PAGE_PREVIEW; // default Media Preview window
static int LastMainWindowIndex = MAIN_PAGE_PREVIEW;
static int LastEditingWindowIndex = -1;
static int MonitorIndexPreviewVideo = -1;
static int MonitorIndexVideoFilterOrg = -1;
static int MonitorIndexVideoFiltered = -1;
static int MonitorIndexScope = -1;
static bool MonitorIndexChanged = false;
static float ui_breathing = 1.0f;
static float ui_breathing_step = 0.01;
static float ui_breathing_min = 0.5;
static float ui_breathing_max = 1.0;
#if IMGUI_VULKAN_SHADER
static ImGui::Histogram_vulkan * m_histogram {nullptr};
static ImGui::Waveform_vulkan * m_waveform {nullptr};
static ImGui::CIE_vulkan * m_cie {nullptr};
static ImGui::Vector_vulkan * m_vector {nullptr};
#endif
#define MATVIEW_WIDTH 256
#define MATVIEW_HEIGHT 256
static bool need_update_scope {false};
static bool need_update_preview {false};
static ImGui::ImMat mat_histogram;
static ImGui::ImMat histogram_mat;
static ImTextureID histogram_texture {nullptr};
static ImGui::ImMat mat_video_waveform;
static ImTextureID video_waveform_texture {nullptr};
static ImGui::ImMat mat_cie;
static ImTextureID cie_texture {nullptr};
static ImGui::ImMat mat_vector;
static ImTextureID vector_texture {nullptr};
static ImGui::ImMat wave_mat;
static ImTextureID wave_texture {nullptr};
static ImGui::ImMat fft_mat;
static ImTextureID fft_texture {nullptr};
static ImGui::ImMat db_mat;
static ImTextureID db_texture {nullptr};
static std::unordered_map<std::string, std::vector<FM::FontDescriptorHolder>> fontTable;
static std::vector<string> fontFamilies; // system fonts
static std::string g_plugin_path = "";
static std::string g_language_path = "";
static std::string g_resource_path = "";
static void GetVersion(int& major, int& minor, int& patch, int& build)
{
major = MEDIAEDITOR_VERSION_MAJOR;
minor = MEDIAEDITOR_VERSION_MINOR;
patch = MEDIAEDITOR_VERSION_PATCH;
build = MEDIAEDITOR_VERSION_BUILD;
}
// static bool TimelineConfChanged(MediaEditorSettings &old_setting, MediaEditorSettings &new_setting)
// {
// if (old_setting.VideoHeight != new_setting.VideoHeight || old_setting.VideoWidth != new_setting.VideoWidth ||
// old_setting.PreviewScale != new_setting.PreviewScale || old_setting.PixelAspectRatio.den != new_setting.PixelAspectRatio.den ||
// old_setting.PixelAspectRatio.num != new_setting.PixelAspectRatio.num || old_setting.VideoFrameRate.den != new_setting.VideoFrameRate.den ||
// old_setting.VideoFrameRate.num != new_setting.VideoFrameRate.num || old_setting.ColorSpaceIndex != new_setting.ColorSpaceIndex ||
// old_setting.ColorTransferIndex != new_setting.ColorTransferIndex || old_setting.HardwareCodec != new_setting.HardwareCodec ||
// old_setting.AudioSampleRate != new_setting.AudioSampleRate || old_setting.AudioChannels != new_setting.AudioChannels ||old_setting.AudioFormat != new_setting.AudioFormat)
// return true;
// return false;
// }
static void UpdateBreathing()
{
ui_breathing -= ui_breathing_step;
if (ui_breathing <= ui_breathing_min)
{
ui_breathing = ui_breathing_min;
ui_breathing_step = -ui_breathing_step;
}
else if (ui_breathing >= ui_breathing_max)
{
ui_breathing = ui_breathing_max;
ui_breathing_step = -ui_breathing_step;
}
}
static bool UIPageChanged()
{
bool updated = false;
if (LastMainWindowIndex == MAIN_PAGE_PREVIEW && MainWindowIndex != MAIN_PAGE_PREVIEW)
{
// we leave video preview windows, stop preview play
Logger::Log(Logger::DEBUG) << "[Changed page] leaving video preview page!!!" << std::endl;
need_update_scope = true;
if (timeline)
{
timeline->bPreviewing = false;
timeline->Play(false);
}
}
if (LastMainWindowIndex == MAIN_PAGE_CLIP_EDITOR && MainWindowIndex != MAIN_PAGE_CLIP_EDITOR)
{
// we leave editing windows
Logger::Log(Logger::DEBUG) << "[Changed page] leaving editing page!!!" << std::endl;
LastEditingWindowIndex = -1;
timeline->Seek(timeline->mCurrentTime);
timeline->RefreshPreview();
}
if (LastMainWindowIndex == MAIN_PAGE_MIXING && MainWindowIndex != MAIN_PAGE_MIXING)
{
// we leave audio mixing editor windows
Logger::Log(Logger::DEBUG) << "[Changed page] leaving audio mixing editor page!!!" << std::endl;
}
if ((MainWindowIndex == MAIN_PAGE_CLIP_EDITOR && LastMainWindowIndex != MAIN_PAGE_CLIP_EDITOR) ||
(MainWindowIndex == MAIN_PAGE_CLIP_EDITOR && LastMainWindowIndex == MAIN_PAGE_CLIP_EDITOR && LastEditingWindowIndex == -1))
{
// we enter editing windows
Logger::Log(Logger::DEBUG) << "[Changed page] Enter editing page!!!" << std::endl;
LastEditingWindowIndex = timeline->mSelectedItem;
}
else if (MainWindowIndex == MAIN_PAGE_CLIP_EDITOR && LastMainWindowIndex == MAIN_PAGE_CLIP_EDITOR && LastEditingWindowIndex != timeline->mSelectedItem)
{
// we changed editing page
Logger::Log(Logger::DEBUG) << "[Changed page] Change editing page!!!" << std::endl;
LastEditingWindowIndex = timeline->mSelectedItem;
if (timeline->mSelectedItem != -1)
{
auto item = timeline->mEditingItems[timeline->mSelectedItem];
if (item)
{
int64_t seek_time = -1;
if (item->mEditorType == EDITING_CLIP && item->mEditingClip)
{
seek_time = item->mEditingClip->GetPreviewTime();
}
else if (item->mEditorType == EDITING_TRANSITION && item->mEditingOverlap)
{
seek_time = item->mEditingOverlap->mCurrentTime != -1 ? item->mEditingOverlap->mStart + item->mEditingOverlap->mCurrentTime : -1;
}
if (seek_time != -1)
{
timeline->Seek(seek_time);
}
}
}
}
else if (MainWindowIndex == MAIN_PAGE_CLIP_EDITOR && timeline->mSelectedItem == -1)
{
MainWindowIndex = MAIN_PAGE_PREVIEW;
LastEditingWindowIndex = -1;
timeline->Seek(timeline->mCurrentTime);
timeline->RefreshPreview();
}
if (MainWindowIndex == MAIN_PAGE_MIXING && LastMainWindowIndex != MAIN_PAGE_MIXING)
{
// we enter audio mixing editor windows
Logger::Log(Logger::DEBUG) << "[Changed page] Enter audio mixing editor page!!!" << std::endl;
}
LastMainWindowIndex = MainWindowIndex;
return updated;
}
static int EditingClip(int type, void* handle)
{
if (timeline && timeline->mSelectedItem != -1)
{
MainWindowIndex = MAIN_PAGE_CLIP_EDITOR;
}
else
{
MainWindowIndex = MAIN_PAGE_PREVIEW;
}
auto updated = UIPageChanged();
return updated ? 1 : 0;
}
static int EditingOverlap(int type, void* handle)
{
if (timeline && timeline->mSelectedItem != -1)
{
MainWindowIndex = MAIN_PAGE_CLIP_EDITOR;
}
else
{
MainWindowIndex = MAIN_PAGE_PREVIEW;
}
auto updated = UIPageChanged();
return updated ? 1 : 0;
}
// Utils functions
static bool ExpandButton(ImDrawList *draw_list, ImVec2 pos, bool expand = true, bool icon_mirror = false)
{
ImGuiIO &io = ImGui::GetIO();
ImRect delRect(pos, ImVec2(pos.x + 16, pos.y + 16));
bool overDel = delRect.Contains(io.MousePos);
ImU32 delColor = IM_COL32_WHITE;
// a ----- c
// | \ / |
// | e |
// | / \ |
// b ----- d
ImVec2 tra = pos + ImVec2(0, 0);
ImVec2 trb = pos + ImVec2(0, 16);
ImVec2 trc = pos + ImVec2(16, 0);
ImVec2 trd = pos + ImVec2(16, 16);
ImVec2 tre = pos + ImVec2(8, 8);
if (!expand) icon_mirror ? draw_list->AddTriangleFilled(trc, trd, tre, delColor) : draw_list->AddTriangleFilled(tra, trb, tre, delColor);
else draw_list->AddTriangleFilled(tra, tre, trc, delColor);
return overDel;
}
static std::pair<ImVec2, ImVec2> ShowVideoWindow(ImDrawList *draw_list, ImTextureID texture, ImVec2 pos, ImVec2 size, std::string title, float title_size, float& offset_x, float& offset_y, float& tf_x, float& tf_y, bool bLandscape = true, bool out_border = false, const ImVec2& uvMin = ImVec2(0, 0), const ImVec2& uvMax = ImVec2(1, 1))
{
ImVec2 v2RenderPos(0, 0);
ImVec2 v2RenderSize(0, 0);
if (!texture)
return {v2RenderPos, v2RenderSize};
float texture_width = ImGui::ImGetTextureWidth(texture);
float texture_height = ImGui::ImGetTextureHeight(texture);
float aspectRatioTexture = texture_width / texture_height;
float aspectRatioView = size.x / size.y;
bool bTextureisLandscape = aspectRatioTexture > 1.f ? true : false;
bool bViewisLandscape = aspectRatioView > 1.f ? true : false;
float adj_w = 0, adj_h = 0;
if ((bViewisLandscape && bTextureisLandscape) || (!bViewisLandscape && !bTextureisLandscape))
{
if (aspectRatioTexture >= aspectRatioView)
{
adj_w = size.x;
adj_h = adj_w / aspectRatioTexture;
}
else
{
adj_h = size.y;
adj_w = adj_h * aspectRatioTexture;
}
}
else if (bViewisLandscape && !bTextureisLandscape)
{
adj_h = size.y;
adj_w = adj_h * aspectRatioTexture;
}
else if (!bViewisLandscape && bTextureisLandscape)
{
adj_w = size.x;
adj_h = adj_w / aspectRatioTexture;
}
tf_x = (size.x - adj_w) / 2.0;
tf_y = (size.y - adj_h) / 2.0;
offset_x = pos.x + tf_x;
offset_y = pos.y + tf_y;
draw_list->AddRectFilled(ImVec2(offset_x, offset_y), ImVec2(offset_x + adj_w, offset_y + adj_h), IM_COL32_BLACK);
v2RenderPos = ImVec2(offset_x, offset_y);
v2RenderSize = ImVec2(adj_w, adj_h);
draw_list->AddImage(
texture,
v2RenderPos,
v2RenderPos+v2RenderSize,
uvMin,
uvMax
);
tf_x = offset_x + adj_w;
tf_y = offset_y + adj_h;
if (!title.empty() && title_size > 0)
{
draw_list->AddTextComplex(ImVec2(offset_x, offset_y) + ImVec2(20, 10),
title.c_str(), title_size, IM_COL32(224, 224, 224, 128),
0.25f, IM_COL32(128, 128, 128, 255),
ImVec2(title_size * 1.5, title_size * 1.5), IM_COL32(32, 32, 32, 255));
}
if (out_border)
{
draw_list->AddTextComplex(ImVec2(offset_x, offset_y + adj_h - 48) + ImVec2(20, 10),
"Out of range", title_size, IM_COL32(224, 0, 0, 224),
0.25f, IM_COL32(128, 128, 128, 255),
ImVec2(title_size * 1.5, title_size * 1.5), IM_COL32(32, 32, 32, 255));
}
ImGui::SetCursorScreenPos(pos);
ImGui::InvisibleButton(("##video_window" + std::to_string((long long)texture)).c_str(), size);
return {v2RenderPos, v2RenderSize};
}
static void ShowVideoWindow(ImTextureID texture, ImVec2 pos, ImVec2 size, std::string title = std::string(), float title_size = 0.f, bool out_border = false, const ImVec2& uvMin = ImVec2(0, 0), const ImVec2& uvMax = ImVec2(1, 1))
{
float offset_x = 0, offset_y = 0;
float tf_x = 0, tf_y = 0;
ShowVideoWindow(ImGui::GetWindowDrawList(), texture, pos, size, title, title_size, offset_x, offset_y, tf_x, tf_y, true, out_border, uvMin, uvMax);
}
static void CalculateVideoScope(const ImGui::ImMat& mat)
{
#if IMGUI_VULKAN_SHADER
if (m_histogram && (scope_flags & SCOPE_VIDEO_HISTOGRAM | need_update_scope)) m_histogram->scope(mat, mat_histogram, 256, g_media_editor_settings.HistogramScale, g_media_editor_settings.HistogramLog);
if (m_waveform && (scope_flags & SCOPE_VIDEO_WAVEFORM | need_update_scope)) m_waveform->scope(mat, mat_video_waveform, 256, g_media_editor_settings.WaveformIntensity, g_media_editor_settings.WaveformSeparate, g_media_editor_settings.WaveformShowY);
if (m_cie && (scope_flags & SCOPE_VIDEO_CIE | need_update_scope)) m_cie->scope(mat, mat_cie, g_media_editor_settings.CIEIntensity, g_media_editor_settings.CIEShowColor);
if (m_vector && (scope_flags & SCOPE_VIDEO_VECTOR | need_update_scope)) m_vector->scope(mat, mat_vector, g_media_editor_settings.VectorIntensity);
#endif
need_update_scope = false;
}
static bool MonitorButton(const char * label, ImVec2 pos, int& monitor_index, std::vector<int> disabled_index)
{
static std::string monitor_icons[] = {ICON_ONE, ICON_TWO, ICON_THREE, ICON_FOUR, ICON_FIVE, ICON_SIX, ICON_SEVEN, ICON_EIGHT, ICON_NINE};
auto platform_io = ImGui::GetPlatformIO();
ImGuiViewportP* viewport = (ImGuiViewportP*)ImGui::GetWindowViewport();
auto current_monitor = viewport->PlatformMonitor;
int org_index = monitor_index;
ImGui::SetCursorScreenPos(pos);
auto show_monitor_tooltips = [&](int index)
{
ImGuiPlatformMonitor& mon = index >= 0 ? platform_io.Monitors[index] : platform_io.Monitors[current_monitor];
ImGui::SetNextWindowViewport(viewport->ID);
if (ImGui::BeginTooltip())
{
ImGui::BulletText("Monitor #%d:", index + 1);
ImGui::Text("DPI %.0f", mon.DpiScale * 100.0f);
ImGui::Text("MainSize (%.0f,%.0f)", mon.MainSize.x, mon.MainSize.y);
ImGui::Text("WorkSize (%.0f,%.0f)", mon.WorkSize.x, mon.WorkSize.y);
ImGui::Text("MainMin (%.0f,%.0f)", mon.MainPos.x, mon.MainPos.y);
ImGui::Text("MainMax (%.0f,%.0f)", mon.MainPos.x + mon.MainSize.x, mon.MainPos.y + mon.MainSize.y);
ImGui::Text("WorkMin (%.0f,%.0f)", mon.WorkPos.x, mon.WorkPos.y);
ImGui::Text("WorkMax (%.0f,%.0f)", mon.WorkPos.x + mon.WorkSize.x, mon.WorkPos.y + mon.WorkSize.y);
ImGui::EndTooltip();
}
};
ImGui::PushStyleColor(ImGuiCol_FrameBg, 0);
ImGui::PushStyleColor(ImGuiCol_HeaderHovered, ImVec4(0.2, 0.7, 0.2, 1.0));
ImGui::PushStyleColor(ImGuiCol_Header, ImVec4(0.2, 0.5, 0.2, 1.0));
ImGui::PushStyleColor(ImGuiCol_FrameBgHovered, ImVec4(0.2, 0.7, 0.2, 1.0));
ImGui::PushItemWidth(24);
std::string selected_label = monitor_icons[monitor_index < 0 ? current_monitor : monitor_index];
if (ImGui::BeginCombo(label, selected_label.c_str(), ImGuiComboFlags_NoArrowButton))
{
for (int i = 0; i < platform_io.Monitors.Size; i++)
{
bool is_selected = monitor_icons[i] == selected_label;
bool is_disable = false;
for (auto disabled : disabled_index)
{
if (disabled != -1 && disabled == i)
is_disable = true;
}
if (g_media_editor_settings.SeparateScope && current_monitor == i)
is_disable = true;
//if (is_disable) continue;
ImGui::BeginDisabled(is_disable);
if (ImGui::Selectable(monitor_icons[i].c_str(), is_selected))
{
if (i == current_monitor)
monitor_index = -1;
else
monitor_index = i;
MonitorIndexChanged = true;
}
ImGui::EndDisabled();
if (is_selected)
{
ImGui::SetItemDefaultFocus();
}
if (ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenDisabled))
{
show_monitor_tooltips(i);
}
}
ImGui::EndCombo();
}
ImGui::PopItemWidth();
ImGui::PopStyleColor(4);
if (ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenDisabled))
{
show_monitor_tooltips(monitor_index);
}
return monitor_index != org_index;
}
// System view