Skip to content

Instantly share code, notes, and snippets.

@SleepProgger
Last active September 29, 2018 02:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SleepProgger/06a35aa183c297849088efd6204ae45b to your computer and use it in GitHub Desktop.
Save SleepProgger/06a35aa183c297849088efd6204ae45b to your computer and use it in GitHub Desktop.
video2gif_debug.bat
@ECHO OFF
REM For general infos see http://blog.pkh.me/p/21-high-quality-gif-with-ffmpeg.html
REM Set the path here if your ffmpeg executable is somewhere else as in the current directory
SET ffmpeg_path=ffmpeg.exe
SET palette=%TMP%\palette.png
SET subtitlefile=subtitle.ass
if not exist "%ffmpeg_path%" echo "Can't find ffmpeg.exe" & goto done
SET /P src=Video to convert (you can drag and drop the file):
if not exist %src% echo "Can't find the video file" & goto done
SET /P start_time=Startime (ss, mm:ss, and hh:mm:ss formats are supported):
SET /P duration=Duration in seconds:
SET /P dest=Name and path for the gif [test.gif]:
if "%dest%" == "" (
SET dest=test.gif
)
SET /P size=Size [320:-1]("width:height" format. if one is -1 the aspect ratio will be the same):
if "%size%" == "" (
SET size=320:-1
)
SET /P fps=FPS [15]:
if "%fps%" == "" (
SET fps=15
)
SET stats_mode=full
SET dithering=sierra2_4a
SET FC_CONFIG_DIR=.\fonts
SET FC_CONFIG_FILE=.\fonts\fonts.conf
SET /P extended=Extended settings ? [N]:
if "%extended%" == "" goto noextended
if not "%extended%" == "Y" goto noextended
SET /P stats_mode=Prioritize moving objects [N]:
if "%stats_mode%" == "Y" (
SET stats_mode=diff
)
SET /P dithering=Dithering algo (f.e: none, sierra2_4a, floyd_steinberg, bayer(configurable) ) [sierra2_4a]:
Setlocal EnableDelayedExpansion
if "%dithering%" == "bayer" (
SET /P bayer_scale=Bayer scale 1-5 [1]:
if "!bayer_scale!" == "" (
SET bayer_scale=1
)
SET "dithering=bayer:bayer_scale=!bayer_scale!"
)
SET /P with_subtitle=Burn subtitle [N]:
if "%with_subtitle%" == "Y" (
SET /P subtitle="Subtitlefile (video if embedded): "
echo Converting subtitle file ...
"%ffmpeg_path%" -v warning -i !subtitle! -y %subtitlefile%
SET "subtitlefilter=ass=%subtitlefile%,"
)
Setlocal DisableDelayedExpansion
:noextended
SET "filters=%subtitlefilter%fps=%fps%,scale=%size%:flags=lanczos"
echo.
echo Creating palette ...
REM Doesn't have the correct subtitle offset but it shouldn't matter
echo "Executing %ffmpeg_path%" -v debug -ss %start_time% -t %duration% -i %src% -vf "%filters%,palettegen=stats_mode=%stats_mode%" -y %palette%
"%ffmpeg_path%" -v debug -ss %start_time% -t %duration% -i %src% -vf "%filters%,palettegen=stats_mode=%stats_mode%" -y %palette% || echo Failed creating the palette (Invalid video file ?)
echo.
echo Creating GIF ...
echo "Executing %ffmpeg_path%" -v debug -i %src% -i %palette% -ss %start_time% -t %duration% -lavfi "%filters% [x]; [x][1:v] paletteuse=dither=%dithering%" -y %dest%
"%ffmpeg_path%" -v debug -i %src% -i %palette% -ss %start_time% -t %duration% -lavfi "%filters% [x]; [x][1:v] paletteuse=dither=%dithering%" -y %dest% || echo Failed creating the gif
:done
pause
exit /b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment