REM Make a copy of this batch file before modifying. SetLocal EnableDelayedExpansion @echo on REM When a podcast cover file (bc###.png) is passed to this script, a series of thumbnail files for YouTube are created, each one smaller, until one that is under 2 gigabytes that YouTube will accept, is generated. REM The thumbnail image files are saved in this folder: C:\Users\livec\Downloads\ If Not Exist "%1" Then (Choice /m "File does not exist. Press Ctrl+C") Title %~nx1 For /l %%i In (1280, -100, 1000) Do ( REM Echo %%i C:\ffmpeg\ffmpeg -y -i "%~dp1%~nx1" -vf scale=%%i:%%i "C:\Users\livec\Downloads\%~n1_%%ix%%i.png" Set n="C:\Users\livec\Downloads\%~n1_%%ix%%i.png" REM Echo n = !n! for %%f in (!n!) do ( Set /a FileSize=%%~zf Echo %%~nxf FileSize = %FileSize% If !FileSize! LEQ 2097152 ( GoTo FileLessThan2Megabytes ) ) ) :FileLessThan2Megabytes rundll32.exe cmdext.dll,MessageBeepStub rundll32 user32.dll,MessageBeep Choice /d N /t 99 EndLocal
Thursday, September 4
Iterate.bat
ConvertAudioForYouTube.bat
REM Make a copy of this batch file before modifying.
@echo on
Setlocal enableDelayedExpansion
REM An MP3 audio file passed to this script will be converted into an MP4 file with randomly selected static images for uploading to YouTube. These are not true MP4 files, so they can only be played with VLC, but YouTube recognizes them, and converts them to their own formats in very high quality.
REM A 1280x1280 thumbnail file of the cover art for uploading to YouTube is also generated. Sometimes, these files are larger than 2 megabytes, which YouTube will not accept. When that happens, pass the cover file (bc###.png) to the Interate.bat script to generate successively smaller thumbnail files until one is created that is slightly smaller than 2 megabytes.
Set /a MinFileVal = 119
Set /a MaxFileVal = 159
Set /a MinDurationVal = 14
Set /a MaxDurationVal = 19
REM Set /a AudioFileDurationInSeconds = 9999
For /f %%a in ('C:\MediaInfo\MediaInfo.exe --Inform^=General^;%%Duration%% ^"%~1^"') Do Set /a AudioFileDurationInMilliseconds=%%a
Echo AudioFileDurationInMilliseconds = %AudioFileDurationInMilliseconds%
Set /a AudioFileDurationInSeconds = AudioFileDurationInMilliseconds / 1000
Echo AudioFileDurationInSeconds = %AudioFileDurationInSeconds%
Copy nul "C:\Users\livec\Downloads\Images.txt" > nul
Echo file 'F:\Podcast\%~n1.png' >> "C:\Users\livec\Downloads\Images.txt"
Echo duration 5 >> "C:\Users\livec\Downloads\Images.txt"
Echo Filling Images.txt file with timestamps.
Set /a RunningTimeInSeconds = 0
Set /a RndDurationVal = 0
Set /a MaxIterations = AudioFileDurationInSeconds / MinDurationVal
FOR /L %%i in (0,1,%MaxIterations%) do (
If !RunningTimeInSeconds! GEQ !AudioFileDurationInSeconds! (
GoTo :ImagesFileFilled
)
Set /a CountDown = AudioFileDurationInSeconds - RunningTimeInSeconds
Title !CountDown!
Set /a RndFileVal = "!RANDOM! * (!MaxFileVal! - !MinFileVal! + 1) / 32768 + !MinFileVal!"
set "PaddedVal=0000000000!RndFileVal!"
set "FormattedVal=bc!PaddedVal:~-3!.png"
echo file 'F:\Podcast\!FormattedVal!' >> "C:\Users\livec\Downloads\Images.txt"
Set /a RndDurationVal = "!RANDOM! * (!MaxDurationVal! - !MinDurationVal! + 1) / 32768 + !MinDurationVal!"
Echo duration !RndDurationVal! >> "C:\Users\livec\Downloads\Images.txt"
Set /a RunningTimeInSeconds = RunningTimeInSeconds + RndDurationVal
REM Echo "Running Seconds: !RunningTimeInSeconds!" >> "C:\Users\livec\Downloads\Images.txt"
)
:ImagesFileFilled
Title %0
REM Due to a quirk, the last image has to be specified twice - the 2nd time without any duration directive
echo file 'F:\Podcast\!FormattedVal!' >> "C:\Users\livec\Downloads\Images.txt"
Type "C:\Users\livec\Downloads\Images.txt"
c:\ffmpeg\ffmpeg.exe -y -i "%~d1%~p1%~n1.png" -vf scale=1280:1280 "%~d1%~p1%~n1_1280x1280.png"
c:\ffmpeg\ffmpeg.exe -safe 0 -y -f concat -i "C:\Users\livec\Downloads\Images.txt" -i "%~1" -i "F:\Podcast\%~n1.vtt" -c:s mov_text -metadata:s:s:0 language=eng -c:a copy -c:v copy -t 9999 -r 30 -movflags faststart "%~d1%~p1%~n1.mp4"
rundll32.exe cmdext.dll,MessageBeepStub
rundll32 user32.dll,MessageBeep
timeout /t 999
endlocal
ConvertVideoForMastodon.bat
REM Make a copy of this batch file before modifying.
Setlocal EnableDelayedExpansion
rem Convert video into a file size acceptable in a Mastodon post.
Set /a MaxFileSizeInMegaBytes = 98
Title %MaxFileSizeInMegaBytes% MG Conversion
Echo MaxFileSizeInMegaBytes = %MaxFileSizeInMegaBytes%
Set /a AudioBitRateInKiloBits = 128
Echo AudioBitRateInKiloBits = %AudioBitRateInKiloBits%
Set /a MaxFileSizeInKiloBytes = MaxFileSizeInMegaBytes * 1000
Echo MaxFileSizeInKiloBytes = %MaxFileSizeInKiloBytes%
Set /a FileSizeInBytes = 0
Set /a FileSizeInBytes = %~z1
Echo FileSizeInBytes = %FileSizeInBytes%
Set /a FileSizeInKiloBytes = FileSizeInBytes / 1024
Echo FileSizeInKiloBytes = %FileSizeInKiloBytes%
If %FileSizeInKiloBytes% EQU 0 (
Echo File size is too large to fit in 32 bit variable
Set /a FileSizeInKiloBytes = MaxFileSizeInKiloBytes + 1
)
If %FileSizeInKiloBytes% LEQ %MaxFileSizeInKiloBytes% (
Echo %~1
Echo File is already smaller than %MaxFileSizeInMegaBytes% megabytes.
Choice /c y /t 999 /d y /m "Press Y to exit."
Endlocal
Exit
)
For /f %%a in ('C:\MediaInfo\MediaInfo.exe --Inform^=General^;%%Duration%% ^"%~1^"') Do Set /a DurationInMilliseconds=%%a
Echo DurationInMilliseconds = %DurationInMilliseconds%
Set /a DurationInSeconds = DurationInMilliseconds / 1000
Echo DurationInSeconds = %DurationInSeconds%
Set /a CenterTimeInSeconds = DurationInSeconds / 2
Echo CenterTimeInSeconds = %CenterTimeInSeconds%
c:\ffmpeg\ffmpeg.exe -ss %CenterTimeInSeconds% -i "%~1" -frames:v 1 -y "%~d1%~p1%~n1_Thumbnail.png"
Set /a MaxFileSizeInMegaBits = 8388 * MaxFileSizeInMegaBytes
Echo MaxFileSizeInMegaBits = %MaxFileSizeInMegaBits%
Set /a TotalBitRateInKiloBits = MaxFileSizeInMegaBits / DurationInSeconds
Echo TotalBitRateInKiloBits = %TotalBitRateInKiloBits%
Set /a TargetBitRateInKiloBits = TotalBitRateInKiloBits - AudioBitRateInKiloBits
Echo TargetBitRateInKiloBits = %TargetBitRateInKiloBits%
If %TargetBitRateInKiloBits% LEQ 0 (
Echo %~1
Echo File is too large to convert.
Choice /c y /t 999 /d y /m "Press Y to exit."
Endlocal
Exit
)
c:\ffmpeg\ffmpeg.exe -i "%~1" -tune film -preset slow -vf fps=30,scale='min(1920,iw)':-2 -vcodec libx264 -b:v %TargetBitRateInKiloBits%k -pass 1 -an -f null null && ^
c:\ffmpeg\ffmpeg.exe -i "%~1" -tune film -preset slow -vf fps=30,scale='min(1920,iw)':-2 -vcodec libx264 -b:v %TargetBitRateInKiloBits%k -pass 2 -ac 1 -b:a %AudioBitRateInKiloBits%k -y -movflags faststart -fs %MaxFileSizeInMegaBytes%M "%~d1%~p1%~n1_4Mastodon.mp4"
REM c:\ffmpeg\ffmpeg.exe -i "%~d1%~p1%~n1_4Mastodon.mp4" -i "%~d1%~p1%~n1_Thumbnail.png" -map 0 -map 1 -c copy -c:v:1 png -disposition:v:1 attached_pic -y "%~d1%~p1%~n1_4MastodonWithThumbnail.mp4"
timeout /t 999
Endlocal
Sunday, October 9
Wednesday, September 21
Sunday, August 7
Saturday, April 9
Subscribe to:
Comments (Atom)