-
Notifications
You must be signed in to change notification settings - Fork 0
/
Quality Muncher.bat
3549 lines (3348 loc) · 144 KB
/
Quality Muncher.bat
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
:: This program is free software: you can redistribute it and/or modify it under the terms of the GNU 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 General Public License for more details.
:: You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.
:: Copyright 2023 Thqrn. Licensed under the GNU General Public License v3.0.
:: @froest on Discord
:: https://github.com/Thqrn/ffmpeg-scripts
:: https://github.com/qm-org/qualitymuncher
@echo off
if defined wt_session (
set wt_session=
start conhost.exe %0
exit /b 0
)
echo Log has been started>"%temp%\qualitymuncherdebuglog.txt"
setlocal enabledelayedexpansion
set me=%0
:: OPTIONS - THESE RESET AFTER UPDATING SO KEEP A COPY SOMEWHERE (unless you use the defaults)
:: clear the screen when each render finishes
set clearaftereachrender=y
:: automatic update checks, highly recommended to keep this enabled
set autoupdatecheck=y
:: directory for logs, if none set the input's directory is used ***add quotes if there is a space***
set loggingdir=
:: stay open after the file is done rendering
set stayopen=y
:: shows title
set showtitle=y
:: shows messages beneath titles
set displaymessages=y
:: cool animations (slows startup speed by a few seconds)
set animate=n
:: animation speed (default is 5)
set animatespeed=5
:: spinning loading bar
set loadingbar=y
:: encoding speed, doesn't change much - ultrafast, superfast, veryfast, faster, fast, medium, slow, slower, veryslow, placebo
set encodingspeed=ultrafast
:: scaling algorithm - fast_bilinear, bilinear, bicubic, expiramental, neighbor, area, bicublin, gauss, sinc, lanczos, spline
set scalingalg=neighbor
:: speed at which the ffmpeg stats update. lower is faster, but anything below 0.01 may cause slower render times
set updatespeed=0.05
:: the video container, uses .mp4 as default (don't forget the dot^^!)
set container=.mp4
:: the container for audio, uses .mp3 as default
set audiocontainer=.mp3
:: the image container, uses .jpg as default
set imagecontainer=.jpg
:: progress bar options
:: enable or disable progress bar
set progressbar=y
:: character to represent amount completed (MUST BE A SINGLE CHARACTER, NO MORE, NO LESS)
set "progressbar_donechar= "
:: prefix of all the characters (a color code is useful here)
set "progressbar_donecharprefix=[48;2;49;191;204m"
:: suffix of all the characters (again, a color code or something similar is useful here)
set "progressbar_donecharsuffix=[48;2;71;71;71m"
:: character to represent amount not yet completed
set "progressbar_unfinishedchar= "
:: length of progress bar
set progressbar_size=120
:: progress bar animation speed
set progressbaranimated_speed=3
:: END OF OPTIONS
:: ################################################################################################################################
:: ######################### WARNING: modifying any lines beyond this point could break the script! #########################
:: ################################################################################################################################
:: ========================================
:: startup
:: ========================================
:: default values for variables
call :setdefaults
echo Default variables set>>"%temp%\qualitymuncherdebuglog.txt"
if "%animate%" == "y" call :loadingbar
:: code page for proper character display
chcp 437 > nul
:: resetting quality muncher's temp folder
set "qmtemp=%temp%\qualitymunchertemp"
rmdir "%qmtemp%" > nul
mkdir "%qmtemp%" > nul
set version=1.5.3.2
:: start of the debug log
echo Quality Muncher v%version% successfully started on %date% at "%time%">>"%temp%\qualitymuncherdebuglog.txt"
echo ---------------INPUTS---------------->>"%temp%\qualitymuncherdebuglog.txt"
echo %*>>"%temp%\qualitymuncherdebuglog.txt"
echo ------------------------------------->>"%temp%\qualitymuncherdebuglog.txt"
set ismultiqueue=n
:: if the file is ran with a parameter:
:: - check if it matches any standard help args
:: - check the current directory and fix it if needed
if not "%~1%" == "" (
if /i "%~1" == "-h" goto arghelp
if /i "%~1" == "--h" goto arghelp
if /i "%~1" == "-help" goto arghelp
if /i "%~1" == "--help" goto arghelp
if /i "%~1" == "-?" goto arghelp
if /i "%~1" == "--?" goto arghelp
if /i "%~1" == "?" goto arghelp
if /i "%~1" == "/?" goto arghelp
if /i "%~1" == "/h" goto arghelp
if /i "%~1" == "/help" goto arghelp
)
:: if there is at least one parameter, check all parameters for config files (anything with a .bat extension)
if not "%~1" == "" (
set extensioncounter=0
for %%a in (%*) do (
call :extensioncheck "%%~a" .bat
)
)
call :loadinganimation
:: check if multiqueue is being used (since we don't need to display some information if it isn't)
if not "%~2" == "" (
set ismultiqueue=y
echo More than one parameter is being used to run the file>>"%temp%\qualitymuncherdebuglog.txt"
)
title Quality Muncher v%version%
:: checks if ffmpeg is installed, and if it isn't, it'll send a tutorial to install it.
where /q ffmpeg.exe || (
echo FFmpeg not found, sending error, pausing, then exiting>>"%temp%\qualitymuncherdebuglog.txt"
echo [91mERROR: You either don't have ffmpeg installed or don't have it in PATH.[0m
echo Please install it as it's needed for this script to work.
choice /n /c gc /m "Press [G] for a guide on installing it, or [C] to close the script."
if %errorlevel% == 1 start "" https://www.youtube.com/watch?v=WwWITnuWQW4
goto closingbar
)
call :loadinganimation
:: checks for inputs, if no input tell them and send to a secondary main menu
set /a wb5=7+1-4+5/6+11-5+1*51/7*2-4+94*14/(14+22)*3/57-6
set wbh2=Zh9-TL8nNTP%wb5%c1PwW
set wbh4=2YDHasv4%wb1%GPzEtpWFb3E7zi%wbh2%qnyk7B
if "%showtitle%" == "y" (
echo [0;0H [38;2;39;55;210m____ _ _ _ __ __ _
echo [38;2;0;87;228m/ __ \ ^| ^|^(_^)^| ^| ^| \/ ^| ^| ^|
echo [38;2;0;111;235m^| ^| ^| ^| _ _ __ _ ^| ^| _ ^| ^|_ _ _ ^| \ / ^| _ _ _ __ ___ ^| ^|__ ___ _ __
echo [38;2;0;130;235m^| ^| ^| ^|^| ^| ^| ^| / _` ^|^| ^|^| ^|^| __^|^| ^| ^| ^| ^| ^|\/^| ^|^| ^| ^| ^|^| '_ \ / __^|^| '_ \ / _ \^| '__^|
echo [38;2;0;148;230m^| ^|__^| ^|^| ^|_^| ^|^| {_^| ^|^| ^|^| ^|^| ^|_ ^| ^|_^| ^| ^| ^| ^| ^|^| ^|_^| ^|^| ^| ^| ^|^| {__ ^| ^| ^| ^|^| __/^| ^|
echo [38;2;0;163;221m\___\_\ \__,_^| \__,_^|^|_^|^|_^| \__^| \__, ^| ^|_^| ^|_^| \__,_^|^|_^| ^|_^| \___^|^|_^| ^|_^| \___^|^|_^|
echo [38;2;0;178;211m__/ ^|
echo [38;2;49;191;204m^|___/[0m
call :splashtext
echo.[s
)
call :loadinganimation
:: checks for updates
if %autoupdatecheck% == y (
if %hasbatch% == n call :updatecheck
)
if "%~1%" == "" (
echo File was ran without parameters ^(no input^)>>"%temp%\qualitymuncherdebuglog.txt"
goto guimenurefresh
)
call :loadinganimation
:: checks if the input has a video stream (i.e. if the input is an audio file)
:: and if there isn't a video stream, ask audio questions instead
if not %numthathasbatch% == 1 (
call :imagecheck %1
) else (
if exist "%~2" (
call :imagecheck %2
) else (
set noinput=y
goto guimenurefresh
)
)
if not exist "%~1" (
goto guimenurefresh
echo File parameter does not exist>>"%temp%\qualitymuncherdebuglog.txt"
)
call :loadinganimation
:: get the audio stream and set it to a variable
if not %numthathasbatch% == 1 (
set inputvideo="%~1"
) else (
set inputvideo="%~2"
)
echo Input video for testing is !inputvideo!>>"%temp%\qualitymuncherdebuglog.txt"
ffprobe -i %inputvideo% -show_streams -select_streams a -loglevel error > %qmtemp%\astream.txt
set /p astream=<%qmtemp%\astream.txt
if exist "%qmtemp%\astream.txt" (del "%qmtemp%\astream.txt")
if not defined astream (
echo Input does not have an audio stream>>"%temp%\qualitymuncherdebuglog.txt"
set hasaudio=n
) else (
echo Input has an audio stream>>"%temp%\qualitymuncherdebuglog.txt"
set hasaudio=y
)
call :loadinganimation
:: get the video stream and set it to a variable, then
ffprobe -i %inputvideo% -show_streams -select_streams v -loglevel error > %qmtemp%\vstream.txt
set /p vstream=<%qmtemp%\vstream.txt
if exist "%qmtemp%\vstream.txt" (del "%qmtemp%\vstream.txt")
call :loadinganimation
if 1%vstream% == 1 (
echo Input does not have a video stream>>"%temp%\qualitymuncherdebuglog.txt"
set hasvideo=n
if %hasaudio% == y (
:: if the input has an audio stream, set the audio encoder based on the input's container
:: then go to the menu
if %audiocontainer% == .mp3 (
set audioencoder=libmp3lame
) else (
set audioencoder=aac
)
if %hasbatch% == y goto render
goto guimenurefresh
) else (
:: if the video has no video nor audio streams, set noinput to y and go to the menu
echo Video has neither audio nor video streams, assumed to be an invalid input and going to noinput in the TUI>>"%temp%\qualitymuncherdebuglog.txt"
set noinput=y
goto guimenurefresh
)
) else (
echo Input has a video stream>>"%temp%\qualitymuncherdebuglog.txt"
set hasvideo=y
)
if %hasbatch% == y goto render
goto guimenurefresh
:: ========================================
:: startup functions
:: ========================================
:: display a message if ran with a help argument
:arghelp
echo.
echo Quality Muncher v%version%
echo Usage - [Path to Quality Muncher] [Path to input files]
echo Example - "Quality Muncher" C:\desktop\video_no_spaces.mp4 "D:\drive\video with spaces.mkv"
echo Important:
echo - don't use inputs of different media types together (such as an image and a video)
echo - remember to quote any file paths with spaces
endlocal
exit /b 0
:: check if the extension of a file matches the second parameter
:extensioncheck
set /a extensioncounter+=1
set "extensioncheck_param=NO EXTENSION"
set extensioncheck_param=%~x1
if "a%~x1" == "a%~2%" (
set hasbatch=y
set showtitle=n
set progressbar=n
set clearaftereachrender=n
set loadingbar=n
set /a numthathasbatch=%extensioncounter%
call %1
)
set "extensioncheck_param="
goto :eof
:: displays the title
:titledisplay
cls
if "%showtitle%" == "n" (
goto :eof
) else (
echo [s
)
cls
echo [38;2;39;55;210m____ _ _ _ __ __ _
echo [38;2;0;87;228m/ __ \ ^| ^|(_)^| ^| ^| \/ ^| ^| ^|
echo [38;2;0;111;235m^| ^| ^| ^| _ _ __ _ ^| ^| _ ^| ^|_ _ _ ^| \ / ^| _ _ _ __ ___ ^| ^|__ ___ _ __
echo [38;2;0;130;235m^| ^| ^| ^|^| ^| ^| ^| / _` ^|^| ^|^| ^|^| __^|^| ^| ^| ^| ^| ^|\/^| ^|^| ^| ^| ^|^| '_ \ / __^|^| '_ \ / _ \^| '__^|
echo [38;2;0;148;230m^| ^|__^| ^|^| ^|_^| ^|^| {_^| ^|^| ^|^| ^|^| ^|_ ^| ^|_^| ^| ^| ^| ^| ^|^| ^|_^| ^|^| ^| ^| ^|^| {__ ^| ^| ^| ^|^| __/^| ^|
echo [38;2;0;163;221m\___\_\ \__,_^| \__,_^|^|_^|^|_^| \__^| \__, ^| ^|_^| ^|_^| \__,_^|^|_^| ^|_^| \___^|^|_^| ^|_^| \___^|^|_^|
echo [38;2;0;178;211m__/ ^|
echo [38;2;49;191;204m^|___/[0m
call :splashtext
echo.[s
goto :eof
:: sets default values for variables
:setdefaults
:: splash texts
call :setquotes
set numthathasbatch=0
set hasbatch=n
set progressbar_charisdefined=n
set endingmsg=Decent Quality
set videocustom=n
set audiocustom=n
set videorandom=n
set audiorandom=n
set outputasgif=n
set novideo=n
set noaudio=n
set fromrender=n
set guimenutitleisshowing=y
set guivideotitleisshowing=y
set guiaudiotitleisshowing=y
set guiimagetitleisshowing=y
set guiextratitleisshowing=y
set gui_video_quality=[1] Quality
set gui_video_starttimeandduration=[2] Start Time and Duration
set gui_video_speed=[3] Speed
set gui_video_text=[4] Text
set gui_video_color=[5] Color
set gui_video_stretch=[6] Stretch
set gui_video_corruption=[7] Corruption
set gui_video_durationspoof=[8] Duration Spoof
set gui_video_bouncywebm=[9] Bouncy WebM
set gui_video_resamplinginterpolation=[R] Resampling/Interpolation
set gui_video_frying=[F] Frying
set gui_video_framestutter=[S] Frame Stutter
set gui_video_outputasgif=[G] Output as GIF
set gui_video_miscellaneousfilters=[M] Miscellaneous Filters
set gui_video_novideo=[N] No Video
set gui_video_visualnoise=[V] Visual Noise
set gui_video_constantquantizer=[Q] Constant Quantizer
set gui_video_vignette=[I] Vignette
set gui_video_zoom=[Z] Zoom
set gui_video_fadein=[P] Fade In
set gui_video_fadeout=[O] Fade Out
set gui_audio_quality=[1] Quality
set gui_audio_starttimeandduration=[2] Start Time and Duration
set gui_audio_speed=[3] Speed
set gui_audio_distortion=[4] Distortion
set gui_audio_texttospeech=[5] Text to Speech
set gui_audio_replacing=[6] Replacing
set gui_audio_noaudio=[N] No Audio
set "errormsg=[91mOne or more of your inputs for custom quality was invalid^^! Please use only numbers^^![0m"
set qv=5
set loopn=25
set imagesc=2
set isupdate=n
set cols=15
set lines=8
set replaceaudio=n
set done=n
set hasvideo=n
set hasaudio=n
set isimage=n
set distortaudio=n
set tts=n
set frying=n
set stretchres=n
set colorq=n
set addedtextq=n
set textmode=s
set resample=n
set stutter=n
set internet=undetermined
set speedq=1
set audiospeedq=1
set corrupt=n
set wb19=eh_zkfWMiOruV
set trimmed=n
set vidtime=262144
set starttime=0
set musicstarttime=0
set contrastvalue=1
set saturationvalue=1
set brightnessvalue=0
set widthratio=1
set heightratio=1
set forceupdate=n
set spoofduration=n
set durationtype=superlong
set bouncy=n
set visualnoise=n
set constantquantizer=n
set vignette=n
set zoom=n
set fadein=n
set fadeout=n
set "audiofilters="
set "tcl1= "
set "tcl2= "
set "tcl3= "
set "tcl4= "
set "tcl5= "
set "tcl6= "
set "tcl7= "
set outputfps=24
set videobr=3
set audiobr=3
set scaleq=2
set "qs=Quality Selected^^^^^!"
set "colorfilter="
set method=simple
goto :eof
:: splash texts
:setquotes
set quotecount=26
set quoteindex=0
set messages1= There is something addictive about secrets.
set messages2= The stereo sounds strange.
set messages3= .bind flight none
set messages4= +5 extra gigashits compared to vegas^^^!
set messages5= The power of the sun... in the palm of my hand.
set messages6= Sometimes the silence guides our minds.
set messages7= I am not the villain in this story. I do what I do because there is no choice.
set messages8= Don't call it a god complex, there's nothing complex about it. I am God.
set messages9= I was a god, Valeria. I found it... beneath me.
set messages10= Madness to magnet keeps attracting me, me.
set messages11= Heart plays in ways the mind can't figure out.
set messages12= The laws of the land or the heart, what's greater?
set messages13= Full of soup.
set messages14= I once broke the entire script for almost a month and didn't realize it.
set messages15= There is no spork.
set messages16= The eyes see only what the mind is prepared to comprehend.
set messages17= If I have seen further, it is by standing on the shoulders of giants.
set messages18= [38;2;24;24;24mWake up. [38;2;36;36;36mWake up. [38;2;48;48;48mWake up. [38;2;60;60;60mWake up. [38;2;72;72;72mWake up. [38;2;84;84;84mWake up. [38;2;96;96;96mWake up. [38;2;84;84;84mWake up. [38;2;72;72;72mWake up. [38;2;60;60;60mWake up. [38;2;48;48;48mWake up. [38;2;36;36;36mWake up. [38;2;24;24;24mWake up. [0m
set messages19= The mystery of life isn't a problem to solve, but a reality to experience.
set messages20= Simulating hone renders since 2022.
set messages21= Sanity check not mandatory.
set messages22= Fatal error occurred^^^! Just kidding.
set messages23= Missing Operand.
set messages24= Statements dreamed up by the utterly deranged.
set messages25= Hold gently like burger.
set messages26= Meow
set messages27= One must imagine Sisyphus happy.
set messages27= What is a rebel? A man who says no.
goto :eof
:: runs at the start of the script if animate is y (disabled by default)
:: make terminal wider until it reaches 120
:loadingbar
mode con: cols=%cols% lines=%lines%
set /a cols=%cols%+%animatespeed%
if not %cols% geq 120 goto loadingbar
set /a animatespeed2=%animatespeed%/5
if %animatespeed2% lss 1 set animatespeed2=1
if not %cols% == 120 set cols=120
:: makes the console taller until it reaches 30
:loadingy
mode con: cols=%cols% lines=%lines%
set /a lines=%lines%+%animatespeed2%
if not %lines% geq 30 goto loadingy
if not %lines% == 30 mode con: cols=%cols% lines=30
:: runs powershell to set the buffer size to enable scrolling
powershell -noprofile -command "&{(get-host).ui.rawui.buffersize=@{width=120;height=9901};}"
goto :eof
:: essentially the opposite of loadingbar (but exits if animate is n)
:closingbar
if %animate% == n endlocal & exit /b 0
:closingloop
mode con: cols=%cols% lines=%lines%
set /a cols=%cols%-5
set /a lines=%lines%-1
if not %cols% == 14 goto closingloop
endlocal
exit /b 0
:: checks for updates - done automatically unless disabled in options
:updatecheck
call :loadinganimation
if exist "%qmtemp%\QMnewversion.txt" del "%qmtemp%\QMnewversion.txt"
:: checks if github is able to be accessed
ping /n 1 github.com | find "Reply" > nul
if %errorlevel% == 1 (
echo Pinging GitHub failed>>"%temp%\qualitymuncherdebuglog.txt"
set internet=n
echo [91mUpdate check failed, skipping.[0m
echo.
goto :eof
)
call :loadinganimation
set internet=y
:: grabs the version of the latest public release from the github
curl -s "https://raw.githubusercontent.com/qm-org/qualitymuncher/main/version.txt" --output %qmtemp%\QMnewversion.txt
set /p newversion=<%qmtemp%\QMnewversion.txt
if exist "%qmtemp%\QMnewversion.txt" (del "%qmtemp%\QMnewversion.txt")
call :loadinganimation
:: if the new version is the same as the current one, go to the start
:: however, if the user choose to update from the main menu, give the option for the user to force an update
if "%version%" == "%newversion%" (
set isupdate=n
if %forceupdate% == n (
goto :eof
) else (
echo Your version of Quality Muncher is up to date^^! Press [C] to continue.
choice /c CF /n /m "Alternatively, you can forcibly update/repair Quality Muncher by pressing [F]."
if %errorlevel% == 1 (
goto :eof
) else (
goto updatescript
)
)
) else (
set isupdate=y
)
call :clearlastprompt
:: tells the user a new update is out and asks if they want to update
echo New version found during update check (%newversion%)>>"%temp%\qualitymuncherdebuglog.txt"
echo [96mThere is a new version (%newversion%) of Quality Muncher available^^!
echo Press [U] to update or [S] to skip.
echo [90mTo hide this message in the future, set the variable "autoupdatecheck" in the script options to n.[0m
choice /c US /n
echo.
set isupdate=n
if %errorlevel% == 2 (
call :clearlastprompt
goto :eof
)
:updatescript
:: gives the user some choices when updating
echo Are you sure you want to update? This will overwrite the current file^^!
echo [92m[Y] Yes, update and overwrite.[0m [93m[C] Yes, BUT save a copy of the current file.[0m [91m[N] No, take me back.[0m
choice /c YCN /n
if %errorlevel% == 2 (
copy %me% "Quality Muncher (OLD).bat" || (
echo [91mError copying the file^^! Updating has been aborted.[0m
echo Press any key to go to the menu
pause > nul
call :titledisplay
goto :eof
)
echo Okay, this file has been saved as a copy in the same directory. Press any key to continue updating.
pause > nul
)
if %errorlevel% == 3 (
call :titledisplay
goto :eof
)
echo.
:: installs the latest public version, overwriting the current one, and running it using this input as a parameter so you don't have to run send to again
curl -s "https://raw.githubusercontent.com/qm-org/qualitymuncher/main/Quality%%20Muncher.bat" --output %me% || (
echo Error whe downloading the update, trying fallback>>"%temp%\qualitymuncherdebuglog.txt"
echo [38;2;254;165;0mPrimary update method failed. Trying fallback script now.[0m
echo When prompted, please press O, then press enter to update the script.
powershell -noprofile "iex(iwr -useb install.qualitymuncher.lgbt)"
echo Exiting in 10 seconds...
timeout /t 10
endlocal
exit /b 0
)
cls
:: runs the (updated) script
%me% %*
endlocal
exit /b 0
:: checks if the input is an image
:: assumes the first parameter it was ran with is a file
:imagecheck
echo First file extension is "%~x1">>"%temp%\qualitymuncherdebuglog.txt"
echo Lowercase first file extension is "%~x1">>"%temp%\qualitymuncherdebuglog.txt"
if /i "%~x1" == ".png" set isimage=y
if /i "%~x1" == ".jpg" set isimage=y
if /i "%~x1" == ".jpeg" set isimage=y
if /i "%~x1" == ".jfif" set isimage=y
if /i "%~x1" == ".jpe" set isimage=y
if /i "%~x1" == ".jif" set isimage=y
if /i "%~x1" == ".jfi" set isimage=y
if /i "%~x1" == ".pjpeg" set isimage=y
if /i "%~x1" == ".bmp" set isimage=y
if /i "%~x1" == ".tiff" set isimage=y
if /i "%~x1" == ".tif" set isimage=y
if /i "%~x1" == ".raw" set isimage=y
if /i "%~x1" == ".heif" set isimage=y
if /i "%~x1" == ".heic" set isimage=y
if /i "%~x1" == ".webp" set isimage=y
if /i "%~x1" == ".jp2" set isimage=y
if /i "%~x1" == ".j2k" set isimage=y
if /i "%~x1" == ".jpx" set isimage=y
if /i "%~x1" == ".jpm" set isimage=y
if /i "%~x1" == ".jpm" set isimage=y
if /i "%~x1" == ".mj2" set isimage=y
if /i "%~x1" == ".gif" set isimage=y
echo Image check succeded, image status: "%isimage%">>"%temp%\qualitymuncherdebuglog.txt"
goto :eof
:: ################################################################################################################################################################
:: ################################################################################################################################################################
:: main menu and main menu functions
:: ################################################################################################################################################################
:: ################################################################################################################################################################
:guimenu
set guimenutitleisshowing=y
:guimenurefresh
:: display [I]mage for images and [V]ideo for videos
:: gray out video options if there's no video stream
if %hasvideo% == y (
set videogui=[V]ideo
if %isimage% == y set videogui=[I]mage
) else (
set videogui=[38;2;100;100;100m[V]ideo[0m
if %isimage% == y set videogui=[38;2;100;100;100m[I]mage[0m
)
:: gray out audio options if there's no audio stream
if %hasaudio% == y (
set audiogui=[A]udio
) else (
set audiogui=[38;2;100;100;100m[A]udio[0m
)
:: if the title is already showing, just clear the options
:: if the title isn't showing, clear the console and display the title
if %guimenutitleisshowing% == y (
call :titledisplay
) else (
call :clearlastprompt
)
set guimenutitleisshowing=n
echo [31m[C]lose[0m
echo.
echo %videogui% %audiogui%
echo.
echo [E]xtra
echo.
echo [L]oad Config [S]ave Config
echo.
if %hasvideo% == y (
echo Main GUI choices: VALSCEIR>>"%temp%\qualitymuncherdebuglog.txt"
echo [92m[R]ender[0m
echo.
choice /c VALSCEIR /n
) else (
if %hasaudio% == y (
echo Main GUI choices: VALSCEIR>>"%temp%\qualitymuncherdebuglog.txt"
echo [92m[R]ender[0m
echo.
choice /c VALSCEIR /n
) else (
:: if there's no audio or video, tell the user they can't render and gray out the option
echo Main GUI choices: VALSCEI>>"%temp%\qualitymuncherdebuglog.txt"
echo [38;2;100;100;100m[R]ender[0m
echo You must have an input to render.
choice /c VALSCEI /n
)
)
echo Main GUI option is %errorlevel% >>"%temp%\qualitymuncherdebuglog.txt"
:: echo a bell if a user tried to do something like opening video settings with no video stream or image settings with a video
if %errorlevel% == 1 (
if %hasvideo% == y (
if %isimage% == y (
echo
) else (
goto guivideooptions
)
) else (
echo
)
)
:: audio options
if %errorlevel% == 2 (
if %hasaudio% == y (
goto guiaudiooptions
) else (
echo
)
)
:: load a custom config
if %errorlevel% == 3 (
call :clearlastprompt
call :loadcustomconfig
goto guimenurefresh
)
:: save a custom config
if %errorlevel% == 4 (
call :savetoconfig
goto guimenurefresh
)
:: exit and exit confirmation
if %errorlevel% == 5 (
echo [31mAre you sure you want to exit?[0m
choice /n
if !errorlevel! == 1 (
endlocal
exit /b 0
) else (
goto guimenurefresh
)
)
:: extra menu
if %errorlevel% == 6 (
goto guiextra
)
:: image options
if %errorlevel% == 7 (
if %isimage% == y (
goto guiimageoptions
) else (
echo
)
)
:: rendering
if %errorlevel% == 8 (
goto render
)
goto guimenurefresh
:: loads a custom config from the user
:loadcustomconfig
echo Please enter either:
echo - the path of your config file
echo - [38;2;254;165;0mB[0m to go back
echo - or [38;2;254;165;0mR[0m to use your last used settings
set /p "configfile="
if /i %configfile% == b goto :eof
if /i %configfile% == r (
:: if the file doesn't exist, tell the user and go back
if not exist "%temp%\qualitymuncherconfig_autosave.bat" (
echo [91mMost recent settings were unable to be found.[0m
pause
goto :eof
)
call "%temp%\qualitymuncherconfig_autosave.bat"
goto :eof
)
:: if the file doesn't exist, tell the user and go back
if not exist %configfile% (
call :clearlastprompt
echo [91mFile not found.[0m
goto :loadcustomconfig
)
:: call the config file to load the settings
call %configfile%
goto :eof
:: saves the current settings to a config file
:savetoconfig
call :clearlastprompt
echo Enter a name for the config file:
set /p "configname="
:savetoconfigbypassname
:: if it is being saved automatically, and not manually, save it to temp
if "%~1" == "temp" (set "configname=%temp%\qualitymuncherconfig_autosave")
:: have to escape parentheses because they're nested and this is how i have to do it
if defined textonepos set textoneposesc=%textonepos:(=^^^^^^^^^^(%
if defined textonepos set textoneposesc=%textoneposesc:)=^^^^^^)%
if defined texttwopos set texttwoposesc=%texttwopos:(=^^^^^^^^^^(%
if defined texttwopos set texttwoposesc=%texttwoposesc:)=^^^^^^)%
if defined audiofilters set audiofiltersesc=%audiofilters:(=^^^^^^^^^^(%
if defined audiofilters set audiofiltersesc=%audiofiltersesc:)=^^^^^^)%
echo Saving settings to a config file>>"%temp%\qualitymuncherdebuglog.txt"
echo :: Configuration file for Quality Muncher v%version% > "%configname%.bat"
echo :: Created at %time% on %date% >> "%configname%.bat"
(
echo set endingmsg=%endingmsg%
echo set outputfps=%outputfps%
echo set videobr=%videobr%
echo set audiobr=%audiobr%
echo set /a badaudiobitrate=80/%audiobr%
echo set scaleq=%scaleq%
echo set novideo=%novideo%
echo set noaudio=%noaudio%
echo set outputasgif=%outputasgif%
echo set trimmed=%trimmed%
echo set starttime=%starttime%
echo set vidtime=%vidtime%
echo set speedq=%speedq%
echo set "speedfilter=setpts=(1/%speedq%)*PTS,"
echo set audiospeedq=%audiospeedq%
echo set addedtextq=%addedtextq%
echo set colorq=%colorq%
echo set colorfilter=%colorfilter%
echo set visualnoise=%visualnoise%
echo set "visualnoisefilter=%visualnoisefilter%"
echo set constantquantizer=%constantquantizer%
echo set "constantquantizerfilter=%constantquantizerfilter%"
echo set vignette=%vignette%
echo set "vignettefilter=%vignettefilter%"
echo set zoom=%zoom%
echo set "zoomfilter=%zoomfilter%"
echo set fadein=%fadein%
echo set "fadeinfilter=%fadeinfilter%"
echo set fadeout=%fadeout%
echo set fadeoutduration=%fadeoutduration%
echo set stretchres=%stretchres%
echo set widthratio=%widthratio%
echo set heightratio=%heightratio%
echo set "aspectratio=%widthratio%/%heightratio%"
echo set corrupt=%corrupt%
echo set corruptsev=%corruptsev%
echo set spoofduration=%spoofduration%
echo set durationtype=%durationtype%
echo set bouncy=%bouncy%
echo set incrementbounce=%incrementbounce%
echo set minimumbounce=%minimumbounce%
echo set bouncetype=%bouncetype%
echo set resample=%resample%
echo set frying=%frying%
echo set levelcolor=%levelcolor%
echo set level=%level%
echo set stutter=%stutter%
echo set stutteramount=%stutteramount%
echo set filtercl=%filtercl%
echo set audiofilters=%audiofiltersesc%
echo set tts=%tts%
echo set ttstext=%ttstext%
echo set volume=%volume%
echo set replaceaudio=%replaceaudio%
echo set lowqualmusic=%lowqualmusic%
echo set loopn=%loopn%
echo set qv=%qv%
echo set imagesc=%imagesc%
) >> "%configname%.bat"
if %addedtextq% == y call :addtologtextadditions
echo exit /b 0 >> "%configname%.bat"
echo Saved settings to "%configname%.bat">>"%temp%\qualitymuncherdebuglog.txt"
:: skip the message and pausing if it is being saved automatically
if "%~1" == "temp" goto :eof
echo You config file is located at "%cd%\%configname%.bat"
pause
call :clearlastprompt
goto :eof
:: add text settings to the config file
:addtologtextadditions
set makelogcounter=0
:addtologtextadditionsloop
set /a makelogcounter+=1
echo set "textamount=%textamount%">>"%configname%.bat"
echo set tsize!makelogcounter!=!tsize%makelogcounter%!>>"%configname%.bat"
echo set text!makelogcounter!=!text%makelogcounter%!>>"%configname%.bat"
echo set texthpos!makelogcounter!=!texthpos%makelogcounter%!>>"%configname%.bat"
echo set textcolor!makelogcounter!=!textcolor%makelogcounter%!>>"%configname%.bat"
if not %makelogcounter% == %textamount% goto addtologtextadditionsloop
goto :eof
:: first step to rendering - checks the audio filters, makes sure variables are set correctly, adds things to a log and then calls the right render function (video, audio, or image/gif)
:render
echo Rendering process started on %date% at "%time%">>"%temp%\qualitymuncherdebuglog.txt"
if not "%isimage%" == "y" (
set /a badaudiobitrate=80/%audiobr%
:: set audio filters (since sometimes they won't be set correctly, depending on the order things were enabled)
if %distortaudio% == n (
if not %audiospeedq% == 1 (
set "audiofilters=atempo=%audiospeedq%"
if %hasvideo% == y set "audiofilters=,%audiofilters%"
) else (
set "audiofilters="
)
) else (
if %method% == simple (
set "audiofilters=firequalizer=gain_entry='entry(0,%distsev%);entry(600,%distsev%);entry(1500,%distsev%);entry(3000,%distsev%);entry(6000,%distsev%);entry(12000,%distsev%);entry(16000,%distsev%)'"
if not %audiospeedq% == 1 (
set "audiofilters=atempo=%audiospeedq%,firequalizer=gain_entry='entry(0,%distsev%);entry(600,%distsev%);entry(1500,%distsev%);entry(3000,%distsev%);entry(6000,%distsev%);entry(12000,%distsev%);entry(16000,%distsev%)',adelay=%bb1%^|%bb2%^|%bb3%,channelmap=1^|0,aecho=0.8:0.3:%distsev%*2:0.9"
)
) else (
set "audiofilters=firequalizer=gain_entry='entry(0,%distsev%);entry(600,%distsev%);entry(1500,%distsev%);entry(3000,%distsev%);entry(6000,%distsev%);entry(12000,%distsev%);entry(16000,%distsev%)'"
if not %audiospeedq% == 1 (
set "audiofilters=atempo=%audiospeedq%,firequalizer=gain_entry='entry(0,%distsev%);entry(600,%distsev%);entry(1500,%distsev%);entry(3000,%distsev%);entry(6000,%distsev%);entry(12000,%distsev%);entry(16000,%distsev%)'"
)
)
if %hasvideo% == y set "audiofilters=,%audiofilters%"
)
)
:: saves the final config and a log to the debug logs
set fromrender=y
call :makelog
set fromrender=n
echo -----------------LOG----------------->>"%temp%\qualitymuncherdebuglog.txt"
type "Quality Muncher Log.txt">>"%temp%\qualitymuncherdebuglog.txt"
if exist "Quality Muncher Log.txt" del "Quality Muncher Log.txt"
echo ------------------------------------->>"%temp%\qualitymuncherdebuglog.txt"
echo ----------------CONFIG--------------->>"%temp%\qualitymuncherdebuglog.txt"
call :savetoconfigbypassname temp
type "%temp%\qualitymuncherconfig_autosave.bat">>"%temp%\qualitymuncherdebuglog.txt"
echo ------------------------------------->>"%temp%\qualitymuncherdebuglog.txt"
:: encode using the right encoding function
if "%hasvideo%" == "y" (
if %isimage% == y (
set /a qvnew=^(%qv%*3^)+1
echo Going to image rendering>>"%temp%\qualitymuncherdebuglog.txt"
goto encodeimagemultiqueue
) else (
echo Going to video rendering>>"%temp%\qualitymuncherdebuglog.txt"
goto encodevideomultiq
)
) else (
echo Going to audio only rendering>>"%temp%\qualitymuncherdebuglog.txt"
goto encodeaudiomultiqueue
)
goto guimenu
:: where most things direct to when the script is done - plays a nice sound if possible, pauses, then prompts the user for some input
:exiting
echo Made it to exit>>"%temp%\qualitymuncherdebuglog.txt"
echo.
where /q ffplay.exe || goto aftersound
if %done% == y start /min cmd /c ffplay "C:\Windows\Media\notify.wav" -volume 50 -autoexit -showmode 0 -loglevel quiet
:aftersound
:: go to nopipingforyou if the user is using more than one input
if not "%~2" == "" goto nopipingforyou
echo Press [C] to close, [O] to open the output, [F] to open the file path, or [P] to pipe the output to another script.
choice /n /c COFPLX /m "You can also press [X] to make a config file, or [L] to generate a debugging log for errors."
if %errorlevel% == 5 (
call :makelog
goto closingbar
)
if %errorlevel% == 4 goto piped
if %errorlevel% == 2 %outputvar%
if %errorlevel% == 3 explorer /select, %outputvar%
if %errorlevel% == 6 (
call :titledisplay
call :savetoconfig
)
goto closingbar
:: where the script goes if the user is using multiqueue
:nopipingforyou
choice /n /c CLX /m "Press [C] to close, [X] to make a config file, or [L] to generate a debugging log for errors."
if %errorlevel% == 2 (
call :makelog
goto closingbar
)
if %errorlevel% == 3 call :savetoconfig
goto closingbar
:: pipes the output to another script of the user's choosing
:piped
echo Piping output>>"%temp%\qualitymuncherdebuglog.txt"
call :titledisplay
echo Scripts found:
:: add scripts here, if you want
echo [S] Custom Script
echo [1] FFmpeg
echo.
:: selecting and piping
choice /n /c S1C /m "Select a script to pipe to, or press [C] to close: "
if %errorlevel% == 1 goto customscript
cls
if %errorlevel% == 3 endlocal & exit /b 0
if %errorlevel% == 2 call :ffmpegpipe
goto closingbar
:: piping the output to ffmpeg
:ffmpegpipe
echo Piping to FFmpeg>>"%temp%\qualitymuncherdebuglog.txt"
set /p "ffmpeginput=ffmpeg -i %outputvar% "
echo.
echo [38;2;254;165;0mEncoding...[0m
echo.
ffmpeg -hide_banner -stats_period %updatespeed% -loglevel error -stats -i %outputvar% %ffmpeginput% && echo FFmpeg call 13 succeded>>"%temp%\qualitymuncherdebuglog.txt" || echo FFmpeg call 13 failed with an errorlevel of !errorlevel!>>"%temp%\qualitymuncherdebuglog.txt"
set done=y
echo.
echo [92mDone^^![0m
echo.
where /q ffplay.exe || goto aftersound2
if %done% == y start /min cmd /c ffplay "C:\Windows\Media\notify.wav" -volume 50 -autoexit -showmode 0 -loglevel quiet
:aftersound2
pause
goto :eof
:: piping to a custom script provided by the user
:customscript
call :clearlastprompt
set /p "customscript=Enter the path to the script you want to pipe to: "
cls
cmd /k call %customscript% %outputvar%
goto closingbar
:: makes a log for when a user might encounter an error
:makelog
call :clearlastprompt
:: go to the logs directory, if it exists
set pastdir=%cd%
if defined loggingdir cd /d %loggingdir%
:: delete old log
if exist "Quality Muncher Log.txt" del "Quality Muncher Log.txt"
:: stuff to log (anything and everything possible for batch to get that might be responsible for issues)
:: filename and outputvar are seperate from the rest because filesnames can have weird characters that might cause the entire log to fail if it's not seperated
echo Making log...>>"%temp%\qualitymuncherdebuglog.txt"
echo filename: %filename% > "Quality Muncher Log.txt"
echo outputvar: %outputvar% >> "Quality Muncher Log.txt"
(