-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.html
1219 lines (1018 loc) · 52 KB
/
index.html
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
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>FFMPEG command builder</title>
<style>
textarea { width: 800px;
height: 600px; }
.lg-edit { width: 600px; }
.sm-edit { width: 50px;}
.vsm-edit { width: 40px; }
body { padding-left: 20px;
padding-right: 20px;
font-family: Helvetica, Arial, "sans-serif";
font-size: 14px }
h3 { margin-block-end: 5px; }
h4 { margin-block-start: 8px;
margin-block-end: 3px; }
.options { display: none; }
.perrate { display: none; }
.sm-button { width: 25px; text-align: center}
.col { display: flex;
flex-direction: column;
flex-basis: 100%;
flex: 1; }
.row { display: flex;
flex-direction: row;
flex-wrap: wrap;
width: 100%; }
a { color: black; }
.modal{position:fixed;top:0;left:0;bottom:0;right:0;display:none;overflow:auto;background-color:#000;background-color:rgba(0,0,0,.7);z-index:9999}
.modal-window{position:relative;background-color:#fff;width:50%;margin:10% auto;padding:20px}
.close{position:absolute;top:0;right:0;color:rgba(0,0,0,.3);height:30px;width:30px;font-size:30px;line-height:30px;text-align:center}
.close:hover,.close:focus{color:#000;cursor:pointer}
.open{display:block}
</style>
</head>
<script>
const VERSION = "r0.3k"
const BUILDER = "Generated by command builder "+VERSION;
const RELEASE_NOTES = [
{ version: "0.3k",
features: [ "Added support for Windows Batch script output",
"Added support for ddagrab (requires FFMPEG v6)",
"Added support for Roger Pack’s screen-capture-recorder"] },
{ version: "0.3j",
features: [ "Add common HLS options"] },
{ version: "0.3i",
features: [ "Removed hls_init_time, due odd issue at start of sliding window"] },
{ version: "0.3h",
features: [ "Added audio only support mode, remove all video renditions to enable",
"Moved scaling to filter_complex due to performance improvement vs inline scaling",
"Added deinterlace filter (bob-weave)",
"Added maxrate to video encodes for HLS compliance",
"Added RTMP input and output with multi-stream support",
"Added constant bitrate modes",
"Default CPU usage mode is now set to veryfast"] },
{ version: "0.3g",
features: [ "Optimized support for combining HLS-muxed and DASH cmaf (discrete) for multiple video encodes" ] },
{ version: "0.3f",
features: [ "Multiple outputs selectable, enables tee pseudo muxer",
"Remove rtmp output (temp)",
"Added use_fifo for hls muxer to avoid issue with mpegs stuttering",
"More than one video encode causes issues when HLS+MPEGTS are enabled together" ] },
{ version: "0.3e",
features: [ "Added mpegts input, using ignore error flags and large fifo",
"Fixed issue input parameters not updating script correctly",
"Rearranged optimizations",
"Added seperate modes for DASH and HLS muxers." ] },
{ version: "0.3d",
features: [ "Fixed issue video parameters not updating script correctly" ] }
]
const MAC = 0
const WIN = 1
let SCRIPTTYPE = MAC
let DELIMITER = "\\\n"
let QUOTE = "\'"
const DEFAULT_MAC_FONT = "/usr/share/fonts/truetype/freefont/FreeSans.ttf"
const DEFAULT_WIN_FONT = "/Windows/Fonts/arial.ttf"
// Analytics tracker ---------------------------------------------------------
/*
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-47247573-14', 'auto');
ga('send', 'pageview');
*/
// ---------------------------------------------------------------------------
function copy() {
let textarea = document.getElementById("cmd_div");
textarea.select();
document.execCommand("copy");
document.getSelection().removeAllRanges();
document.getElementById("clipboardbutton_id").innerHTML = "Copied!"
setTimeout(() => {
document.getElementById("clipboardbutton_id").innerHTML = "Copy to clipboard"
}, 2000);
}
function showhide(t,i) {
document.getElementById(i).style.display = t.checked ? "block" : "none";
document.getElementById(i).style.padding = t.checked ? '5px 25px' : '0px';
rebuild_command();
}
function showhideclass(t,i) {
Array.from(document.getElementsByClassName(i)).forEach(a => a.style.display = t.checked ? "block":"none");
rebuild_command();
}
function endis(t,i) {
document.getElementById(i).disabled = t.checked;
}
function override(t,i,d) {
if (t.checked) document.getElementById(i).value = d;
}
// INPUTS *************************************************************************************************************
function input_fileloop() {
return "-re -fflags +genpts -stream_loop -1 -i " + document.getElementById("loop_filename").value + " \\\n";
}
function input_sdi() {
return "-copyts -probesize 10M -f decklink -bm_v210 0 -audio_depth 16 -channels 2 -queue_size 124608000 \\\n" +
"-decklink_copyts 1 -audio_pts abs_wallclock -video_pts abs_wallclock \\\n" +
"-i \""+document.getElementById("sdi_input").value+"\" \\\n";
}
function input_udp() {
return "-err_detect ignore_err \\\n" +
"-re -i 'udp://"+document.getElementById("ip_input").value+":"+document.getElementById("udp_input").value+"?fifo_size=1000000&overrun_nonfatal=1' \\\n";
}
function input_avf() {
return "-f avfoundation -framerate "+document.getElementById('inputframerate_id').value+" -i \""+document.getElementById("avf_input").value+"\" \\\n";
}
function input_rtmp() {
return "-re -i "+document.getElementById("rtmp_input").value+" \\\n" +
"-max_muxing_queue_size 9999 \\\n";
}
function input_dda() {
return "-rtbufsize 100M -probesize 2500 \\\n" +
"-f dshow -i audio=\""+document.getElementById("dshow_input").value+"\" \\\n";
}
// Roger Pack’s screen-capture-recorder dshow filter.
function input_scr() {
return "-thread_queue_size 1024 -rtbufsize 2000M -probesize 2500 -re \\\n" +
"-f dshow -framerate "+document.getElementById('inputframerate_id').value+" -i video=\"screen-capture-recorder\":audio=\""+document.getElementById("dshow_input").value+"\" \\\n";
}
//-f dshow -framerate 50/1 -i video="screen-capture-recorder":audio="Line 1 (Virtual Audio Cable)" \
/*
function input_local_rtmp() {
return "-f flv -listen 1 -i rtmp://localhost:1935/live/app"
}
*/
function input_selected() {
switch (document.getElementById('inputselected_id').selectedIndex) {
case 1: return input_fileloop();
case 2: return input_sdi();
case 3: return input_avf();
case 4: return input_udp();
case 5: return input_rtmp();
case 6: return input_dda();
case 7: return input_scr();
//case 6: return input_local_rtmp();
}
}
function inputselected_changed(index) {
let options = '';
switch (index) {
case 1 : options = '<label for="loop_filename">Filename</label><input onchange="rebuild_command()" type="text" id="loop_filename" value="testclip.mp4">';
break;
case 2 : options = '<label for="sdi_input">Device label</label><input onchange="rebuild_command()" type="text" id="sdi_input" value="DeckLink SDI (1)">';
break;
case 3 : options = '<label for="avf_input">AV inputs v:a</label><input onchange="rebuild_command()" type="text" id="avf_input" value="0:0">';
break;
case 4 : options = '<label for="ip_input">IP address</label><input onchange="rebuild_command()" type="text" id="ip_input" value="<IP Address>">' +
'<label for="udp_input">UDP port</label><input onchange="rebuild_command()" class="sm-edit" type="text" id="udp_input" value="<port>">';
break;
case 5 : options = '<label for="rtmp_input">RTMP server</label><input onchange="rebuild_command()" type="text" id="rtmp_input" value="<RTMP Address>">';
break;
case 6 : options = '<label for="dda_input">Display idx</label><input onchange="rebuild_command()" class="sm-edit" type="text" id="dda_input" value="0">' +
'<label for="dshow_input">Audio dev</label><input onchange="rebuild_command()" type="text" id="dshow_input" value="CABLE Output (VB-Audio Virtual Cable)">';
break;
case 7 : options = '<label for="dshow_input">Audio dev</label><input onchange="rebuild_command()" type="text" id="dshow_input" value="virtual-audio-capturer">';
break;
}
document.getElementById('inputOptions').innerHTML = options;
rebuild_command();
}
// FILTERS ************************************************************************************************************
// Overlay wallclock
function filter_wallclock_init() {
return "settb=AVTB," +
"setpts='trunc(PTS/1K)*1K+st(1,trunc(RTCTIME/1K))-1K*trunc(ld(1)/1K)',";
}
function filter_wallclock_string() {
return "%{localtime\\:%M}\\:%{localtime\\:%S}.%{eif\\:1M*t-1K*trunc(t*1K)\\:d\\:3}";
}
function filter_drawbox(x,y,w,h,c,o) {
return "drawbox=x="+document.getElementById(x).value+":y="+document.getElementById(y).value+
":width="+document.getElementById(w).value+":height="+document.getElementById(h).value+
":color="+document.getElementById(c).value+"@"+document.getElementById(o).value+":t=fill";
}
function filter_drawtext(t,x,y,ff,fs,fc) {
return "drawtext=text='"+t+
"':x="+document.getElementById(x).value+":y="+document.getElementById(y).value+":"+(SCRIPTTYPE==MAC?"\\\n":"")+
"fontfile="+document.getElementById(ff).value+":"+
"fontsize="+document.getElementById(fs).value+":fontcolor="+document.getElementById(fc).value;
}
function filter_apply() {
let filterstr = "-filter_complex \""; // remove "
//ddagrab=output_idx=0:framerate=50,hwdownload,format=bgra
if (document.getElementById('inputselected_id').selectedIndex==6) {
filterstr += "ddagrab=output_idx="+document.getElementById("dda_input").value+":framerate="+document.getElementById('inputframerate_id').value+",hwdownload,format=bgra,"
}
if (document.getElementById('filter_deinterlace_id').checked) {
filterstr += "bwdif=0:0:0,"+DELIMITER
}
// background/text common for all streams...
if (document.getElementById('filter_banner_id').checked) {
var bt = document.getElementById('banner_text').value;
if (document.getElementById('burntimecode_id').checked) {
filterstr += filter_wallclock_init() + DELIMITER
bt = filter_wallclock_string();
}
filterstr += filter_drawbox('banner_x','banner_y','banner_w','banner_h','banner_bc','banner_bo');
filterstr += ","+DELIMITER
filterstr += filter_drawtext(bt,'banner_ox','banner_oy','banner_tf','banner_ts','banner_tc');
filterstr += ","+DELIMITER
}
// background for per bitrate banner...
if (document.getElementById('filter_per_bitrate_banner_id').checked) {
filterstr += filter_drawbox('banner_p_x','banner_p_y','banner_p_w','banner_p_h','banner_p_bc','banner_p_bo');
filterstr += ","+DELIMITER
}
// split
//if (encoding_table.length>1)
//{
filterstr += "split="+encoding_table.length;
for (i=0; i<encoding_table.length; i++) { filterstr += "[s"+i+"]"; }
filterstr += ";"+DELIMITER
// post filters (per bitrate)
for (i=0; i<encoding_table.length; i++) {
filterstr += "[s"+i+"]";
if (document.getElementById('filter_per_bitrate_banner_id').checked) {
filterstr += filter_drawtext(encoding_table[i].overlay,'banner_p_ox','banner_p_oy','banner_p_tf','banner_p_ts','banner_p_tc');
filterstr += ","+DELIMITER
}
filterstr += "scale=" + encoding_table[i].res;
filterstr += "[s"+i+"]";
if (i!=encoding_table.length-1) { filterstr += ";"+DELIMITER; }
}
//} else {
// if (document.getElementById('filter_per_bitrate_banner_id').checked) {
// filterstr += filter_drawtext(encoding_table[0].overlay,'banner_p_ox','banner_p_oy','banner_p_tf','banner_p_ts','banner_p_tc');
// filterstr += ","+DELIMITER
// }
// filterstr += "scale=" + encoding_table[0].res;
//}
filterstr += "\" \\\n\\\n"; // remove "
return filterstr;
}
function generate_preview() {
var c = document.getElementById("preview");
var ctx = c.getContext("2d");
ctx.fillStyle = "#008800";
ctx.fillRect(0,0,384,216);
if (document.getElementById('filter_banner_options').style.display == "block") {
ctx.beginPath();
ctx.lineWidth = "1";
ctx.fillStyle = document.getElementById('banner_bc').value;
ctx.rect(Number(document.getElementById('banner_x').value)/5, Number(document.getElementById('banner_y').value)/5,
Number(document.getElementById('banner_w').value)/5, Number(document.getElementById('banner_h').value)/5 );
ctx.fill();
ctx.font = Number(document.getElementById('banner_ts').value)/5+"px Arial";
ctx.fillStyle = document.getElementById('banner_tc').value;
ctx.fillText(document.getElementById('banner_text').value,
Number(document.getElementById('banner_ox').value)/5,
Number(document.getElementById('banner_oy').value)/5 + Number(document.getElementById('banner_ts').value)/5 - 5);
}
if (document.getElementById('filter_per_bitrate_banner_options').style.display == "block") {
ctx.beginPath();
ctx.lineWidth = "1";
ctx.fillStyle = document.getElementById('banner_p_bc').value;
ctx.rect(Number(document.getElementById('banner_p_x').value)/5, Number(document.getElementById('banner_p_y').value)/5,
Number(document.getElementById('banner_p_w').value)/5, Number(document.getElementById('banner_p_h').value)/5 );
ctx.fill();
ctx.font = Number(document.getElementById('banner_p_ts').value)/5+"px Arial";
ctx.fillStyle = document.getElementById('banner_p_tc').value;
ctx.fillText(document.getElementById('encode_overlay0').value,
Number(document.getElementById('banner_p_ox').value)/5,
Number(document.getElementById('banner_p_oy').value)/5 + Number(document.getElementById('banner_p_ts').value)/5 - 5);
}
}
function check_preview() {
if (document.getElementById('filter_banner_options').style.display == "block" ||
document.getElementById('filter_per_bitrate_banner_options').style.display == "block" ) {
document.getElementById('preview').style.display = "block";
}
else {
document.getElementById('preview').style.display = "none";
}
}
// ENCODES ************************************************************************************************************
var encoding_table = [ {res: '1280x720', bitrate: '3000', overlay: '720p-3.0M'} ];
var res_table = ['1920x1080','1280x720','960x540','768x432','640x360','480x270'];
function loadpreset() {
switch (document.getElementById("presetselected_id").selectedIndex) {
case 1 : // SBR 1080p
encoding_table = [ {res: '1920x1080', bitrate: '4500', overlay: '1080p-4.5M'} ];
break;
case 2 : // SBR 720p
encoding_table = [ {res: '1280x720', bitrate: '3000', overlay: '720p-3.0M'} ];
break;
case 3 : // SBR 360p
encoding_table = [ {res: '640x360', bitrate: '730', overlay: '360p-0.7M'} ];
break;
case 5 : // MBR 1080p
encoding_table = [ {res: '1920x1080', bitrate: '6000', overlay: '1080p-6.0M'},
{res: '1920x1080', bitrate: '4500', overlay: '1080p-4.5M'},
{res: '1280x720', bitrate: '3000', overlay: '720p-3.0M'},
{res: '960x540', bitrate: '2000', overlay: '540p-2.0M'},
{res: '768x432', bitrate: '1100', overlay: '432p-1.1M'},
{res: '640x360', bitrate: '730', overlay: '360p-0.7M'},
{res: '480x270', bitrate: '365', overlay: '270p-0.4M'}
];
break;
case 6 : // MBR 720p
encoding_table = [ {res: '1280x720', bitrate: '3000', overlay: '720p-3.0M'},
{res: '960x540', bitrate: '2000', overlay: '540p-2.0M'},
{res: '768x432', bitrate: '1100', overlay: '432p-1.1M'},
{res: '640x360', bitrate: '730', overlay: '360p-0.7M'},
{res: '480x270', bitrate: '365', overlay: '270p-0.4M'}
];
break;
}
draw_encode_table();
}
function updateencodingres(i, el) {
encoding_table[i].res = el.value;
draw_encode_table();
}
function updateencodingbitrate(i, el) {
encoding_table[i].bitrate = el.value;
draw_encode_table();
}
function updateencodingoverlay(i, el) {
encoding_table[i].overlay = el.value;
draw_encode_table();
}
function draw_encode_table() {
var dtable = "<tr><td></td><td>Resolution</td><td>Bitrate</td><td class='perrate'>Overlay</td></tr>";
for (i=0; i<encoding_table.length; i++) {
dtable += '<tr><td>';
dtable += '<button class="sm-button" onclick="encode_delete_row('+i+')">x</button></td><td>';
dtable += '';
dtable += '<select onchange="updateencodingres('+i+', this)" id="encode_res'+i+'">';
for (j=0; j<res_table.length; j++) {
dtable += '<option'+ (encoding_table[i].res==res_table[j]?' selected':'') +'>' + res_table[j] + '</option>';
}
dtable += '</select></td>';
dtable += '<td><input onchange="updateencodingbitrate('+i+', this)" class="sm-edit" type="text" value="'+encoding_table[i].bitrate+'" id="encode_bitrate'+i+'"></td>';
dtable += '<td><input onchange="updateencodingoverlay('+i+', this)" class="perrate" type="text" value="'+encoding_table[i].overlay+'" id="encode_overlay'+i+'"></td>';
dtable += '</tr>';
}
dtable += '<tr><td><button class="sm-button" onclick="encode_add_row()">+</button></td></tr>';
document.getElementById('encode_table').innerHTML = "<table>" + dtable + "</table>";
showhideclass(document.getElementById('filter_per_bitrate_banner_id'),"perrate");
rebuild_command();
update_rtmp_ep();
}
function encode_delete_row(i) {
encoding_table.splice(i,1);
draw_encode_table();
}
function encode_add_row() {
encoding_table.push({res: '1280x720', bitrate: '3000', overlay: '720p-3.0M'});
draw_encode_table();
}
function encodes_video() {
var data = "-pix_fmt yuv420p \\\n" +
"-c:v libx264 \\\n" +
"\\\n";
for (i=0; i<encoding_table.length; i++) {
data += "-b:v:"+i+" "+encoding_table[i].bitrate+"K ";
if (document.getElementById('encodemode_id').selectedIndex==1) {
data += "-minrate:v:"+i+" "+encoding_table[i].bitrate+"K ";
}
data += "-maxrate:v:"+i+" "+encoding_table[i].bitrate+"K ";
if (document.getElementById('encodemode_id').selectedIndex==1) {
data += "-bufsize:v:"+i+" "+encoding_table[i].bitrate+"K/10 \\\n";
} else {
data += "-bufsize:v:"+i+" "+encoding_table[i].bitrate+"K/2 \\\n";
}
//data += "-b:v:"+i+" "+encoding_table[i].bitrate+"K -s:v:"+i+" "+encoding_table[i].res+" \\\n";
}
return data;
}
function encodes_audio() {
// One audio to rule them all... change this if supporting multiple audios...
return "-c:a aac -ar "+document.getElementById('audiosample_id').value+" -b:a "+document.getElementById('audiobirate_id').value+" \\\n"
}
// OPTIMIZATIONS
function optimize() {
var opt_txt = "-preset veryfast \\\n";
if (document.getElementById('optimizeselected_id').selectedIndex < 2) { opt_txt += "-tune zerolatency \\\n" }
if (document.getElementById('encodemode_id').selectedIndex==1) {
if (document.getElementById('optimizeselected_id').selectedIndex == 1) { opt_txt += "-x264-params 'sliced-threads=0:nal-hrd=cbr' \\\n" }
else { opt_txt += "-x264-params nal-hrd=cbr \\\n"; }
} else {
if (document.getElementById('optimizeselected_id').selectedIndex == 1) { opt_txt += "-x264-params sliced-threads=0 \\\n" }
}
return opt_txt + "\\\n";
}
// OUTPUTS ************************************************************************************************************
function update_cmaf_ep() { // DASH
document.getElementById('cmaf_stream_ep').value = "http://p-ep" + document.getElementById('cmaf_stream_id').value + ".i.akamaientrypoint.net/cmaf/" +
document.getElementById('cmaf_stream_id').value + "/" +
document.getElementById('cmaf_stream_name').value + "/out.mpd";
rebuild_command();
}
function update_hls_ep() {
document.getElementById('hls_stream_ep').value = "http://p-ep" + document.getElementById('hls_stream_id').value + ".i.akamaientrypoint.net/" +
(document.getElementById('hls_package_type').selectedIndex==0?"cmaf/":"") +
document.getElementById('hls_stream_id').value + "/" +
document.getElementById('hls_stream_name').value + "/level_%v.m3u8";
rebuild_command();
}
function write_opt(key, value, t) {
if (t) {
// Escape characters $ and : in tee muxer output...
value = value.replaceAll('$','\\\$');
// $timestamp must not be escaped...
value = value.replaceAll('\\\$timestamp','$timestamp');
value = value.replaceAll(':','\\\:');
return ':'+key+'='+value+'\\\n';
}
else {
return '-'+key+' '+value+' \\\n'
}
}
function output_lhls() {
return "-strict experimental -lhls 1 -hls_playlist 1 \\\n";
}
function output_get_segduration() {
var segduration = 2;
if ((document.getElementById('optimizesegment_id').selectedIndex) == 1) {
segduration = 6;
}
var fps = eval(document.getElementById('inputframerate_id').value);
return (Math.round(fps) * segduration / fps).toFixed(3);
}
function output_cmaf(tee) {
var data = '';
var segduration = output_get_segduration();
if (tee) { data += "[f=dash\\\n" }
// If in HLS muxed mode...
if (in_hlsmuxed_mode()) {
if (encoding_table.length>0) {
data += ":select=\\\'v,a:0\\\'\\\n"
} else {
data += ":select=\\\'a:0\\\'\\\n" // Audio only
}
}
if (encoding_table.length>0) {
data += write_opt('adaptation_sets',QUOTE+'id=0,seg_duration='+segduration+',streams=v id=1,seg_duration='+segduration+',streams=a'+QUOTE,tee);
} else {
data += write_opt('adaptation_sets','\'id=0,seg_duration='+segduration+',streams=a\'',tee); // Audio only
}
data += write_opt('use_timeline','0',tee);
data += write_opt('streaming','1',tee);
// Ultra low latency mode
if ((document.getElementById('cmaf_package_type').selectedIndex)==2) { // LL-HLS
data += write_opt('window_size','3',tee);
data += write_opt('frag_type','every_frame',tee);
data += write_opt('ldash','1',tee);
data += write_opt('utc_timing_url','\'https://time.akamai.com?iso&ms\'',tee);
data += write_opt('format_options','\'movflags=cmaf\'',tee);
//data += write_opt('export_side_data','prft',tee); // Not supported in 4.3.2 on Mac. Is supported from source in Ubuntu?
data += write_opt('timeout', '0.5', tee);
data += write_opt('write_prft','1',tee);
data += write_opt('target_latency','\'3.0\'',tee);
}
data += write_opt('http_user_agent','Akamai_Broadcaster_v1.0',tee);
data += write_opt('http_persistent','1',tee);
// DASH + HLS mode
if ((document.getElementById('cmaf_package_type').selectedIndex)==1) { // DASH+HLS
data += write_opt('hls_playlist','1',tee);
//data += write_opt('hls_master_name','master.m3u8',tee);
}
data += write_opt('media_seg_name','$timestamp'+QUOTE+'/chunk-stream_$RepresentationID$-$Number%05d$.$ext$'+QUOTE,tee);
data += write_opt('init_seg_name','$timestamp'+QUOTE+'/init-stream_$RepresentationID$.$ext$'+QUOTE,tee);
if (tee) { data += ']'; }
else { data += "-f dash \\\n" }
data += document.getElementById('cmaf_stream_ep').value;
return data;
}
function output_hls(tee) {
var data = '';
var segduration = output_get_segduration();
if (tee) {
if (document.getElementById('cmafoutput_id').checked) { data += "|\\\n" }
data += "[f=hls\\\n"
data += ":use_fifo=1\\\n" // Workaround for HLS muxer when combined with other outputs, put it in seperate thread
}
//data += write_opt('hls_init_time',segduration,tee); // Not sure why this causes a werid issue at wraparound point in the stream?
data += write_opt('hls_time',segduration,tee);
data += write_opt('hls_list_size','20',tee);
// HLS options
var hlsopts = [];
if (document.getElementById('hlsopt_pdt_id').checked) { hlsopts.push("program_data_time") }
if (document.getElementById('hlsopt_indep_id').checked) { hlsopts.push("independent_segments") }
if (document.getElementById('hlsopt_delete_id').checked) { hlsopts.push("delete_segments") }
if (hlsopts.length!=0) {
var hlsoptstr = hlsopts[0];
for (i=1; i<hlsopts.length; i++) { hlsoptstr += "+"+hlsopts[i] }
data += write_opt('hls_flags',hlsoptstr,tee);
}
data += write_opt('hls_base_url','$timestamp/',tee);
var ext = "ts";
if ((document.getElementById('hls_package_type').selectedIndex)==0) {
data += write_opt('hls_segment_type','fmp4',tee);
ext = "m4s";
}
var var_map = QUOTE;
if (encoding_table.length>0) {
if (in_hlsmuxed_mode()) {
var_map += 'v:0,a:0';
for (i=1; i<encoding_table.length; i++) { var_map+=' v:'+i+',a:'+i; }
}
else {
// Only one audio for the moment...
var_map += 'a:0,agroup:a0,default:0';
for (i=0; i<encoding_table.length; i++) { var_map+=' v:'+i+',agroup:a0' }
}
}
else {
// Audio only service
var_map += 'a:0';
}
data += write_opt('var_stream_map',var_map+QUOTE,tee);
data += write_opt('hls_segment_filename',QUOTE+'http://p-ep'+document.getElementById('hls_stream_id').value +
'.i.akamaientrypoint.net/' +
(document.getElementById('hls_package_type').selectedIndex==0?'cmaf/':'') +
document.getElementById('hls_stream_id').value + '/' +
document.getElementById('hls_stream_name').value + '/'+QUOTE+'$timestamp/stream%v_%05d.'+ext,tee);
data += write_opt('master_pl_name','master.m3u8',tee);
data += write_opt('http_user_agent','Akamai_Broadcaster_v1.0',tee);
data += write_opt('http_persistent','1',tee);
if (tee) { data += ']'; }
else { data += "-f hls \\\n" }
data += document.getElementById('hls_stream_ep').value;
return data;
}
function write_rtmp_ep(id) {
var rtmpstr = "rtmp://";
if (document.getElementById('rtmp_auth').checked) {
rtmpstr += document.getElementById('rtmp_username').value + ":" + document.getElementById('rtmp_password').value + "@";
}
rtmpstr += "p.ep" + document.getElementById('rtmp_stream_id').value + ".i.akamaientrypoint.net/EntryPoint/" +
document.getElementById('rtmp_stream_key').value + "_1_"+id+"@" + document.getElementById('rtmp_stream_id').value;
return rtmpstr;
}
function update_rtmp_ep() {
document.getElementById('rtmp_stream_ep').value = write_rtmp_ep((encoding_table.length>0)?encoding_table[0].bitrate:1)
rebuild_command();
}
function output_rtmp(tee) {
var data = '';
if (tee) {
if (document.getElementById('cmafoutput_id').checked || (document.getElementById('hlsoutput_id').checked)) { data += "|\\\n" }
}
if (encoding_table.length>1) {
for (i=0; i<encoding_table.length; i++) {
data+="[f=flv:select=\\'v:"+i+",a:0\\']'" + write_rtmp_ep(encoding_table[i].bitrate) + "'";
if (i<(encoding_table.length-1)) { data += "|\\\n" }
}
}
else {
if (tee) { data += '[f=flv]'; }
else { data += "-f flv " }
data += "'"+write_rtmp_ep((encoding_table.length>0)?encoding_table[0].bitrate:1)+"'";
}
return data;
}
function output_multicast(tee) {
var ipudp = "\'udp://" + document.getElementById('mpegts_ip').value + ":" + document.getElementById('mpegts_udp').value + "?pkt_size=1316\'";
if (tee) {
return "|\\\n[f=mpegts]" + ipudp;
} else {
return "-f mpegts " + ipudp;
}
}
function output_mp4() {
return document.getElementById('mp4_filename').value;
}
function output_more_than_one() {
var count = 0;
if (document.getElementById('cmafoutput_id').checked) count++;
if (document.getElementById('hlsoutput_id').checked) count++;
if (document.getElementById('rtmpoutput_id').checked) count++;
if (document.getElementById('multicastoutput_id').checked) count++;
return (count>1)
}
function in_hlsmuxed_mode() {
return (document.getElementById('hls_package_type').selectedIndex==2 && document.getElementById('hlsoutput_id').checked)
}
// ********************************************************************************************************************
function rebuild_command() {
generate_preview();
let command = "ffmpeg \\\n\\\n";
// Input
command += input_selected();
command += "\\\n";
command += "-flags +global_header -r "+document.getElementById('inputframerate_id').value+" \\\n" // pull in frame rate
command += "\\\n";
// Filters
if (encoding_table.length>0) {
command += filter_apply();
}
// Encoder
if (encoding_table.length>0) {
command += encodes_video();
var keyframe = Math.round(eval(document.getElementById('inputframerate_id').value));
command += "\\\n" +
"-g:v "+keyframe+" -keyint_min:v "+keyframe+" -sc_threshold:v 0 \\\n" +
"\\\n" +
"-color_primaries bt709 -color_trc bt709 -colorspace bt709 \\\n" +
"\\\n"
}
command += encodes_audio();
command += "\\\n";
// Mapping
for (i=0; i<encoding_table.length; i++) {
//if (encoding_table.length>1) {
command += "-map [s"+i+"] ";
//} else command += "-map 0:v:0 ";
//if (document.getElementById('filter_per_bitrate_banner_id').checked) command += "-map [s"+i+"] ";
//else command += "-map 0:v:0 ";
};
if (encoding_table.length>0) { command += "\\\n"; }
// Hack for HLS (muxed segment mode)...
// Multiple maps to create audios, always have at least one (for audio only)
for (i=0; i<(in_hlsmuxed_mode()?Math.max(1,encoding_table.length):1); i++) {
command += "-map 0:a:0 ";
};
command += "\\\n";
// Optimatizations
command += "\\\n";
command += optimize();
// Outputs
// More than one output or RTMP and more than one video, use tee pseudo muxer
if (output_more_than_one() || ((document.getElementById('rtmpoutput_id').checked) && (encoding_table.length>1))) {
command += "-f tee \"\\\n"
}
if (document.getElementById('cmafoutput_id').checked) { command += output_cmaf(output_more_than_one()); }
if (document.getElementById('hlsoutput_id').checked) { command += output_hls(output_more_than_one()); }
if (document.getElementById('rtmpoutput_id').checked) { command += output_rtmp(output_more_than_one()); }
if (document.getElementById('multicastoutput_id').checked) { command += output_multicast(output_more_than_one()); }
//if (document.getElementById('mp4output_id').checked) { command += output_mp4(false); }
if (output_more_than_one()) { command += "\"" }
// Linux/Mac or Windows formatting...
let header = ""
if (SCRIPTTYPE==MAC) {
header = "#!/bin/bash\n\n"
header += "#" + BUILDER + "\n\n"
header += 'timestamp="$(date +%s)"' + "\n\n"
} else {
command = command.replace("ffmpeg","ffmpeg.exe")
command = command.replaceAll("\\\n\\\n","^\n")
command = command.replaceAll("\\\n","^\n")
command = command.replaceAll("%","%%")
//command = command.replaceAll("'",'"')
command = command.replaceAll("$timestamp","%timestamp%")
// Header
header = "::" + BUILDER + "\n\n"
header += 'for /f "tokens=2 delims==" %%a in (\'wmic OS Get localdatetime /value\') do set "dt=%%a"\n'
header += 'set timestamp=%dt:~0,4%%dt:~4,2%%dt:~6,2%%dt:~8,2%%dt:~10,2%%dt:~12,2%\n\n'
}
document.getElementById("cmd_div").value = header + command;
}
function change_script_format() {
SCRIPTTYPE = Number(document.getElementById("scriptformat_id").value)
DELIMITER=(SCRIPTTYPE==MAC?"\\\n":"")
QUOTE=(SCRIPTTYPE==MAC?"\'":'\"')
document.getElementById("banner_tf").value = SCRIPTTYPE==MAC?DEFAULT_MAC_FONT:DEFAULT_WIN_FONT
document.getElementById("banner_p_tf").value = SCRIPTTYPE==MAC?DEFAULT_MAC_FONT:DEFAULT_WIN_FONT
rebuild_command()
}
// RELEASE NOTES
function write_release_notes() {
var rt = "<h3>Release notes</h3>" +
"<p>This tool is tested against ffmpeg version 4.3 or higher<br/>" +
"Use of overlays requires drawfilter to be enabled in ffmpeg</p>"
RELEASE_NOTES.forEach(release => {
rt += "<h4>rev: "+release.version+"</h4><ul>";
release.features.forEach(feature => {
rt += "<li>"+feature+"</li>";
})
rt += "</ul>"
})
document.getElementById('releasenotes').innerHTML = rt;
document.getElementById('version').innerHTML = "("+VERSION+")";
}
function showreleasenotes() {
document.getElementById('ReleaseNotes').classList.add('open');
}
function hidereleasenotes() {
var modal = document.querySelector('[class="modal open"]');
modal.classList.remove('open');
}
</script>
<!-- UI ===================================================================--->
<body>
<h1>FFMPEG command line builder <span id="version"></span></h1>
<a href="#" onclick="showreleasenotes()">Release notes</a> <a href="https://github.com/peterchave/ffbuilder">Github</a>
<div id="ReleaseNotes" class="modal" onclick="hidereleasenotes()">
<div class="modal-window">
<span class="close">×</span>
<span id='releasenotes'></span>
</div>
</div>
<script>write_release_notes();</script>
<div class='row'>
<div class='col'>
<!-- Input section ------------------------------------------------------->
<div id="inputs">
<h3>Input</h3>
<table><tr>
<td>
<select id="inputselected_id" onChange="inputselected_changed(this.selectedIndex)">
<option disabled>---Live inputs---</option>
<option selected>Looped file</option>
<option>Decklink SDI port</option>
<option>Mac: webcam</option>
<option>MPEG-TS over IP</option>
<option>RTMP pull</option>
<option>Win: ddagrab</option>
<option>Win: screen-capture-recorder</option>
<!-- <option disabled>---VoD inputs---</option>
<option>File</option> -->
</select>
</td>
<td>
<div id="inputOptions"></div>
</td>
</tr>
<tr>
<td colspan=2>Framerate
<select id="inputframerate_id" onChange="rebuild_command()">
<option>60</option>
<option>60000/1001</option>
<option>50</option>
<option>30</option>
<option selected>30000/1001</option>
<option>25</option>
<option>24</option>
<option>24000/1001</option>
</select>
</td>
</tr></table>
</div>
<!-- Filter section ------------------------------------------------------>
<div id="filters">
<h3>Filters</h3>
<table><tr><td style="vertical-align: top">
<!-- Deinterlace filters --->
<input type="checkbox" id="filter_deinterlace_id" onChange="rebuild_command()">
<label for="filter_deinterlace_id">Deinterlace (Bob-weave)</label><br>
<!-- Banner text --->
<input type="checkbox" id="filter_banner_id" onChange="showhide(this,'filter_banner_options'); check_preview();">
<label for="filter_banner_id">Overlay banner</label><br>
<div class="options" id="filter_banner_options">
<table>
<tr><td>Banner position (x,y)</td>
<td><input class='sm-edit' type="text" id="banner_x" onChange="rebuild_command();" value="0"> ,
<input class='sm-edit' type="text" id="banner_y" onChange="rebuild_command();" value="0"></td></tr>
<tr><td>Banner size (w,h)</td>
<td><input class='sm-edit' type="text" id="banner_w" onChange="rebuild_command();" value="400"> ,
<input class='sm-edit' type="text" id="banner_h" onChange="rebuild_command();" value="100"></td></tr>
<tr><td>Banner color</td>
<td><input class='sm-edit' type="text" id="banner_bc" onChange="rebuild_command();" value="black"> @
<input class='vsm-edit' type="text" id="banner_bo" onChange="rebuild_command();" value="0.5"></td></tr>
<tr><td>Text position (x,y)</td>
<td><input class='sm-edit' type="text" id="banner_ox" onChange="rebuild_command();" value="15"> ,
<input class='sm-edit' type="text" id="banner_oy" onChange="rebuild_command();" value="20"></td></tr>
<tr><td>Text font</td>
<td><input type="text" id="banner_tf" onChange="rebuild_command();" value="/usr/share/fonts/truetype/freefont/FreeSans.ttf"></td></tr>
<tr><td>Text size</td>
<td><input class='sm-edit' type="text" id="banner_ts" onChange="rebuild_command();" value="80"></td></tr>
<tr><td>Text color</td>
<td><input type="text" id="banner_tc" onChange="rebuild_command();" value="white"></td></tr>
<tr><td>Timecode</td>
<td><input type="checkbox" checked id="burntimecode_id" onChange="endis(this,'banner_text'); override(this,'banner_text','00:00.000'); rebuild_command()"></td></tr>
<tr><td>Text</td>
<td><input disabled type="text" id="banner_text" onChange="rebuild_command();" value="00:00.000"></td></tr>
</table>
</div>
<input type="checkbox" id="filter_per_bitrate_banner_id" onChange="showhide(this,'filter_per_bitrate_banner_options'); showhideclass(this,'perrate'); check_preview();">
<label for="filter_per_bitrate_banner_id">Overlay per bitrate</label><br>
<div class="options" id="filter_per_bitrate_banner_options">
<table>
<tr><td>Banner position (x,y)</td>
<td><input class='sm-edit' type="text" id="banner_p_x" onChange="rebuild_command();" value="1460"> ,
<input class='sm-edit' type="text" id="banner_p_y" onChange="rebuild_command();" value="0"></td></tr>
<tr><td>Banner size (w,h)</td>
<td><input class='sm-edit' type="text" id="banner_p_w" onChange="rebuild_command();" value="460"> ,
<input class='sm-edit' type="text" id="banner_p_h" onChange="rebuild_command();" value="100"></td></tr>
<tr><td>Banner color</td>
<td><input class='sm-edit' type="text" id="banner_p_bc" onChange="rebuild_command();" value="black"> @
<input class='vsm-edit' type="text" id="banner_p_bo" onChange="rebuild_command();" value="0.5"></td></tr>
<tr><td>Text position (x,y)</td>
<td><input class='sm-edit' type="text" id="banner_p_ox" onChange="rebuild_command();" value="1480"> ,
<input class='sm-edit' type="text" id="banner_p_oy" onChange="rebuild_command();" value="20"></td></tr>
<tr><td>Text font</td>
<td><input type="text" id="banner_p_tf" onChange="rebuild_command();" value="/usr/share/fonts/truetype/freefont/FreeSans.ttf"></td></tr>
<tr><td>Text size</td>
<td><input class='sm-edit' type="text" id="banner_p_ts" onChange="rebuild_command();" value="80"></td></tr>
<tr><td>Text color</td>
<td><input type="text" id="banner_p_tc" onChange="rebuild_command();" value="white"></td></tr>
</table>
</div>
<!--
<input type="checkbox" id="filter_image_id" onChange="showhide(this,'filter_image_options'); check_preview();">
<label for="filter_image_id">Overlay image</label><br>
<div class="options" id="filter_image_options">
<table>
<tr><td>Image position (x,y)</td>
<td><input class='sm-edit' type="text" id="image_x" onChange="rebuild_command();" value="0"> ,
<input class='sm-edit' type="text" id="image_y" onChange="rebuild_command();" value="0"></td>
</tr>
<tr><td>Image filename</td>
<td><input type="text" id="image_filename" onChange="rebuild_command();" value="~/images/logo.png"></td></tr>