-
Notifications
You must be signed in to change notification settings - Fork 1
/
bullet-video-V4.9.jsx
1261 lines (1114 loc) · 53.4 KB
/
bullet-video-V4.9.jsx
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
// Change the values of these 3 variables to change the font.
//========================================================
var subsHeadingFont = "Lato-Bold";
var subsHeadingFontSize = 49;
var subsPointFont = "Lato-Regular";
var subsPointFontSize = 38;
var subsSubPointFont = "Lato-Regular";
var subsSubPointFontSize = 33;
//========================================================
// Half-screen extention time. This variable decides how long the half-screen remains on the screen after the subtitles.
//========================================================
var halfScreenExtendTime = 2;
//========================================================
// Logo dimensions. [width, height].
//========================================================
var logoDimens = [372, 100];
//========================================================
// Change this value to change the X-Coordinate of the bullet-point
//========================================================
var overridePointBulltetPointVal = 0;
//========================================================
var proj = app.project;
var settingsFile = new File(Folder.current.absoluteURI + "/Video-Creator-Settings.txt");
var templateProjName = "Video-Creator-Template.aep";
var vidTitle = "";
var vidDescription = "";
var logoArray = [];
var commercialsArray = [];
var infoVidFolder = null; // Folder containing all the Main videos and their respective subtitle AE files
var curInfoVidFile = null;
var curComVidFile = null;
var curLogoFile = null;
var introFile = null;
var outroFile = null;
var spreadsheetFile = null;
var ameWatchFolder = null; // Adobe Media Encoder watch folder
var vidDimens = [1920,1080]; // Internal video dimensions
var finalVidDimens = vidDimens; // Final video dimensions
var videoBGColor = [206/255, 206/255, 206/255];
var introComIndentTime = 0.5; // How much the commerical video needs to be indented into the intro video (measured in seconds)
var comTransIndentTime = 0.5; // How much the transition video needs to be indented into the commercial video (measured in seconds)
var transInfoVidIndentTime = 1.5; // How much the info video needs to be indented into the transition video (measured in seconds)
var infoVidOutroIndentTime = 1; // How much the outro video needs to be indented into the info video (measured in seconds)
var halfScreenPaddingTime = halfScreenExtendTime; // The time in-between the half-screen moving-in and the text start appearing.
var comInfoVidTransComp = null; // Transition comp between commerial and infor video.
var infoVidItem = null; // Imported info video project item
var infoVidLayer = null; // Info video layer in the main comp
var nullMarkerLayer = null; // Subtitle null marker layer
var infoVidCenterX = 960; // x-coord of the center of person in info video
var stopVideoCreation = false; // Stops the video creation process after the current video
// UI Elements
var txtIntro = null; // Intro file path textbox
var txtOutro = null; // Outro file path textbox
var txtInfoVid = null; // Main video folder path textbox
var txtSpreadsheet = null; // Spreadsheet file (should be CSV)
var txtVidWidth = null; // Video width textbox
var txtVidHeight = null; // Video height textbox
var txtWatchFold = null; // Adobe Media Encoder watch folder textbox
var txtColor = null; // Background color hex code
function createUI ()
{
var userPanel = new Window ("dialog", "Video Creator - V4.8", undefined);
var introMainGroup = userPanel.add("group", undefined, "Intro Main Group");
introMainGroup.orientation = "column";
var lblIntro = introMainGroup.add("statictext", undefined, "Intro video:");
lblIntro.alignment = "left";
var introInGroup = introMainGroup.add("group", undefined, "Intro Input Group");
txtIntro = introInGroup.add("edittext", [0,0,150,22], "");
var btnIntro = introInGroup.add("button", undefined, "Browse");
btnIntro.onClick = function(){selectIntroFile ()};
var outroMainGroup = userPanel.add("group", undefined, "Outro Main Group");
outroMainGroup.orientation = "column";
var lblOutro = outroMainGroup.add("statictext", undefined, "Outro video:");
lblOutro.alignment = "left";
var outroInGroup = outroMainGroup.add("group", undefined, "Outro Input Group");
txtOutro = outroInGroup.add("edittext", [0,0,150,22], "");
var btnOutro = outroInGroup.add("button", undefined, "Browse");
btnOutro.onClick = function(){selectOutroFile()};
var infoVidGroup = userPanel.add("group", undefined, "Info Video Group");
infoVidGroup.orientation = "column";
var lblInfoVid = infoVidGroup.add("statictext", undefined, "Main video folder:");
lblInfoVid.alignment = "left";
var infoVidInGroup = infoVidGroup.add("group", undefined, "Info Video Input Group");
txtInfoVid = infoVidInGroup.add("edittext", [0,0,150,22], "");
var btnInfoVid = infoVidInGroup.add("button", undefined, "Browse");
btnInfoVid.onClick = function(){selectInfoVideoFolder()};
var spreadSheetGroup = userPanel.add("group", undefined, "Spread Sheet Group");
spreadSheetGroup.orientation = "column";
var lblSpreadSheet = spreadSheetGroup.add("statictext", undefined, "Spreadsheet (.csv):");
lblSpreadSheet.alignment = "left";
var ssInGroup = spreadSheetGroup.add("group", undefined, "Spreadsheet Input Group");
txtSpreadsheet = ssInGroup.add("edittext", [0,0,150,22], "");
var btnSpreadsheet = ssInGroup.add("button", undefined, "Browse");
btnSpreadsheet.onClick = function(){selectSpreadsheet()};
var watchFoldGroup = userPanel.add("group", undefined, "Watch Folder Group");
watchFoldGroup.orientation = "column";
var lblWatchFold = watchFoldGroup.add("statictext", undefined, "Adobe Media Encoder watch folder:");
lblWatchFold.alignment = "left";
var watchFoldInGroup = watchFoldGroup.add("group", undefined, "Watch Folder Input Group");
txtWatchFold = watchFoldInGroup.add("edittext", [0,0,150,22], "");
var btnWatchFold = watchFoldInGroup.add("button", undefined, "Browse");
btnWatchFold.onClick = function(){selectVidWatchFolder()};
var advancedPanel = userPanel.add("panel", undefined, "Advanced");
var vidDimensGroup = advancedPanel.add("group", undefined, "Video Dimensions Group");
vidDimensGroup.orientation = "column";
vidDimensGroup.alignment = "left";
var lblVidDimens = vidDimensGroup.add("statictext", undefined, "Video Dimensions (WIDTH x HEIGHT):");
lblVidDimens.alignment = "left";
var vidDimensInGroup = vidDimensGroup.add("group", undefined, "Video Dimensions Input Group");
vidDimensInGroup.alignment = "left";
txtVidWidth = vidDimensInGroup.add("edittext", [0,0,50,22], "1920");
var lblMultiply = vidDimensInGroup.add("statictext", undefined, "x");
txtVidHeight = vidDimensInGroup.add("edittext", [0,0,50,22], "1080");
var colorGroup = advancedPanel.add("group", undefined, "Color Group");
colorGroup.orientation = "column";
colorGroup.alignment = "left";
var lblColor = colorGroup.add("statictext", undefined, "Background Color (Hex Code):");
lblColor.alignment = "left";
txtColor = colorGroup.add("edittext", [0,0,50,22], "CECECE");
txtColor.alignment = "left";
var btnStart = userPanel.add("button", [0,0,100,30], "Start");
btnStart.onClick = function(){startUp ()};
var btnStop = userPanel.add("button", [0,0,100,30], "Close");
btnStop.onClick = function(){shutdownScript ()};
return userPanel;
}
// The GUI is created, centered and displayed.
var controlPanelGUI = createUI();
grabFilePaths ();
controlPanelGUI .center();
controlPanelGUI .show();
function grabFilePaths ()
/*
* This function checks whether the settings file is present and if so, opens it and imports
* the previously selected settings.
*/
{
if (settingsFile.exists)
{
var fileOpened = settingsFile.open('r');
if (fileOpened)
{
infoVidFolder = new Folder(settingsFile.readln());
txtInfoVid.text = decodeURI(infoVidFolder.absoluteURI)
introFile = new File(settingsFile.readln());
txtIntro.text = decodeURI(introFile.absoluteURI);
outroFile = new File(settingsFile.readln());
txtOutro.text = decodeURI(outroFile.absoluteURI);
spreadsheetFile = new File(settingsFile.readln());
txtSpreadsheet.text = decodeURI(spreadsheetFile.absoluteURI);
ameWatchFolder = new Folder(settingsFile.readln());
txtWatchFold.text = decodeURI(ameWatchFolder.absoluteURI);
txtVidWidth.text = decodeURI(settingsFile.readln());
txtVidHeight.text = decodeURI(settingsFile.readln());
txtColor.text = decodeURI(settingsFile.readln());
settingsFile.close();
}
}
}
function selectIntroFile ()
/*
* Allows the user to select the Intro video file.
*/
{
var tmpIntro = File.openDialog("Please select the intro video");
if (tmpIntro != null)
{
introFile = tmpIntro;
txtIntro.text = decodeURI(tmpIntro.absoluteURI.toString());
}
}
function selectOutroFile ()
/*
* Allows the user to select the Outro video file.
*/
{
var tmpOutro = File.openDialog("Please select the outro video");
if (tmpOutro != null)
{
outroFile = tmpOutro;
txtOutro.text = decodeURI(tmpOutro.absoluteURI.toString());
}
}
function selectInfoVideoFolder ()
/*
* Allows the user to select the video folder (containing the videos and the respective subtitle projects).
*/
{
var tmpInfoVidFold = Folder.selectDialog("Please select the main video folder");
if (tmpInfoVidFold != null)
{
infoVidFolder = tmpInfoVidFold;
txtInfoVid.text = decodeURI(tmpInfoVidFold.absoluteURI.toString());
}
}
function selectSpreadsheet ()
/*
* Allows the user to select the spreadsheet file.
*/
{
var tmpSpreadsheetFile = File.openDialog("Please select the spreadsheet");
if (tmpSpreadsheetFile != null)
{
spreadsheetFile = tmpSpreadsheetFile;
txtSpreadsheet.text = decodeURI(tmpSpreadsheetFile.absoluteURI.toString());
}
}
function selectVidWatchFolder ()
/*
* Allows the user to select the project output folder (the folder to which the completed projects are saved).
*/
{
var tmpWatchFold = Folder.selectDialog("Please select the Adobe Media Encoder watch folder");
if (tmpWatchFold != null)
{
ameWatchFolder = tmpWatchFold;
txtWatchFold.text = decodeURI(tmpWatchFold.absoluteURI.toString());
}
}
function shutdownScript ()
/*
* Shutsdown the script.
*/
{
stopVideoCreation = true;
controlPanelGUI .close();
}
function startUp ()
/*
* This function checks whether all the neccessary user-inputs are present and if so,
* starts the video creation process.
*/
{
try
{
if (infoVidFolder == null)
alert("Main video folder not selected. Please select the main video folder and try again.");
else if (introFile == null)
alert("Intro video not found. Please select a valid intro video and try again.");
else if (outroFile == null)
alert("Outro video not found. Please select a valid outro video and try again.");
else if (spreadsheetFile == null)
alert("Spreadsheet not found. Please select a valid spreadsheet and try again.");
else if (spreadsheetFile.name.indexOf(".csv") == -1)
alert("Invalid spreadsheet. Spreadsheet should be of type: Comma Seperated Value (.csv)");
else if (ameWatchFolder == null)
alert("Adobe Media Encoder watch folder not selected. Please select the folder and try again.");
else if (txtVidWidth.text == "" || txtVidHeight.text == "")
alert("Please input a valid width and height for the video.");
else if (txtColor.text =="")
alert("Please input a valid hex code.");
else
{
var fileOpened = settingsFile.open("w");
if (fileOpened)
{
settingsFile.writeln(infoVidFolder.absoluteURI);
settingsFile.writeln(introFile.absoluteURI);
settingsFile.writeln(outroFile.absoluteURI);
settingsFile.writeln(spreadsheetFile.absoluteURI);
settingsFile.writeln(ameWatchFolder.absoluteURI);
settingsFile.writeln(txtVidWidth.text);
settingsFile.writeln(txtVidHeight.text);
settingsFile.writeln(txtColor.text);
settingsFile.close();
}
finalVidDimens = [parseInt(trimWhitespaces(txtVidWidth.text)), parseInt(trimWhitespaces(txtVidHeight.text))];
if (txtColor.text != "")
decodeHexCode (trimWhitespaces(txtColor.text));
mainCtrl();
}
}catch(e){
alert(e);
}
}
function mainCtrl()
/*
* This function controls the whole video creation process. It gets all the video files and the respective subtitle projects from the video
* folder. Each video is iterated against each commercial and each logo in the spreadsheet file. The completed AE project file is stored
* in the "watch folder".
*/
{
try
{
stopVideoCreation = false;
decodeSpreadsheet ();
var allFoldVidFiles = infoVidFolder.getFiles(/\.(mp4|mov|avi|ts)$/i);
var aepFiles = infoVidFolder.getFiles(/\.(aep)$/i);
var videoSubtitleArray = []; // Array of arrays. Each inner array pair contains the video and its respective subtitle AE project.
// matches each video file with its respective comments project
var m = 0;
var n = 0;
for (m=0; m<aepFiles.length; m++)
{
var fileNameOnly = aepFiles[m].name.substr(0, aepFiles[m].name.length - 4) // Removes the ".aep" part of file
for (n=0; n<allFoldVidFiles.length; n++)
{
if (allFoldVidFiles[n].name.indexOf(fileNameOnly) != -1)
videoSubtitleArray.push([allFoldVidFiles[n], aepFiles[m]]);
}
}
p = 0;
m =0;
n = 0;
for (p=0; p<videoSubtitleArray.length; p++)
{
for (m=0; m<logoArray.length; m++)
{
for (n=0; n<commercialsArray.length; n++)
{
controlPanelGUI.update();
if (stopVideoCreation != true)
{
app.open(new File(Folder.current.absoluteURI + "/" + templateProjName));
proj = app.project;
curInfoVidFile = videoSubtitleArray[p][0];
curLogoFile = logoArray[m];
curComVidFile = commercialsArray[n];
convrtProjToFrameIO (videoSubtitleArray[p][1]);
vidTitle = trimWhitespaces(nullMarkerLayer.marker.keyValue(1).comment.substring(nullMarkerLayer.marker.keyValue(1).comment.indexOf(": ")+2));
vidDescription = nullMarkerLayer.marker.keyValue(2).comment.substring(nullMarkerLayer.marker.keyValue(2).comment.indexOf(": ")+2);
theDocName = trimWhitespaces(nullMarkerLayer.marker.keyValue(3).comment.substring(nullMarkerLayer.marker.keyValue(1).comment.indexOf(": ")+2));
var finalVidName = theDocName + " " + vidTitle + " (logo-" + m + ")" + "(com-" + n + ")" + " (Render)";
createVideo(finalVidName);
proj.save(new File(ameWatchFolder.absoluteURI + "/" + finalVidName + ".aep"));
proj.close(CloseOptions.DO_NOT_SAVE_CHANGES);
}
}
}
}
alert("Video creation completed! All videos have been successfully created.");
}catch(e){
alert(e);
stopVideoCreation = true;
controlPanelGUI .close();
}
}
function decodeHexCode (colorHexCode)
/*
* This function accepts a (string) color code as its parameter. It converts the color code to its respective RGB values. It stores the RGB values
* as an array in the "videoBGColor" variable.
*/
{
try{
var redCol = parseInt(colorHexCode.substr(0,2),16)/255;
var greenCol = parseInt(colorHexCode.substr(2,2),16)/255;
var blueCol = parseInt(colorHexCode.substr(4,2),16)/255;
videoBGColor = [redCol, greenCol, blueCol];
}catch(e){
alert("Error occrured at: decodeHexCode");
alert(e);
throw Error("Unexpected error");
}
}
function decodeSpreadsheet ()
/*
* The first row of the spreadsheet is ignored. From the second row, the first column represents a logo path while
* the second column represents a commercial video path. "BLANK" keyword is used to specify no logo or no commercial.
*/
{
try{
var isOpen = spreadsheetFile.open("r");
if (isOpen)
{
spreadsheetFile.readln();
while (!spreadsheetFile.eof)
{
var curLine = spreadsheetFile.readln();
var logoCommercialArray = curLine.split(",");
if (logoCommercialArray[0] != "")
{
if (logoCommercialArray[0] == "BLANK")
logoArray.push("BLANK");
else
logoArray.push(new File(logoCommercialArray[0]));
}
if(logoCommercialArray[1] != "")
{
if (logoCommercialArray[1] == "BLANK")
commercialsArray.push("BLANK");
else
commercialsArray.push(new File(logoCommercialArray[1]));
}
}
spreadsheetFile.close();
}
}catch(e){
alert("Error occrured at: decodeSpreadsheet");
alert(e);
throw Error("Unexpected error");
}
}
//============================================================================
function convrtProjToFrameIO (commentProjFile)
/*
* Parameter: project file object
*
* Algorithm:
* The project is imported into the current project.
* The comp inside the project is located
* The first layer is identified as the text layer with comments in the "Source Text" property
* The comments are transfered into a null layer
* The null layer is assigned to global "nullMarkerLayer"
* The comment text layer is deleted
*
* Conditions:
* There should be only one comp in the imported project
* The first layer in that comp should be the comment text layer
*/
{
try
{
var compObj = null;
var comTxtLayer = null;
var cProjFolder = proj.importFile( new ImportOptions(commentProjFile) );
compObj = findCommentCompRecurse (cProjFolder);
if (compObj == null)
{
alert("No comps present in the project.");
throw Error("Unexpected Error");
}
if (compObj.layer(2).hasVideo)
{
infoVidCenterX = compObj.layer(2).anchorPoint.value[0];
infoVidCenterX *= (compObj.layer(2).scale.value[0]/100);
}else{
alert ("The second layer in the comp should be the video layer to get the center position");
}
if (compObj.layer(1).property("Source Text") == null)
{
alert("First layer in comp should be the comment text layer.");
throw Error ("Unexpected Error");
}
comTxtLayer = compObj.layer(1);
nullMarkerLayer = compObj.layers.addNull (comTxtLayer.outPoint);
for (var j=1; j<=comTxtLayer.property("Source Text").numKeys; j++)
{
var curKeyTxt = comTxtLayer.property("Source Text").keyValue(j).text;
if (curKeyTxt != "")
{
var firstPart = curKeyTxt.substring(0, curKeyTxt.indexOf(" - " ) ) + ": ";
// gets second ":"
var secPart = curKeyTxt.substring( curKeyTxt.indexOf(":")+1);
secPart = secPart.substring(secPart.indexOf(":")+2);
var editedTxt = firstPart + secPart;
var newMarker = new MarkerValue("Text Marker-" + j);
newMarker.comment = editedTxt;
nullMarkerLayer.property("Marker").setValueAtTime (comTxtLayer.property("Source Text").keyTime(j), newMarker);
}
}
comTxtLayer.remove();
}catch(e){
alert("Error occured at:convrtProjToFrameIO");
alert(e);
throw Error ("Uexpected error");
}
}
function findCommentCompRecurse (foldItem)
/*
* Recursively searches the (comment) project folder to find the comp containing the coment layer.
*/
{
var compItem = null;
for (var i=1; i<=foldItem.numItems; i++)
{
if (foldItem.item(i).typeName == "Composition")
compItem = foldItem.item(i);
else if (foldItem.item(i).typeName == "Folder")
{
var retrnItem = findCommentCompRecurse (foldItem.item(i));
if (retrnItem != null)
compItem = retrnItem;
}
}
return compItem;
}
//============================================================================
function createVideo(finalVidName)
/*
* Handles the creation of one video (AE project) using the given parameters.
*/
{
controlPanelGUI.update();
try{
findComInfoVidTransComp ();
var mainComp = proj.items.addComp(vidTitle, vidDimens[0], vidDimens[1], 1, 60, 30);
var totTime = 0;
if (curComVidFile == "BLANK")
{
totTime += addIntroVid (mainComp, true);
totTime += addComInfoTransition (mainComp, totTime);
totTime += addInfoVid (mainComp, totTime);
totTime += addOutro (mainComp, totTime);
}else{
totTime += addIntroVid (mainComp, false);
totTime += addComVid (mainComp, totTime);
totTime += addComInfoTransition (mainComp, totTime);
totTime += addInfoVid (mainComp, totTime);
totTime += addOutro (mainComp, totTime);
}
mainComp.duration = totTime;
var renderFold = proj.items.addFolder("Render-Folder");
mainComp.parentFolder = renderFold;
var finalComp = proj.items.addComp(finalVidName, finalVidDimens[0], finalVidDimens[1], 1, totTime, 30);
finalComp.bgColor = videoBGColor;
finalComp.layers.addSolid(videoBGColor, "Background", finalVidDimens[0], finalVidDimens[1], 1, totTime);
var finalVideoLayer = finalComp.layers.add(mainComp);
finalVideoLayer.scale.setValue([(finalVidDimens[0]/vidDimens[0])*100, (finalVidDimens[1]/vidDimens[1])*100]);
}catch(e){
alert("Error occrured at: createVideo");
alert(e);
throw Error("Unexpected error");
}
}
function findComInfoVidTransComp ()
/*
* Finds the video introduction comp and assigns it to the "comInfoVidTransComp" variable.
*/
{
controlPanelGUI.update();
try{
var i=1;
for (i=1; i<=proj.numItems; i++)
{
if (proj.item(i).name == "Commercial-Info-Video-Transition")
comInfoVidTransComp = proj.item(i);
}
}catch(e){
alert("Error occrured at: findComInfoVidTransComp");
alert(e);
throw Error("Unexpected error");
}
}
function addIntroVid (mainCompObj, noCommercial)
/*
* This function adds the intro video to the main composition. The duration
* of the intro video is returned.
*/
{
controlPanelGUI.update();
try{
if (introFile.exists)
{
var introItem = proj.importFile(new ImportOptions(introFile));
var introLayer = mainCompObj.layers.add(introItem);
resizeComp (introLayer, vidDimens);
if (!noCommercial)
{
introLayer.opacity.setValueAtTime(introItem.duration - introComIndentTime, 100);
introLayer.opacity.setValueAtTime(introItem.duration, 0);
}
return introItem.duration;
}
alert("The intro file or file path is invalid. Please run the script again.");
throw Error("Error.");
return null;
}catch(e){
alert("Error occrured at: addIntroVid ");
alert(e);
throw Error("Unexpected error");
}
}
function addComVid (mainCompObj, curTime)
/*
* This function adds the commercial to the main composition. The duration of the commercial
* (minus the intersection duration) is returned.
*/
{
controlPanelGUI.update();
try{
if (curComVidFile.exists)
{
var comItem = proj.importFile(new ImportOptions(curComVidFile));
var comVidLayer = mainCompObj.layers.add(comItem);
comVidLayer.startTime = curTime - introComIndentTime;
comVidLayer.moveToEnd();
resizeComp (comVidLayer, vidDimens);
return comItem.duration - introComIndentTime;
}
alert("A commercial file doesn't exist. Make sure all commercial file paths are correct.");
alert("File name: " + curComVidFile.name);
throw Error("Error.");
}catch(e){
alert("Error occrured at: addComVid");
alert(e);
throw Error("Unexpected error");
}
}
function addComInfoTransition (mainCompObj, curTime)
/*
* This function sets the video title and description in the video introduction comp. It then adds the
* video introduction comp to the main composition. The duration of the video introduction
* comp (minus the intersection duration) is returned.
*/
{
controlPanelGUI.update();
try{
var titleAndDescComp = null;
var i = 1;
for (i=1; i<=proj.numItems; i++)
{
if (proj.item(i).name == "Transition-SubTitle-And-Description")
titleAndDescComp = proj.item(i);
}
var comInforTransLayer = mainCompObj.layers.add(comInfoVidTransComp);
titleAndDescComp.layer(1).property("Source Text").setValue(vidTitle);
titleAndDescComp.layer(2).property("Source Text").setValue(vidDescription);
// Corrects subtitle (video description) layer position if title is large
var transTitleHeight = titleAndDescComp.layer(1).sourceRectAtTime(0, false).height;
var defaultTitleHeight = 64;
if (transTitleHeight > defaultTitleHeight)
{
var curDesPos = titleAndDescComp.layer(2).position.value;
titleAndDescComp.layer(2).position.setValue([curDesPos[0], curDesPos[1] + (transTitleHeight-defaultTitleHeight)]);
}
comInforTransLayer.startTime = curTime - 2.5;
resizeComp (comInforTransLayer, vidDimens);
return comInfoVidTransComp.duration - 2.5;
}catch(e){
alert("Error occrured at: addComInfoTransition");
alert(e);
throw Error("Unexpected error")
}
}
function addInfoVid (mainCompObj, curTime)
/*
* This function adds the information video to the main composition. If specified, it also superimposes the
* selected logo on top of the information video. The duration of the information video (minus the intersection duration) is returned.
*/
{
controlPanelGUI.update();
try{
if (curInfoVidFile.exists)
{
infoVidItem = proj.importFile(new ImportOptions(curInfoVidFile));
infoVidLayer = mainCompObj.layers.add(infoVidItem);
resizeComp (infoVidLayer, vidDimens);
infoVidLayer.startTime = curTime - transInfoVidIndentTime;
infoVidLayer.moveAfter(mainCompObj.layer(2));
if (curLogoFile != "BLANK")
addInfoVidLogo (mainCompObj);
createHalfScreenAnim (mainCompObj);
createNameTagAnim (mainCompObj);
return infoVidItem.duration - transInfoVidIndentTime;
}
alert("A Main video doesn't exist or is invalid. Please run the script again.");
alert("File name: " + curInfoVidFile.name);
throw Error("Error.");
return null;
}catch(e){
alert("Error occrured at: addInfoVid");
alert(e);
throw Error("Unexpected error");
}
}
function addOutro (mainCompObj, curTime)
/*
* This function adds the outro video to the main composition. The duration of the outro video
* (minus the intersection duration) is returned.
*/
{
controlPanelGUI.update();
try{
if (outroFile.exists)
{
var outroItem = proj.importFile(new ImportOptions(outroFile));
var outroLayer = mainCompObj.layers.add(outroItem);
outroLayer.startTime = curTime - infoVidOutroIndentTime;
outroLayer.opacity.setValueAtTime(outroLayer.startTime, 0);
outroLayer.opacity.setValueAtTime(outroLayer.startTime + infoVidOutroIndentTime, 100);
resizeComp (outroLayer, vidDimens);
return outroItem.duration - infoVidOutroIndentTime;
}
alert("The outro file or file path is invalid. Please run the script again.");
throw Error("Error.");
return null;
}catch(e){
alert("Error occrured at: addOutro");
alert(e);
throw Error("Unexpected error");
}
}
function addInfoVidLogo (mainCompObj)
/*
* This function superimposes the logo on top of the information video layer.
*/
{
controlPanelGUI.update();
try{
if (curLogoFile.exists)
{
var logoItem = proj.importFile(new ImportOptions(curLogoFile));
logoLayer = mainCompObj.layers.add(logoItem);
logoLayer.moveBefore(infoVidLayer);
resizeComp (logoLayer, logoDimens);
logoLayer.position.setValue([vidDimens[0]*0.83, vidDimens[1]*0.9]);
logoLayer.startTime = infoVidLayer.startTime - (2/30);
logoLayer.outPoint = infoVidItem.duration + logoLayer.startTime;
}else{
alert("A logo file or file path is invalid. Please run the script again.");
alert("File name: " + curLogoFile.name);
throw Error("Error.");
}
}catch(e){
alert("Error occrured at: addInfoVidLogo");
alert(e);
throw Error("Unexpected error");
}
}
function resizeComp (layerObj, resizeDimens)
/*
* This function resizes the passed-in layer (layerObj) such that the whole layer fits inside the
* passed-in dimensions (resizeDimens).
*/
{
controlPanelGUI.update();
try{
var widthRatio = resizeDimens[0] / layerObj.width;
var heightRatio = resizeDimens[1] / layerObj.height;
if (widthRatio < heightRatio)
layerObj.scale.setValue([widthRatio*100,widthRatio*100]);
else
layerObj.scale.setValue([heightRatio*100,heightRatio*100]);
}catch(e){
alert("Error occrured at: resizeComp");
alert(e);
throw Error("Unexpected error");
}
}
function createNameTagAnim (mainCompObj)
/*
* This function handles the creation of the dr. name and location tag animation.
* It changes the dr. name and location to the user defined values and then animates the
* tags.
*/
{
controlPanelGUI.update();
try{
var drNameLayerYPos = (320/360) * vidDimens[1];
//outAnimStrtTime = nullMarkerLayer.marker.keyTime(5) + infoVidLayer.startTime;
drNameAndProf = nullMarkerLayer.marker.keyValue(3).comment.substring(nullMarkerLayer.marker.keyValue(3).comment.indexOf(": ")+2);
drLocation = nullMarkerLayer.marker.keyValue(4).comment.substring(nullMarkerLayer.marker.keyValue(4).comment.indexOf(": ")+2);
var drNameComp = null;
var j=1;
for (j=1; j<=proj.numItems; j++)
{
if (proj.item(j).name == "Name-Tag")
drNameComp = proj.item(j);
}
drNameComp.layer(2).property("Source Text").setValue(drNameAndProf);
drNameComp.layer(1).property("Source Text").setValue(drLocation);
drNameWidth = drNameComp.layer(2).sourceRectAtTime(0, false).width;
drLocWidth = drNameComp.layer(1).sourceRectAtTime(0, false).width;
var origDrNameCompWidth = drNameComp.width;
var maxTextWidth = 0;
if (drNameWidth > drLocWidth)
maxTextWidth = drNameWidth;
else
maxTextWidth = drLocWidth;
drNameComp.width = Math.round(maxTextWidth * 1.1);
drNameComp.layer(1).position.setValue([Math.round(drNameComp.width/2), drNameComp.layer(1).position.value[1]]);
drNameComp.layer(2).position.setValue([Math.round(drNameComp.width/2), drNameComp.layer(2).position.value[1]]);
drNameLayer = mainCompObj.layers.add(drNameComp);
drNameLayer.moveBefore(infoVidLayer);
var inAnimStrtTime = infoVidLayer.startTime + 0.3 + transInfoVidIndentTime;
// Animation of whole "Name-Tag" comp
drNameLayer.position.setValueAtTime(inAnimStrtTime, [-(drNameComp.width/2)-2, drNameLayerYPos]);
drNameLayer.position.setValueAtTime(inAnimStrtTime + 1, [drNameComp.width/2, drNameLayerYPos]);
drNameLayer.position.setValueAtTime(inAnimStrtTime + 6, [drNameComp.width/2, drNameLayerYPos]);
drNameLayer.position.setValueAtTime(inAnimStrtTime + 7, [-(drNameComp.width/2)-2, drNameLayerYPos]);
var k = 1;
for (k=1; k<=drNameLayer.position.numKeys; k++)
drNameLayer.position.setInterpolationTypeAtKey(k, KeyframeInterpolationType.BEZIER);
// Animation of textboxes in "Name-Tag" comp
var origDrNamePos = drNameComp.layer(2).position.value;
drNameComp.layer(2).position.setValueAtTime(inAnimStrtTime, origDrNamePos - (drNameWidth*1.2));
drNameComp.layer(2).position.setValueAtTime(inAnimStrtTime + 1.3, origDrNamePos);
drNameComp.layer(2).position.setInterpolationTypeAtKey(1, KeyframeInterpolationType.BEZIER);
drNameComp.layer(2).position.setInterpolationTypeAtKey(2, KeyframeInterpolationType.BEZIER);
var origDrLocPos = drNameComp.layer(1).position.value;
drNameComp.layer(1).position.setValueAtTime(inAnimStrtTime, origDrLocPos - (drLocWidth*1.2));
drNameComp.layer(1).position.setValueAtTime(inAnimStrtTime + 2, origDrLocPos);
drNameComp.layer(1).position.setInterpolationTypeAtKey(1, KeyframeInterpolationType.BEZIER);
drNameComp.layer(1).position.setInterpolationTypeAtKey(2, KeyframeInterpolationType.BEZIER);
}catch(e){
alert("Error occrured at: createNameTagAnim");
alert(e);
throw Error("Unexpected error");
}
}
/*
function createHalfScreenAnim (mainCompObj)
{
controlPanelGUI.update();
try{
var halfScreenComp = proj.items.addComp("Half-Screen", vidDimens[0], vidDimens[1], 1, 600, 30);
var halfScreenFold = proj.items.addFolder("Half-Screen-Folder");
halfScreenComp.parentFolder = halfScreenFold;
halfScreenComp.duration = nullMarkerLayer.marker.keyTime(nullMarkerLayer.marker.numKeys) + 20;
var whiteBG = halfScreenComp.layers.addSolid([1,1,1], "White-BG", vidDimens[0], vidDimens[1], 1, halfScreenComp.duration);
var halfScreenLayer = mainCompObj.layers.add(halfScreenComp);
halfScreenLayer.moveBefore(infoVidLayer);
halfScreenLayer.startTime = infoVidLayer.startTime;
halfScreenOutPos = [halfScreenLayer.position.value[0] + halfScreenLayer.width, halfScreenLayer.position.value[1]];
halfScreenInPos = [halfScreenOutPos[0] - (halfScreenLayer.width/2), halfScreenLayer.position.value[1]];
var lastUsedMarker = 4
while (lastUsedMarker != nullMarkerLayer.marker.numKeys)
{
var subtitleReturn = createSubtitles (halfScreenComp, lastUsedMarker+1);
var halfAnimStrtTime = nullMarkerLayer.marker.keyTime(lastUsedMarker+1) + infoVidLayer.startTime;
var halfAnimFinTime = subtitleReturn[0] + infoVidLayer.startTime + halfScreenPaddingTime;
lastUsedMarker = subtitleReturn[1];
halfScreenLayer.position.setValueAtTime(halfAnimStrtTime, halfScreenOutPos);
halfScreenLayer.position.setValueAtTime(halfAnimStrtTime + 2.0, halfScreenInPos);
halfScreenLayer.position.setValueAtTime(halfAnimFinTime, halfScreenInPos);
halfScreenLayer.position.setValueAtTime(halfAnimFinTime + 2.0, halfScreenOutPos);
var k = 1;
for (k=1; k<=halfScreenLayer.position.numKeys; k++)
halfScreenLayer.position.setInterpolationTypeAtKey(k, KeyframeInterpolationType.BEZIER);
var origVidPos = infoVidLayer.position.value;
var infoVidHalfXPos = infoVidCenterX - (vidDimens[0]/4);
if (infoVidHalfXPos<0)
infoVidHalfXPos = origVidPos[0];
else
infoVidHalfXPos = origVidPos[0] - infoVidHalfXPos;
infoVidLayer.position.setValueAtTime(halfAnimStrtTime, origVidPos);
infoVidLayer.position.setValueAtTime(halfAnimStrtTime + 2.0, [infoVidHalfXPos, origVidPos[1]]);
infoVidLayer.position.setValueAtTime(halfAnimFinTime, [infoVidHalfXPos, origVidPos[1]]);
infoVidLayer.position.setValueAtTime(halfAnimFinTime + 2.0, origVidPos);
k = 1;
for (k=1; k<=infoVidLayer.position.numKeys; k++)
infoVidLayer.position.setInterpolationTypeAtKey(k, KeyframeInterpolationType.BEZIER);
}
}catch(e){
alert("Error occrured at: createHalfScreenAnim");
alert(e);
throw Error("Unexpected error");
}
}
*/
function createHalfScreenAnim (mainCompObj)
{
controlPanelGUI.update();
try{
var topicInteval = 20; // if the number of seconds between topics is less than this value, the half-screen stays
var halfScreenComp = proj.items.addComp("Half-Screen", vidDimens[0], vidDimens[1], 1, 600, 30);
var halfScreenFold = proj.items.addFolder("Half-Screen-Folder");
halfScreenComp.parentFolder = halfScreenFold;
halfScreenComp.duration = nullMarkerLayer.marker.keyTime(nullMarkerLayer.marker.numKeys) + 20;
var whiteBG = halfScreenComp.layers.addSolid([1,1,1], "White-BG", vidDimens[0], vidDimens[1], 1, halfScreenComp.duration);
var halfScreenLayer = mainCompObj.layers.add(halfScreenComp);
halfScreenLayer.moveBefore(infoVidLayer);
halfScreenLayer.startTime = infoVidLayer.startTime;
halfScreenOutPos = [halfScreenLayer.position.value[0] + halfScreenLayer.width, halfScreenLayer.position.value[1]];
halfScreenInPos = [halfScreenOutPos[0] - (halfScreenLayer.width/2), halfScreenLayer.position.value[1]];
var curMarkerIndx = 4;
while (curMarkerIndx != nullMarkerLayer.marker.numKeys)
{
var halfScreenAnimIn = true,
halfScreenAnimOut = true;
// checks if the time difference between the previous topic and the current topic is less than "topicInterval"
// time difference: (new-topic-heading) - (last-topic-last-point)
if (curMarkerIndx > 4)
{
if (nullMarkerLayer.marker.keyTime(curMarkerIndx+1) - nullMarkerLayer.marker.keyTime(curMarkerIndx) < topicInteval)
halfScreenAnimIn = false; // Do not animate-in because previous half-screen would be remaining
}
var subtitleReturn = createSubtitles (halfScreenComp, curMarkerIndx+1);
var halfAnimStrtTime = nullMarkerLayer.marker.keyTime(curMarkerIndx+1) + infoVidLayer.startTime;
var halfAnimFinTime = subtitleReturn[0] + infoVidLayer.startTime + halfScreenPaddingTime;
curMarkerIndx = subtitleReturn[1];
// checks if the time difference between the current topic and the next topic is less than "topicInterval"
// time difference: (current-topic-last-point) - (next-topic-heading)
if (curMarkerIndx != nullMarkerLayer.marker.numKeys)
{
if (nullMarkerLayer.marker.keyTime(curMarkerIndx+1) - nullMarkerLayer.marker.keyTime(curMarkerIndx) < topicInteval)
halfScreenAnimOut = false; // Do not animate-out because next half-screen will not animate-in
}
var origVidPos = infoVidLayer.position.value;
var infoVidHalfXPos = infoVidCenterX - (vidDimens[0]/4);
if (infoVidHalfXPos<0)
infoVidHalfXPos = origVidPos[0];
else
infoVidHalfXPos = origVidPos[0] - infoVidHalfXPos;