Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @echo off
- REM Title: WebM Audio Albulm Art Batch Script
- REM Author: VP8M8
- REM Version: v0.4
- REM Date: 7/20/2015
- REM How to use: Drag an audio file onto this batch file to start
- REM It's a mess, but the important stuff works for now. I tried but it wasted too much of my time.
- REM Current Bugs:
- REM *Detect if image file exists
- REM *Title/Artist code doesn't work anymore?
- REM *Adaptively lowering the audio bitrate to compensate for the video stream
- REM *Adaptively scaling the video based on input image size and user set threshold
- REM To Do List in Priority Order:
- REM *Fix bugs
- REM ***** EDIT THE LINES BELOW TO POINT TO THE LOCATION OF YOUR COPY OF FFMPEG AND FFPROBE *****
- set ffmpeg=C:\Users\Anon\Documents\ffmpeg-20150517-git-2acc065-win64-static\bin\ffmpeg.exe
- set ffprobe=C:\Users\Anon\Documents\ffmpeg-20150517-git-2acc065-win64-static\bin\ffprobe.exe
- :beginning
- REM *********** Get song duration ***********
- for /f %%x in ('%ffprobe% %1 -loglevel quiet -show_format -show_streams ^| findstr "="') do set %%x
- set /a length=%duration%
- echo ___/WebM Audio Albulm Art Batch Script\___
- echo Press ENTER to choose the default
- echo.
- :imageError
- if [%noimage%] EQU [1] echo.&echo Error! No file selected.
- set/a noimage=0
- REM *********** Get image file **************
- set /p image="Please drag and drop the image file you want to use here and press ENTER: "
- if [%image%]==[] @set /a noimage=1
- if [%noimage%] EQU [1] goto :imageError
- echo The image is %image%
- echo.
- REM ********** Get title (was working at one point) ****************
- set /p titlenew="What should be the title? (Default is auto detect Title - Artist): "
- if [%titlenew%]==[] @set title=%TITLE% - %ARTIST%
- echo title is: %TITLE%
- echo artist is: %ARTIST%
- echo The title is: "%titlenew%"
- echo.
- REM *********** Set file name because Title/Artist code is unreliable ***********
- REM # Sets output file name to input audio file name. Optimally should be Title - Artist when it's fixed.
- set name=%~n1
- REM ********* Get file size ****************
- set /p megabyteinput="How big should the WebM be in MB? (Default is 8): "
- if [%megabyteinput%]==[] @set /a megabyte=8
- set /a megabyte=%megabyteinput%
- echo The WebM file size is %megabyte%MB
- echo.
- REM *********** Adjust bitrate ***********
- 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 ***
- REM *** Not really working, there's still some of my debuging code leftover ***
- set /a offset=15
- REM if %length% LEQ 240 (
- REM @set /a offsetmode=1&@set /a offset=%length% / 10 - 2
- REM )
- REM if %lenglth% LEQ 360 (
- REM @set /a offsetmode=2&@set /a offset=%length% / 10 - 10
- REM )
- REM if %lenglth% GTR 360 (
- REM @set /a offsetmode=3&@set /a offset=%length% / 10 - 20
- REM )
- REM if %offset% LEQ 0 @set /a offset=5$@set /a offsetmode=4
- set /a calculatedbitrate=%megabyte% * 8 * 1024 * 1024 / 1000 / %length% - %offset%
- REM # Catch if audio bitrate is over the max of 512.
- if %calculatedbitrate% GTR 512 @set /a calculatedbitrate=512
- echo The calculated bitrate is :%calculatedbitrate%kbps
- REM echo The offset mode is: %offsetmode%
- echo.
- REM ************* Get audio bitrate ***************
- set /p audiobitrateinput="What should be the audio bitrate in kbps? (Default *recommended* is auto calculated): "
- set /a audiobitrate=%audiobitrateinput%
- if [%audiobitrateinput%]==[] @set audiobitrate=%calculatedbitrate%
- echo The audio bitrate is %audiobitrate%kbps
- echo.
- REM *** Tries to automatically scale the image down if it's over a set height. I used 800p ***
- REM *** Logic broken due to alphabetical number comparison. It wasn't worth any more of my time to try to hack around it ***
- REM *** You can't even compare two numbers correctly in a batch script ***
- 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 ***
- REM for /f %%x in ('%ffprobe% %image% -loglevel quiet -show_streams ^| findstr "="') do set %%x
- REM set /a heightimg=%height%
- REM echo Original image height: %heightimg%
- REM set /a heightset=800
- REM set /a heightTest=%heightimg% - %heightset%
- REM echo The heightTest is :%heightTest%
- REM if heightTest GTR 0 (
- REM echo heightTest greater than 0!&@set heightimg=%heightset%
- REM ) else (
- REM @set heightimg=-1
- REM )
- REM Old logic
- REM if [%heightnew%] GEQ [%heightset%] (
- REM @set heightnew=800
- REM ) else (
- REM @set heightnew=-1
- REM )
- REM echo height :%height%
- REM echo heightimg :%heightimg%
- REM pause
- REM # Sets video size manually. Used as a placeholder until the auto resize part is done.
- set /p heightimginput="What should be the height? (Default is input height): "
- set /a heightimg=%heightimginput%
- if [%heightimg%]==[] @set /a heightimg=-1
- echo The scaled height is %heightimg%
- %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"
- cls
- echo Finished Encoding!
- pause
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement