|
1 | | -@echo off |
2 | | -rem by: nabi karamalizadeh <[email protected]> |
3 | | -rem description: video to gif converter |
4 | | -rem version: 0.0.1 |
5 | | -rem license: The MIT License (MIT) |
6 | | -set arg1=%1 |
7 | | -set arg2=%arg1:~0,-4% |
8 | | -ffmpeg -y -i %arg1% -vf fps=15,scale=-1:-1:flags=lanczos,palettegen %TEMP%\palette.png |
9 | | -ffmpeg -i %arg1% -i %TEMP%\palette.png -filter_complex "fps=10,scale=-1:-1:flags=lanczos[x];[x][1:v]paletteuse" %arg2%.gif |
10 | | -del /f %TEMP%\palette.png |
| 1 | +@ECHO OFF |
| 2 | +REM By: Nabi KaramAliZadeh <[email protected]> |
| 3 | +REM Description: video to gif converter |
| 4 | +REM Version: 1.0.0 |
| 5 | +REM Url: https://github.com/NabiKAZ/video2gif |
| 6 | +REM License: The MIT License (MIT) |
| 7 | + |
| 8 | +SETLOCAL |
| 9 | + |
| 10 | +SET "input=" |
| 11 | +SET "output=" |
| 12 | +SET "overwrite=" |
| 13 | +SET "fps=" |
| 14 | +SET "width=" |
| 15 | +SET "start_time=" |
| 16 | +SET "duration=" |
| 17 | +SET "time_range=" |
| 18 | +SET "palette=" |
| 19 | +SET "max_colors=" |
| 20 | +SET "dither=" |
| 21 | + |
| 22 | +SET input=%~1 |
| 23 | +SET base_file=%~dpn1 |
| 24 | +SET input_filename=%~n1%~x1 |
| 25 | +SHIFT |
| 26 | + |
| 27 | +IF "%input%" == "" ( |
| 28 | + ECHO Video to GIF converter v1.0.0 ^(C^) 2017, Nabi KaramAliZadeh ^<nabikaz@gmail.com^> |
| 29 | + ECHO You can download it from here: https://github.com/NabiKAZ/video2gif |
| 30 | + ECHO This tools use of ffmpeg here: http://ffmpeg.zeranoe.com/builds |
| 31 | + ECHO. |
| 32 | + ECHO Usage: video2gif SOURCE_FILE [OPTIONS] |
| 33 | + ECHO. |
| 34 | + ECHO Options: |
| 35 | + ECHO SOURCE_FILE Source video file name for convert |
| 36 | + ECHO also you can drag and drop source video file to this batch file directly |
| 37 | + ECHO -o Output destination .GIF file name |
| 38 | + ECHO if not set it, use video source file name with new .gif extension |
| 39 | + ECHO -y Overwrite destination file |
| 40 | + ECHO if not set it, appears prompt for overwrite destination file |
| 41 | + ECHO -f Frame per second ^(fps^) |
| 42 | + ECHO default: 15 |
| 43 | + ECHO -w Width scale of destination gif file |
| 44 | + ECHO in pixel unit and ^(-1^) for use original width, default: -1 |
| 45 | + ECHO -s Start time of video source for crop |
| 46 | + ECHO in second or time format ^(ex. 1:12^), if set it, so must be set ^(-d^) param |
| 47 | + ECHO -d Duration time of video source for crop |
| 48 | + ECHO in second, if set it, so must be set ^(-s^) param |
| 49 | + ECHO -c Maximum number of colors to the palette |
| 50 | + ECHO must be ^(^<=256^), default: 256 |
| 51 | + ECHO -q Quality of destination gif file |
| 52 | + ECHO must be a number between 1^(low^) to 6^(high^), default: 5 |
| 53 | + ECHO. |
| 54 | + ECHO Examples: |
| 55 | + ECHO video2gif sample.mp4 |
| 56 | + ECHO video2gif sample.mp4 -y -w 60 -q 1 -f 10 |
| 57 | + ECHO video2gif sample.mp4 -o new_file.gif -y -w 100 -f 10 -s 10 -d 5 |
| 58 | + ECHO video2gif sample.mp4 -s 0:30 -d 20 -c 128 -q 6 |
| 59 | + ECHO video2gif sample.mp4 -s 1:16.5 -d 8.3 |
| 60 | + GOTO :EOF |
| 61 | +) |
| 62 | + |
| 63 | +:loop |
| 64 | +IF NOT "%~1"=="" ( |
| 65 | + IF "%~1"=="-o" SET "output=%~2" & SHIFT |
| 66 | + IF "%~1"=="-y" SET "overwrite=-y" |
| 67 | + IF "%~1"=="-f" SET "fps=%~2" & SHIFT |
| 68 | + IF "%~1"=="-w" SET "width=%~2" & SHIFT |
| 69 | + IF "%~1"=="-s" SET "start_time=%~2" & SHIFT |
| 70 | + IF "%~1"=="-d" SET "duration=%~2" & SHIFT |
| 71 | + IF "%~1"=="-c" SET "max_colors=%~2" & SHIFT |
| 72 | + IF "%~1"=="-q" SET "dither=%~2" & SHIFT |
| 73 | + SHIFT |
| 74 | + GOTO :loop |
| 75 | +) |
| 76 | + |
| 77 | +if "%output%"=="" SET output=%base_file%.gif |
| 78 | +if "%fps%"=="" SET fps=15 |
| 79 | +if "%width%"=="" SET width=-1 |
| 80 | +if not "%start_time%"=="" if not "%duration%"=="" SET time_range=-ss %start_time% -t %duration% |
| 81 | +if "%max_colors%"=="" SET max_colors=256 |
| 82 | +if "%dither%"=="" SET dither=sierra2_4a |
| 83 | +if "%dither%"=="1" SET dither=none |
| 84 | +if "%dither%"=="2" SET dither=sierra2 |
| 85 | +if "%dither%"=="3" SET dither=floyd_steinberg |
| 86 | +if "%dither%"=="4" SET dither=heckbert |
| 87 | +if "%dither%"=="5" SET dither=sierra2_4a |
| 88 | +if "%dither%"=="6" SET dither=bayer |
| 89 | + |
| 90 | +SET palette=%TEMP%\%input_filename%.png |
| 91 | +SET filters=fps=%fps%,scale=%width%:-1:flags=lanczos |
| 92 | + |
| 93 | +ECHO Generating palette file. Please wait... |
| 94 | + |
| 95 | +CALL ffmpeg -v error %time_range% -i %input% -vf "%filters%,palettegen=max_colors=%max_colors%" -y %palette% |
| 96 | + |
| 97 | +IF NOT EXIST "%palette%" ( |
| 98 | + ECHO Failed to generate palette file. |
| 99 | + GOTO :EOF |
| 100 | +) |
| 101 | + |
| 102 | +ECHO Generating gif file. Please wait... |
| 103 | + |
| 104 | +CALL ffmpeg -v error %time_range% -i %input% -i %palette% -lavfi "%filters% [x]; [x][1:v] paletteuse=dither=%dither%" %overwrite% %output% |
| 105 | + |
| 106 | +IF NOT EXIST "%output%" ( |
| 107 | + ECHO Failed to generate gif file. |
| 108 | + GOTO :EOF |
| 109 | +) |
| 110 | + |
| 111 | +DEL /F /Q %palette% |
| 112 | + |
| 113 | +ECHO "%output%" Gif file generated successfully. |
| 114 | +ECHO Done. |
0 commit comments