Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @echo off
- SetLocal EnableDelayedExpansion
- set title1=Convert to GIF
- title %title1%
- if "%~1"=="" ( echo ERROR: NO INPUT & echo & pause & goto :eof ) else ( title %title1%^: "%~nx1")
- :: you can override exe paths here. for example, set "ffmpeg=C:\ffmpeg\bin\ffmpeg.exe"
- set "ffmpeg=ffmpeg.exe"
- :: only these file extensions will be processed by the script
- set supported_formats=avi,bik,flv,m2ts,m4p,m4v,mkv,mov,mp2,mp4,mpg,mpeg,mpe,mpv,mts,qt,swf,wmv,xmf,webm
- :: optional default subfolder to output to. for example, set "subfolder=converted"
- set subfolder=
- :CheckFFMPEG
- if not exist "%ffmpeg%" (
- if exist "%~dp0ffmpeg.exe" set "ffmpeg=%~dp0ffmpeg.exe" & goto :CheckFFPROBE
- ffmpeg.exe>nul 2>&1
- if !errorlevel!==9009 CALL :PrintMessage "ERROR: FFMPEG NOT FOUND / INSTALLED. EXITING." & echo & pause & goto :eof
- )
- :CountFiles
- :: count files
- set total=0
- for %%F in (%*) do (
- if not "%%~xF"=="" (
- for %%A in (%supported_formats%) do (
- if /i %%~xF==.%%A set /a total=!total!+1
- )
- )
- )
- if %total%==0 echo & CALL :PrintMessage "NO FILES TO PROCESS" "EXITING" & pause>nul & goto :eof
- if %total% GTR 1 title %title1%^: %total% files
- :Resize
- if defined width goto :FrameRate
- set width=
- echo.
- set /p width="resize (width) = "
- if not "!width!"=="" (
- set "width=!width: =!"
- for /f "delims=1234567890" %%A in ('echo !width!') do ( echo invalid number & goto :Resize )
- if !width! LSS 5 echo invalid number & goto :Resize
- )
- :FrameRate
- if defined framerate goto :ConformFilters
- set frate=
- echo.
- set /p frate="framerate = "
- if not "!frate!"=="" (
- set "frate=!frate: =!"
- for /f "delims=1234567890" %%A in ('echo !frate!') do ( echo invalid number & goto :FrameRate)
- if !frate! LSS 1 echo invalid number & goto :FrameRate
- set "newframerate=!frate!"
- )
- :ConformFilters
- if not "!width!"=="" set filters=scale='min(!width!,iw)':-1:flags=lanczos
- if not "!newframerate!"=="" ( if "!filters!"=="" ( set filters=fps=!newframerate!) else ( set filters=!filters!,fps=!newframerate!))
- if not "!filters!"=="" ( set filters=-vf "!filters!,split[s0][s1];[s0]palettegen[p];[s1][p]paletteuse") else ( set filters=-vf "split[s0][s1];[s0]palettegen[p];[s1][p]paletteuse")
- :BatchProcess
- set current=
- for %%F in (%*) do (
- if not "%%~xF"=="" (
- for %%A in (%supported_formats%) do ( if /i %%~xF==.%%A CALL :ProcessFile "%~1")
- )
- )
- title Finished
- goto :eof
- :: MAIN ROUTINE
- :ProcessFile
- if "!current!"=="" ( set current=1) else ( set /a current=!current!+1)
- if %total% GTR 1 set "ratio= !current!/!total!"
- title %title1%^:!ratio! "%~nx1"
- if not "%cd%\"=="%~dp1" cd /d "%~dp1"
- :Add_Postfix
- if exist "%~n1.gif" (
- for /L %%N in (1,1,1000) do (
- if not exist "%~n1_%%N.gif" ( set "postfix=_%%N" & goto :FFmpeg)
- )
- )
- :FFmpeg
- "%ffmpeg%" -i "%~1" -an !filters! "%~n1!postfix!.gif"
- if not !errorlevel!==0 CALL :ErrorSubroutine "!outpath!%~n1%suffix%!postfix!.%ext%"
- goto :eof
- :: if output file is empty, deletes it. prints some messages. stores goterror var.
- :ErrorSubroutine
- if "%~z1"=="0" del %1 & ( echo & echo ERROR: FILE OUTPUT FAILED & echo.)
- set goterror=true
- pause
- goto :eof
- :: UTILITIES
- :PrintMessage
- echo.
- echo ---------------------------------------------------------------
- echo %~1
- if not "%~2"=="" echo %~2
- if not "%~3"=="" echo %~3
- if not "%~4"=="" echo %~4
- echo ---------------------------------------------------------------
- goto :eof
Add Comment
Please, Sign In to add comment