Advertisement
VP8M8

WebM Audio Albulm Art Batch Script

Jul 20th, 2015
448
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.11 KB | None | 0 0
  1. @echo off
  2. REM Title: WebM Audio Albulm Art Batch Script
  3. REM Author: VP8M8
  4. REM Version: v0.4
  5. REM Date: 7/20/2015
  6. REM How to use: Drag an audio file onto this batch file to start
  7.  
  8. REM It's a mess, but the important stuff works for now. I tried but it wasted too much of my time.
  9.  
  10. REM Current Bugs:
  11. REM *Detect if image file exists
  12. REM *Title/Artist code doesn't work anymore?
  13. REM *Adaptively lowering the audio bitrate to compensate for the video stream
  14. REM *Adaptively scaling the video based on input image size and user set threshold
  15. REM To Do List in Priority Order:
  16. REM *Fix bugs
  17.  
  18. REM ***** EDIT THE LINES BELOW TO POINT TO THE LOCATION OF YOUR COPY OF FFMPEG AND FFPROBE *****
  19.  
  20. set ffmpeg=C:\Users\Anon\Documents\ffmpeg-20150517-git-2acc065-win64-static\bin\ffmpeg.exe
  21. set ffprobe=C:\Users\Anon\Documents\ffmpeg-20150517-git-2acc065-win64-static\bin\ffprobe.exe
  22.  
  23. :beginning
  24. REM *********** Get song duration ***********
  25.  
  26. for /f %%x in ('%ffprobe% %1 -loglevel quiet -show_format -show_streams ^| findstr "="') do set %%x
  27. set /a length=%duration%
  28.  
  29. echo ___/WebM Audio Albulm Art Batch Script\___
  30. echo Press ENTER to choose the default
  31. echo.
  32.  
  33. :imageError
  34. if [%noimage%] EQU [1] echo.&echo Error! No file selected.
  35. set/a noimage=0
  36.  
  37. REM *********** Get image file **************
  38. set /p image="Please drag and drop the image file you want to use here and press ENTER: "
  39. if [%image%]==[] @set /a noimage=1
  40. if [%noimage%] EQU [1] goto :imageError
  41. echo The image is %image%
  42. echo.
  43.  
  44. REM ********** Get title (was working at one point) ****************
  45. set /p titlenew="What should be the title? (Default is auto detect Title - Artist): "
  46. if [%titlenew%]==[] @set title=%TITLE% - %ARTIST%
  47. echo title is: %TITLE%
  48. echo artist is: %ARTIST%
  49. echo The title is: "%titlenew%"
  50. echo.
  51.  
  52. REM *********** Set file name because Title/Artist code is unreliable ***********
  53. REM # Sets output file name to input audio file name. Optimally should be Title - Artist when it's fixed.
  54. set name=%~n1
  55.  
  56. REM ********* Get file size ****************
  57. set /p megabyteinput="How big should the WebM be in MB? (Default is 8): "
  58. if [%megabyteinput%]==[] @set /a megabyte=8
  59. set /a megabyte=%megabyteinput%
  60. echo The WebM file size is %megabyte%MB
  61. echo.
  62.  
  63. REM *********** Adjust bitrate ***********
  64. REM *** Atempting to offset the audio bitrate calculation to make room for the video stream by subtracting bitrate based on the length of the song ***
  65. REM *** Not really working, there's still some of my debuging code leftover ***
  66.  
  67. set /a offset=15
  68. REM if %length% LEQ 240 (
  69. REM @set /a offsetmode=1&@set /a offset=%length% / 10 - 2
  70. REM )
  71.  
  72. REM if %lenglth% LEQ 360 (
  73. REM @set /a offsetmode=2&@set /a offset=%length% / 10 - 10
  74. REM )
  75.  
  76. REM if %lenglth% GTR 360 (
  77. REM @set /a offsetmode=3&@set /a offset=%length% / 10 - 20
  78. REM )
  79.  
  80. REM if %offset% LEQ 0 @set /a offset=5$@set /a offsetmode=4
  81. set /a calculatedbitrate=%megabyte% * 8 * 1024 * 1024 / 1000 / %length% - %offset%
  82. REM # Catch if audio bitrate is over the max of 512.
  83. if %calculatedbitrate% GTR 512 @set /a calculatedbitrate=512
  84. echo The calculated bitrate is :%calculatedbitrate%kbps
  85. REM echo The offset mode is: %offsetmode%
  86. echo.
  87.  
  88. REM ************* Get audio bitrate ***************
  89. set /p audiobitrateinput="What should be the audio bitrate in kbps? (Default *recommended* is auto calculated): "
  90. set /a audiobitrate=%audiobitrateinput%
  91. if [%audiobitrateinput%]==[] @set audiobitrate=%calculatedbitrate%
  92. echo The audio bitrate is %audiobitrate%kbps
  93. echo.
  94.  
  95. REM *** Tries to automatically scale the image down if it's over a set height. I used 800p ***
  96. REM *** Logic broken due to alphabetical number comparison. It wasn't worth any more of my time to try to hack around it ***
  97. REM *** You can't even compare two numbers correctly in a batch script ***
  98. REM *** I tried to check for a negative but it still doesn't work. It scales all images to 800p but detects whether it should or shouldn't ***
  99.  
  100. REM for /f %%x in ('%ffprobe% %image% -loglevel quiet -show_streams ^| findstr "="') do set %%x
  101.  
  102. REM set /a heightimg=%height%
  103. REM echo Original image height: %heightimg%
  104.  
  105. REM set /a heightset=800
  106.  
  107. REM set /a heightTest=%heightimg% - %heightset%
  108. REM echo The heightTest is :%heightTest%
  109.  
  110. REM if heightTest GTR 0 (
  111. REM echo heightTest greater than 0!&@set heightimg=%heightset%
  112. REM ) else (
  113. REM @set heightimg=-1
  114. REM )
  115.  
  116. REM Old logic
  117. REM if [%heightnew%] GEQ [%heightset%] (
  118. REM @set heightnew=800
  119. REM ) else (
  120. REM @set heightnew=-1
  121. REM )
  122.  
  123. REM echo height :%height%
  124. REM echo heightimg :%heightimg%
  125. REM pause
  126.  
  127. REM # Sets video size manually. Used as a placeholder until the auto resize part is done.
  128. set /p heightimginput="What should be the height? (Default is input height): "
  129. set /a heightimg=%heightimginput%
  130. if [%heightimg%]==[] @set /a heightimg=-1
  131. echo The scaled height is %heightimg%
  132.  
  133. %ffmpeg% -i %1 -r 1 -loop 1 -i %image% -y -c:v libvpx -g 9999 -crf 20 -b:v 0 -c:a libopus -b:a %audiobitrate%k -ac 2 -shortest -vf scale=-1:%heightimg% -sws_flags lanczos -threads 1 -metadata title="%titlenew%" "%name%.webm"
  134.  
  135. cls
  136. echo Finished Encoding!
  137. pause
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement