Skip to main content
replaced http://vi-server.org/ with https://vi-server.org/
Source Link

ffmpeg

Can convert from mp4 to gif. You can apply some effects or resize the video to balance between quality and file size.

You haven't posted your mp4 sample, so I am using my ownown.

Plain conversion

ffmpeg -i sample.mkv -y sample.gif

Result 12M (Note: it won't be hosted foverer here):

sample.gif http://vi-server.org/pub/sample.gifsample.gif

Trickier conversion

According to this article.

filters=scale=854x480:sws_dither=ed:sws_flags=lanczos
ffmpeg -v warning -i sample.mkv -vf $filters,palettegen -y sample.d.png
ffmpeg -v warning -i sample.mkv -i sample.d.png -lavfi $filters' [x]; [x][1:v] paletteuse' -y sample.d.gif

The result has half resolution, looks better, but still 12M.

sample.d.gif http://vi-server.org/pub/sample.d.gifsample.d.gif

Let's try to trade quality for smallness

Reduce FPS to 15 and drop dithering

filters=fps=15,scale=425x240:sws_dither=ed:sws_flags=lanczos
ffmpeg -v warning -i sample.mkv -vf $filters,palettegen -y sample.m.png
ffmpeg -v warning -i sample.mkv -i sample.m.png -lavfi $filters' [x]; [x][1:v] paletteuse=dither=none' -y sample.m.gif

Result: 3.7M

sample.m.gif http://vi-server.org/pub/sample.m.gifsample.m.gif

Trying to fit in 2 MiB to attach here as a picture

12 FPS, 320x180, no dither, 1.8M

sample.mm.gif

Windows way

You can also use FFmpeg from command line in Windows.

I haven't tried, but something like this should work:

set F=fps=15,scale=400x240:sws_dither=ed:sws_flags=lanczos
ffmpeg.exe -i input.mp4 -vf %F%,palettegen -y palette.png
ffmpeg.exe -i input.mp4 -i palette.png -lavfi %F%"[x];[x][1:v]paletteuse=dither=none" -y output.gif

I don't have Windows at hand and can't check if everything is right. If it does not work, write a comment.

Batch file

It is probably not convenient to manually edit and paste those commands every time one need to do the conversion. Here is a (untested) batch file:

set SOURCE=input.mp4
set DESTINATION=output.gif
set FPS=12
set SIZE=256x144
set DITHER=none

set F=fps=%FPS%,scale=%SIZE%:sws_dither=ed:sws_flags=lanczos
ffmpeg.exe -v warning -i %SOURCE% -vf %F%,palettegen -y palette.png
ffmpeg.exe -v warning -i %SOURCE% -i palette.png -lavfi %F%"[x];[x][1:v]paletteuse=dither="%DITHER% -y %DESTINATION%
pause

You can play with output size and FPS, as well as with dithering (may be numbers from 0 to 5 instead of none).

ffmpeg

Can convert from mp4 to gif. You can apply some effects or resize the video to balance between quality and file size.

You haven't posted your mp4 sample, so I am using my own.

Plain conversion

ffmpeg -i sample.mkv -y sample.gif

Result 12M (Note: it won't be hosted foverer here):

sample.gif http://vi-server.org/pub/sample.gif

Trickier conversion

According to this article.

filters=scale=854x480:sws_dither=ed:sws_flags=lanczos
ffmpeg -v warning -i sample.mkv -vf $filters,palettegen -y sample.d.png
ffmpeg -v warning -i sample.mkv -i sample.d.png -lavfi $filters' [x]; [x][1:v] paletteuse' -y sample.d.gif

The result has half resolution, looks better, but still 12M.

sample.d.gif http://vi-server.org/pub/sample.d.gif

Let's try to trade quality for smallness

Reduce FPS to 15 and drop dithering

filters=fps=15,scale=425x240:sws_dither=ed:sws_flags=lanczos
ffmpeg -v warning -i sample.mkv -vf $filters,palettegen -y sample.m.png
ffmpeg -v warning -i sample.mkv -i sample.m.png -lavfi $filters' [x]; [x][1:v] paletteuse=dither=none' -y sample.m.gif

Result: 3.7M

sample.m.gif http://vi-server.org/pub/sample.m.gif

Trying to fit in 2 MiB to attach here as a picture

12 FPS, 320x180, no dither, 1.8M

sample.mm.gif

Windows way

You can also use FFmpeg from command line in Windows.

I haven't tried, but something like this should work:

set F=fps=15,scale=400x240:sws_dither=ed:sws_flags=lanczos
ffmpeg.exe -i input.mp4 -vf %F%,palettegen -y palette.png
ffmpeg.exe -i input.mp4 -i palette.png -lavfi %F%"[x];[x][1:v]paletteuse=dither=none" -y output.gif

I don't have Windows at hand and can't check if everything is right. If it does not work, write a comment.

Batch file

It is probably not convenient to manually edit and paste those commands every time one need to do the conversion. Here is a (untested) batch file:

set SOURCE=input.mp4
set DESTINATION=output.gif
set FPS=12
set SIZE=256x144
set DITHER=none

set F=fps=%FPS%,scale=%SIZE%:sws_dither=ed:sws_flags=lanczos
ffmpeg.exe -v warning -i %SOURCE% -vf %F%,palettegen -y palette.png
ffmpeg.exe -v warning -i %SOURCE% -i palette.png -lavfi %F%"[x];[x][1:v]paletteuse=dither="%DITHER% -y %DESTINATION%
pause

You can play with output size and FPS, as well as with dithering (may be numbers from 0 to 5 instead of none).

ffmpeg

Can convert from mp4 to gif. You can apply some effects or resize the video to balance between quality and file size.

You haven't posted your mp4 sample, so I am using my own.

Plain conversion

ffmpeg -i sample.mkv -y sample.gif

Result 12M (Note: it won't be hosted foverer here):

sample.gif

Trickier conversion

According to this article.

filters=scale=854x480:sws_dither=ed:sws_flags=lanczos
ffmpeg -v warning -i sample.mkv -vf $filters,palettegen -y sample.d.png
ffmpeg -v warning -i sample.mkv -i sample.d.png -lavfi $filters' [x]; [x][1:v] paletteuse' -y sample.d.gif

The result has half resolution, looks better, but still 12M.

sample.d.gif

Let's try to trade quality for smallness

Reduce FPS to 15 and drop dithering

filters=fps=15,scale=425x240:sws_dither=ed:sws_flags=lanczos
ffmpeg -v warning -i sample.mkv -vf $filters,palettegen -y sample.m.png
ffmpeg -v warning -i sample.mkv -i sample.m.png -lavfi $filters' [x]; [x][1:v] paletteuse=dither=none' -y sample.m.gif

Result: 3.7M

sample.m.gif

Trying to fit in 2 MiB to attach here as a picture

12 FPS, 320x180, no dither, 1.8M

sample.mm.gif

Windows way

You can also use FFmpeg from command line in Windows.

I haven't tried, but something like this should work:

set F=fps=15,scale=400x240:sws_dither=ed:sws_flags=lanczos
ffmpeg.exe -i input.mp4 -vf %F%,palettegen -y palette.png
ffmpeg.exe -i input.mp4 -i palette.png -lavfi %F%"[x];[x][1:v]paletteuse=dither=none" -y output.gif

I don't have Windows at hand and can't check if everything is right. If it does not work, write a comment.

Batch file

It is probably not convenient to manually edit and paste those commands every time one need to do the conversion. Here is a (untested) batch file:

set SOURCE=input.mp4
set DESTINATION=output.gif
set FPS=12
set SIZE=256x144
set DITHER=none

set F=fps=%FPS%,scale=%SIZE%:sws_dither=ed:sws_flags=lanczos
ffmpeg.exe -v warning -i %SOURCE% -vf %F%,palettegen -y palette.png
ffmpeg.exe -v warning -i %SOURCE% -i palette.png -lavfi %F%"[x];[x][1:v]paletteuse=dither="%DITHER% -y %DESTINATION%
pause

You can play with output size and FPS, as well as with dithering (may be numbers from 0 to 5 instead of none).

Bounty Ended with 50 reputation awarded by AmirHosein Sadeghimanesh
Add batch file prototype
Source Link
Vi.
  • 1k
  • 7
  • 19

ffmpeg

Can convert from mp4 to gif. You can apply some effects or resize the video to balance between quality and file size.

You haven't posted your mp4 sample, so I am using my own.

Plain conversion

ffmpeg -i sample.mkv -y sample.gif

Result 12M (Note: it won't be hosted foverer here):

sample.gif http://vi-server.org/pub/sample.gif

Trickier conversion

According to this article.

filters=scale=854x480:sws_dither=ed:sws_flags=lanczos
ffmpeg -v warning -i sample.mkv -vf $filters,palettegen -y sample.d.png
ffmpeg -v warning -i sample.mkv -i sample.d.png -lavfi $filters' [x]; [x][1:v] paletteuse' -y sample.d.gif

The result has half resolution, looks better, but still 12M.

sample.d.gif http://vi-server.org/pub/sample.d.gif

Let's try to trade quality for smallness

Reduce FPS to 15 and drop dithering

filters=fps=15,scale=425x240:sws_dither=ed:sws_flags=lanczos
ffmpeg -v warning -i sample.mkv -vf $filters,palettegen -y sample.m.png
ffmpeg -v warning -i sample.mkv -i sample.m.png -lavfi $filters' [x]; [x][1:v] paletteuse=dither=none' -y sample.m.gif

Result: 3.7M

sample.m.gif http://vi-server.org/pub/sample.m.gif

Trying to fit in 2 MiB to attach here as a picture

12 FPS, 320x180, no dither, 1.8M

sample.mm.gif

Windows way

You can also use FFmpeg from command line in Windows.

I haven't tried, but something like this should work:

set F=fps=15,scale=400x240:sws_dither=ed:sws_flags=lanczos
ffmpeg.exe -i input.mp4 -vf %F%,palettegen -y palette.png
ffmpeg.exe -i input.mp4 -i palette.png -lavfi %F%"[x];[x][1:v]paletteuse=dither=none" -y output.gif

I don't have Windows at hand and can't check if everything is right. If it does not work, write a comment.

Batch file

It is probably not convenient to manually edit and paste those commands every time one need to do the conversion. Here is a (untested) batch file:

set SOURCE=input.mp4
set DESTINATION=output.gif
set FPS=12
set SIZE=256x144
set DITHER=none

set F=fps=%FPS%,scale=%SIZE%:sws_dither=ed:sws_flags=lanczos
ffmpeg.exe -v warning -i %SOURCE% -vf %F%,palettegen -y palette.png
ffmpeg.exe -v warning -i %SOURCE% -i palette.png -lavfi %F%"[x];[x][1:v]paletteuse=dither="%DITHER% -y %DESTINATION%
pause

You can play with output size and FPS, as well as with dithering (may be numbers from 0 to 5 instead of none).

ffmpeg

Can convert from mp4 to gif. You can apply some effects or resize the video to balance between quality and file size.

You haven't posted your mp4 sample, so I am using my own.

Plain conversion

ffmpeg -i sample.mkv -y sample.gif

Result 12M (Note: it won't be hosted foverer here):

sample.gif http://vi-server.org/pub/sample.gif

Trickier conversion

According to this article.

filters=scale=854x480:sws_dither=ed:sws_flags=lanczos
ffmpeg -v warning -i sample.mkv -vf $filters,palettegen -y sample.d.png
ffmpeg -v warning -i sample.mkv -i sample.d.png -lavfi $filters' [x]; [x][1:v] paletteuse' -y sample.d.gif

The result has half resolution, looks better, but still 12M.

sample.d.gif http://vi-server.org/pub/sample.d.gif

Let's try to trade quality for smallness

Reduce FPS to 15 and drop dithering

filters=fps=15,scale=425x240:sws_dither=ed:sws_flags=lanczos
ffmpeg -v warning -i sample.mkv -vf $filters,palettegen -y sample.m.png
ffmpeg -v warning -i sample.mkv -i sample.m.png -lavfi $filters' [x]; [x][1:v] paletteuse=dither=none' -y sample.m.gif

Result: 3.7M

sample.m.gif http://vi-server.org/pub/sample.m.gif

Trying to fit in 2 MiB to attach here as a picture

12 FPS, 320x180, no dither, 1.8M

sample.mm.gif

Windows way

You can also use FFmpeg from command line in Windows.

I haven't tried, but something like this should work:

set F=fps=15,scale=400x240:sws_dither=ed:sws_flags=lanczos
ffmpeg.exe -i input.mp4 -vf %F%,palettegen -y palette.png
ffmpeg.exe -i input.mp4 -i palette.png -lavfi %F%"[x];[x][1:v]paletteuse=dither=none" -y output.gif

I don't have Windows at hand and can't check if everything is right. If it does not work, write a comment.

ffmpeg

Can convert from mp4 to gif. You can apply some effects or resize the video to balance between quality and file size.

You haven't posted your mp4 sample, so I am using my own.

Plain conversion

ffmpeg -i sample.mkv -y sample.gif

Result 12M (Note: it won't be hosted foverer here):

sample.gif http://vi-server.org/pub/sample.gif

Trickier conversion

According to this article.

filters=scale=854x480:sws_dither=ed:sws_flags=lanczos
ffmpeg -v warning -i sample.mkv -vf $filters,palettegen -y sample.d.png
ffmpeg -v warning -i sample.mkv -i sample.d.png -lavfi $filters' [x]; [x][1:v] paletteuse' -y sample.d.gif

The result has half resolution, looks better, but still 12M.

sample.d.gif http://vi-server.org/pub/sample.d.gif

Let's try to trade quality for smallness

Reduce FPS to 15 and drop dithering

filters=fps=15,scale=425x240:sws_dither=ed:sws_flags=lanczos
ffmpeg -v warning -i sample.mkv -vf $filters,palettegen -y sample.m.png
ffmpeg -v warning -i sample.mkv -i sample.m.png -lavfi $filters' [x]; [x][1:v] paletteuse=dither=none' -y sample.m.gif

Result: 3.7M

sample.m.gif http://vi-server.org/pub/sample.m.gif

Trying to fit in 2 MiB to attach here as a picture

12 FPS, 320x180, no dither, 1.8M

sample.mm.gif

Windows way

You can also use FFmpeg from command line in Windows.

I haven't tried, but something like this should work:

set F=fps=15,scale=400x240:sws_dither=ed:sws_flags=lanczos
ffmpeg.exe -i input.mp4 -vf %F%,palettegen -y palette.png
ffmpeg.exe -i input.mp4 -i palette.png -lavfi %F%"[x];[x][1:v]paletteuse=dither=none" -y output.gif

I don't have Windows at hand and can't check if everything is right. If it does not work, write a comment.

Batch file

It is probably not convenient to manually edit and paste those commands every time one need to do the conversion. Here is a (untested) batch file:

set SOURCE=input.mp4
set DESTINATION=output.gif
set FPS=12
set SIZE=256x144
set DITHER=none

set F=fps=%FPS%,scale=%SIZE%:sws_dither=ed:sws_flags=lanczos
ffmpeg.exe -v warning -i %SOURCE% -vf %F%,palettegen -y palette.png
ffmpeg.exe -v warning -i %SOURCE% -i palette.png -lavfi %F%"[x];[x][1:v]paletteuse=dither="%DITHER% -y %DESTINATION%
pause

You can play with output size and FPS, as well as with dithering (may be numbers from 0 to 5 instead of none).

Source Link
Vi.
  • 1k
  • 7
  • 19

ffmpeg

Can convert from mp4 to gif. You can apply some effects or resize the video to balance between quality and file size.

You haven't posted your mp4 sample, so I am using my own.

Plain conversion

ffmpeg -i sample.mkv -y sample.gif

Result 12M (Note: it won't be hosted foverer here):

sample.gif http://vi-server.org/pub/sample.gif

Trickier conversion

According to this article.

filters=scale=854x480:sws_dither=ed:sws_flags=lanczos
ffmpeg -v warning -i sample.mkv -vf $filters,palettegen -y sample.d.png
ffmpeg -v warning -i sample.mkv -i sample.d.png -lavfi $filters' [x]; [x][1:v] paletteuse' -y sample.d.gif

The result has half resolution, looks better, but still 12M.

sample.d.gif http://vi-server.org/pub/sample.d.gif

Let's try to trade quality for smallness

Reduce FPS to 15 and drop dithering

filters=fps=15,scale=425x240:sws_dither=ed:sws_flags=lanczos
ffmpeg -v warning -i sample.mkv -vf $filters,palettegen -y sample.m.png
ffmpeg -v warning -i sample.mkv -i sample.m.png -lavfi $filters' [x]; [x][1:v] paletteuse=dither=none' -y sample.m.gif

Result: 3.7M

sample.m.gif http://vi-server.org/pub/sample.m.gif

Trying to fit in 2 MiB to attach here as a picture

12 FPS, 320x180, no dither, 1.8M

sample.mm.gif

Windows way

You can also use FFmpeg from command line in Windows.

I haven't tried, but something like this should work:

set F=fps=15,scale=400x240:sws_dither=ed:sws_flags=lanczos
ffmpeg.exe -i input.mp4 -vf %F%,palettegen -y palette.png
ffmpeg.exe -i input.mp4 -i palette.png -lavfi %F%"[x];[x][1:v]paletteuse=dither=none" -y output.gif

I don't have Windows at hand and can't check if everything is right. If it does not work, write a comment.