Skip to content

Instantly share code, notes, and snippets.

@ahallora
Last active January 16, 2024 10:38
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 ahallora/722271519b3ba6849b3553355b0fc9bb to your computer and use it in GitHub Desktop.
Save ahallora/722271519b3ba6849b3553355b0fc9bb to your computer and use it in GitHub Desktop.
Convert MP4 to GIF free and open-source using FFMPEG and Windows Context menu

Convert MP4 to GIF free and easy directly from the Windows context menu

Previously I've been using GifCam, but it doesn't play well with my retina display, so I had to come up with something. There's strong options for Mac but no good free options for Windows.

I can use the native Windows snipping tool to record my screen, but I'm unable to save the recording as a gif, resulting in pretty big MP4 files. I don't want that. So I created this little script that can convert the recorded MP4 file to GIF for a great reduction in file size.

Installation

  1. Install ffmpeg from www.ffmpeg.org
  2. Update the path to ffmpeg in the bat file
  3. Update the path to the bat file in the reg file
  4. Run the reg file and install the keys in registry
  5. Right click on a MP4 file and click "Convert to GIF"

FYI: If you're on Windows 11, you might have to go to "Show all properties" to get the full windows context menu options.

Let me know if you found this helpful, by dropping a comment below. 👋

Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\SystemFileAssociations\.mp4\shell\ConvertToGIF]
@="Convert to GIF"
[HKEY_CLASSES_ROOT\SystemFileAssociations\.mp4\shell\ConvertToGIF\command]
@="\"C:\\Path\\To\\Your\\File\\convert_mp4_to_gif.bat\" \"%1\""
@echo off
setlocal enabledelayedexpansion
set "input="
set "output="
set "ffmpeg_path=C:\ffmpeg\bin\ffmpeg.exe"
if not exist "!ffmpeg_path!" (
echo FFmpeg not found. Make sure the path is correct. Exiting...
pause
exit /b 1
)
if "%~1"=="" (
echo Please provide a file path as an argument.
exit /b 1
)
set "input=%~1"
rem Check if the file exists
if not exist "!input!" (
echo File does not exist.
goto :eof
)
rem Extract file path, name, and extension
for /f "delims=" %%a in ("!input!") do (
set "fullpath=%%~dpnxa"
set "path=%%~dpa"
set "name=%%~na"
set "extension=%%~xa"
)
rem Strip the extension and set the new extension
set "new_extension=gif"
set "output=!path!!name!.!new_extension!"
"%ffmpeg_path%" -i "%input%" -r 16 "%output%"
echo Conversion complete. Output GIF: !output!
endlocal
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment