gas
320-832
834-1346
1347-1859
1900-0012
Ctrl + Alt + T on your Chromebook keyboard. This will open a new tab in your Chrome browser with the Crosh shell.
https://www.zamzar.com/
convert to gifs:
https://gif.ski/
download video:https://retatube.com/
Once the Crosh shell is open, you can type shell and press Enter
$content = [System.IO.File]::ReadAllText("c:\users\bunner\desktop\apr10.txt").Replace("[View]"," ").Replace("..."," ").Replace("."," ")
[System.IO.File]::WriteAllText(("c:\users\bunner\desktop\apr10c.txt"), $content)
youtube to mp3recordrecord
youtube2
incomp
crdoc2
del *900.* *700.* *500.* *300.* *100.*
del *903.* *703.* *503.* *303.* *103.* *904.* *704.* *504.* *304.* *104.*
(for /F "eol=| delims=" %I in ('dir *.mp4 /A-D /B /ON 2^>nul') do @echo file '%I')>a.txt
ffmpeg -f concat -safe 0 -i a.txt -c copy 240806.mp4
ffmpeg -i input.mp4 -c:v libx264 -tune zerolatency -preset ultrafast -crf 63 -c:a aac -b:a 32k output.mp4 cite
combine webms: ffmpeg -f concat -i mylist.txt -c copy -avoid_negative_ts 1 finalvideo.webm
SLOW: ffmpeg -i 240806.mp4 -filter:v "setpts=3.0*PTS" a.mp4
PICS THIS WORKS: (for /F "eol=| delims=" %I in ('dir *.jpg /B /ON 2^>nul') do @echo file '%I' &@echo duration 10)>a.txt
ffmpeg -f concat -i a.txt -c:v libx264 -pix_fmt yuv420p 24.mp4
WEBM to MP4:
ffmpeg -i who.webm -qscale 1 video.mp4
https://www.flexclip.com/tools/screen-recorder/
make list: dir *.mp4 /A-D /B /ON >ListOrderedByName.txt or dir *.mp4 /A-D /B /O-N >ListOrderedByNameReverse.txt
do move "%%i" "file-%%~nxi"
@ECHO OFF
Setlocal EnableDelayedExpansion
set INPUT=E:\in
set OUTPUT=E:\out
:: encode video:
for %a in ("%INPUT%\*.*") DO ffmpeg -i "%a" -c:v libx264 -tune zerolatency -preset ultrafast -crf 63 -c:a aac -b:a 32k "%output%\%~na_%03d.mp4"
ffmpeg -i "concat:input1.ts|input2.ts|input3.ts" -c copy output.ts
CUT: ffmpeg -i input.mp4 -map 0 -c copy -f segment -segment_time 120 -reset_timestamps 1 out%02d.mp4
CONVERT mp4s to mp3s or whatever to GIFS (may need to change to %%): for %i in (*.mp4) do ffmpeg -i "%i" "%~ni.mp3"
speed up slow down ffmpeg -i input.mp4 -vf "setpts=0.5*PTS" output.mp4 or slow 1.5*PTS"
VOLUME:ffmpeg -i ac.mp4 -af volume=14 -vcodec copy ac2.mp4 ~or~ ffmpeg -i input.wav -af "volume=0.5" output.wav (Increase 50%): ffmpeg -i input.wav -af "volume=1.5" output.wav or in dB: ffmpeg -i input.wav -af "volume=10dB" output.wav
save only audio: ffmpeg -i m.mp4 -vn -ac 2 -ar 44100 -ab 320k -f mp3 output.mp3
MP3s: ffmpeg -i My.mp3 -map 0:a:0 -b:a 96k 1My.mp3
ffmpeg -i 1.mpg -ss 00:10:48 -to 00:11:56 -c:v copy -c:a copy e.mp4
file '0.mp4'
file '1.mp4'
file '2.mp4'
Remove Frames from video
ffmpeg -i MichaelRobinson5230804154100.mp4 -vf fps=1/0.5 img%03d.jpg
change 1/1 for 1 frame every second change to 1/30 for one frame every half minute, or 1/60 for one frame every minute etc.
https://www.7-zip.org/download.html
https://www.gyan.dev/ffmpeg/builds/
select second the: ffmpeg-git-full.7z
rightclick folder select extract files
rename the folder to ffmpeg
This PC Local Disk(C:) should have folder ffmpeg with all the files previous
enviroment variables
type "environment properties" on search tab and click open
go to advanced tab choose Environment Variables
go to System Variables select Path click Edit
choose New and add C:\ffmpeg\bin
go to c users (name) and pull the bin out of the ffmpeg folder onto the c users name
ffmpeg -i i_ch2_main_20230521000000_20230521010000.mp4 -c:v libx264 -tune zerolatency -preset ultrafast -crf 48 -c:a aac -b:a 32k 0.mp4
How do I convert a video to GIF using ffmpeg, with reasonable quality?
Asked 11 years, 9 months ago
Modified 28 days ago
Viewed 673k times
676
I'm converting a video to GIF file with ffmpeg:
ffmpeg \
-i input.flv \
-ss 00:00:00.000 \
-pix_fmt rgb24 \
-r 10 \
-s 320x240 \
-t 00:00:10.000 \
output.gif
It works great, but output gif file has a very low quality.
Any ideas how can I improve quality of converted gif?
ffmpeggif
Share
Edit
Follow
Get updates on questions and answers
edited Apr 18, 2022 at 17:42
Rob Bednark's user avatar
Rob Bednark
17511 silver badge55 bronze badges
asked Feb 22, 2013 at 20:06
Kamil Hismatullin's user avatar
Kamil Hismatullin
6,87033 gold badges1515 silver badges77 bronze badges
3
If you don't want any scaling: ffmpeg -i input.mp4 -y -vf 'fps=50,split[s0][s1];[s0]palettegen[p];[s1][p]paletteuse' -loop 0 output.gif. fps=50 is the maximum highly compatible value. –
awvalenti
CommentedNov 6, 2023 at 19:15
Show 1 more comment
18 Answers
Sorted by:
Highest score (default)
1062
ffmpeg example
GIF output from ffmpeg
183k
ffmpeg can output high quality GIF. Before you start it is always recommended to use a recent version: download or compile.
ffmpeg -ss 30 -t 3 -i input.mp4 \
-vf "fps=10,scale=320:-1:flags=lanczos,split[s0][s1];[s0]palettegen[p];[s1][p]paletteuse" \
-loop 0 output.gif
This example will skip the first 30 seconds (-ss 30) of the input and create a 3 second output (-t 3).
fps filter sets the frame rate. A rate of 10 frames per second is used in the example.
scale filter will resize the output to 320 pixels wide and automatically determine the height while preserving the aspect ratio. The lanczos scaling algorithm is used in this example.
palettegen and paletteuse filters will generate and use a custom palette generated from your input. These filters have many options, so refer to the links for a list of all available options and values. Also see the Advanced options section below.
split filter will allow everything to be done in one command and avoids having to create a temporary PNG file of the palette.
Control looping with -loop output option but the values are confusing. A value of 0 is infinite looping, -1 is no looping, and 1 will loop once meaning it will play twice. So a value of 10 will cause the GIF to play 11 times.
Advanced options
The palettegen and paletteuse filters have many additional options. The most important are:
stats_mode (palettegen). You can force the filters to focus the palette on the general picture (full which is the default), only the moving parts (diff), or each individual frame (single). For example, to generate a palette for each individual frame use palettegen=stats_mode=single & paletteuse=new=1.
dither (paletteuse). Choose the dithering algorithm. There are three main types: deterministic (bayer), error diffusion (all the others including the default sierra2_4a), and none. Your GIF may look better using a particular dithering algorithm, or no dithering at all. If you want to try bayer be sure to test the bayer_scale option too.
See High quality GIF with FFmpeg for explanations, example images, and more detailed info for advanced usage.
Also see the palettegen and paletteuse documentation for all available options and values.
ImageMagick convert example
GIF output from ffmpeg
227k
Another command-line method is to pipe from ffmpeg to convert (or magick) from ImageMagick.
ffmpeg -i input.mp4 -vf "fps=10,scale=320:-1:flags=lanczos" -c:v pam \
-f image2pipe - | \
convert -delay 10 - -loop 0 -layers optimize output.gif
ffmpeg options:
-vf "fps=10,scale=320:-1:flags=lanczos" a filtergraph using the fps and scale filters. fps sets frame rate to 10, and scale sets the size to 320 pixels wide and height is automatically determined and uses a value that preserves the aspect ratio. The lanczos scaling algorithm is used in this example.
-c:v pam Chooses the pam image encoder. The example outputs the PAM (Portable AnyMap) image format which is a simple, lossless RGB format that supports transparency (alpha) and is supported by convert. It is faster to encode than PNG.
-f image2pipe chooses the image2pipe muxer because when outputting to a pipe ffmpeg needs to be told which muxer to use.
convert options:
-delay See Setting frame rate section below.
-loop 0 makes infinite loop.
-layers optimize Will enable the general purpose GIF optimizer. See ImageMagick Animation Optimization for more details. It is not guaranteed that it will produce a smaller output, so it is worth trying without -layers optimize and comparing results.
Setting frame rate
Set frame rate with a combination of the fps filter in ffmpeg and -delay in convert. This can get complicated because convert just gets a raw stream of images so no fps is preserved. Secondly, the -delay value in convert is in ticks (there are 100 ticks per second), not in frames per second. For example, with fps=12.5 = 100/12.5 = 8 = -delay 8.
convert rounds the -delay value to a whole number, so 8.4 results in 8 and 8.5 results in 9. This effectively means that only some frame rates are supported when setting a uniform delay over all frames (a specific delay can be set per frame but that is beyond this answer).
-delay appears to be ignored if used as an output option, so it has to be used before - as shown in the example.
Lastly, browsers and image viewers may implement a minimum delay, so your -delay may get ignored anyway.
Video courtesy of U.S. Fish & Wildlife Service National Conservation Training Center.
Share
Edit
Follow
edited Sep 21, 2022 at 18:56
K3---rnc's user avatar
K3---rnc
28033 silver badges88 bronze badges
answered Feb 22, 2013 at 21:31
llogan's user avatar
llogan
62k1717 gold badges133133 silver badges153153 bronze badges
4
Added some example results (just still frames though). Here, the first file is 4.1 MB, the second around 8 MB. –
slhck
CommentedFeb 22, 2013 at 21:44
4
@LordNeckbeard, you are awesome! much thanks for -vf scale=320:-1,format=rgb8,format=rgb24 –
Kamil Hismatullin
CommentedFeb 22, 2013 at 21:53
8
By the way, for the convert command for converting from the PNG frames I ended up using convert -delay 5 -loop 0 -dither None -colors 80 "frames/ffout*.png" -fuzz "40%" -layers OptimizeFrame "output.gif", which reduces the overall file size quite a bit –
Wilf
CommentedJul 24, 2014 at 13:58
7
Okay, I've got it, i used scale=0:-1, so when you set the scale to 0, it will take the scale from the video. –
Mousa Alfhaily
CommentedSep 16, 2017 at 12:20
2
This Q&A must be permanently encoded in a tome (or maybe just "pinned" for now) because in a hundred years from now all communication will be done via memes. I think the activity on this post alone speaks to that. –
Coder Guy
CommentedOct 7, 2018 at 8:15
Show 37 more comments
106
If you would prefer to avoid intermediate image files, the commands provided by LordNeckBeard can be piped between ffmpeg and ImageMagick's convert so that no intermediate files are required:
ffmpeg -i input.flv -vf scale=320:-1 -r 10 -f image2pipe -vcodec ppm - | convert -delay 10 -loop 0 - output.gif
The -f image2pipe tells ffmpeg to split the video into images and make it suitable to be piped out, and -vcodec ppm specifies the output format to be ppm (for some reason if the format is png, either convert does not read all the images from the pipe, or ffmpeg does not output them all). The - for both commands specifies that a pipe will be used for output and input respectively.
To optimize the result without saving a file, you can pipe the output from convert to a second convert command:
ffmpeg -i input.flv -vf scale=320:-1 -r 10 -f image2pipe -vcodec ppm - | convert -delay 10 -loop 0 - gif:- | convert -layers Optimize - output.gif
The gif:- tells convert to pipe its output as gif formatted data and -layers Optimize tells the second convert to perform optimize-frame and optimize-transparancy methods (see the ImageMagick Introduction to Animation Optimization). Note that the output from the -layers Optimize may not always provide a smaller file size, so you may want to try converting to a gif without optimization first to be sure.
Remember that during this whole process everything is in memory so you may need sufficient memory if the images are quite large.
Share
Edit
Follow
edited Feb 26, 2021 at 20:50
Connor McCormick's user avatar
Connor McCormick
21322 silver badges66 bronze badges
answered Mar 18, 2014 at 9:47
notedible's user avatar
notedible
1,30911 gold badge99 silver badges44 bronze badges
1
This set of commands also works with avconv –
raphael
CommentedDec 9, 2015 at 2:00
2
The gif appears to be running at 2x the speed of the source video? –
Titan
CommentedOct 10, 2016 at 13:28
1
@Titan believe it's the -r 10 in the first command and the -delay 5 in the second. I changed the delay to 10 also and it seems to play normally now. –
Steven Huang
CommentedJan 8, 2017 at 4:28
3
You can also avoid intermediate image files by using the split filter in ffmpeg. No need to pipe anything at all: ffmpeg -ss 30 -t 3 -i "input.flv fps=10,scale=320:-1:flags=lanczos,split[x][z];[z]palettegen[y];[x][y]paletteuse" output.gif –
Ajedi32
CommentedJan 8, 2017 at 23:26
1
Is there a way to maintain the scale? For example, my video file is 904:774. How do I do it without setting scale=320:-1? Is there a way to automate it without exploding the size? –
Sudhir Singh Khanger
CommentedSep 7, 2018 at 7:08
Show 2 more comments
57
As of ffmpeg 2.6, we can do even better. Based on High quality GIF with FFmpeg:
palette="/tmp/palette.png"
filters="fps=15,scale=320:-1:flags=lanczos"
ffmpeg -i input.flv -vf "$filters,palettegen" -y $palette
ffmpeg -i input.flv -i $palette -lavfi "$filters [x]; [x][1:v] paletteuse" -y output.gif
Share
Edit
Follow
edited Oct 10, 2021 at 7:18
Peregrino69's user avatar
Peregrino69
4,81433 gold badges2323 silver badges3131 bronze badges
answered Mar 23, 2015 at 18:39
pje's user avatar
pje
67155 silver badges55 bronze badges
9
what does this do? –
CervEd
CommentedMay 19, 2021 at 6:44
1
I tried and get an error: The specified filename 'palette.png' does not contain an image sequence pattern or a pattern is invalid. –
Xan-Kun Clark-Davis
CommentedFeb 18 at 19:22
Add a comment
35
The answer from @Stephane is very good. But it will get a warning like Buffer queue overflow, dropping. for some video, and the generated gif has some frame dropped.
Here is a better version with fifo filter to avoid Buffer queue overflow when using paletteuse filter. By using split filter to avoid the creation of intermediate palette PNG file.
ffmpeg -i input.mp4 -filter_complex 'fps=10,scale=320:-1:flags=lanczos,split [o1] [o2];[o1] palettegen [p]; [o2] fifo [o3];[o3] [p] paletteuse' out.gif
Share
Edit
Follow
answered Oct 5, 2017 at 12:04
alijandro's user avatar
alijandro
45144 silver badges33 bronze badges
1
@Chloe Did you see the fifo filter operation between o2 and o3? To avoid the Buffer queue overflow warning. –
alijandro
CommentedOct 23, 2018 at 1:45
1
the fifo filter was recently removed. I removed the substring ` fifo [o3];[o3]` from the command in this answer and it worked without Buffer queue overflow –
Mattwmaster58
CommentedAug 22 at 13:24
Show 1 more comment
30
I made my own version of this script, which parameterizes the output resolution and frame rate as well.
Running ./gifenc.sh input.mov output.gif 720 10 will output 720p wide 10fps GIF from the movie you gave it. You might need to do chmod +x gifenc.sh for the file.
#!/bin/sh
palette="/tmp/palette.png"
filters="fps=$4,scale=$3:-1:flags=lanczos"
ffmpeg -v warning -i "$1" -vf "$filters,palettegen" -y "$palette"
ffmpeg -v warning -i "$1" -i $palette -lavfi "$filters [x]; [x][1:v] paletteuse" -y "$2"
You can read the details on my Github
Assumptions: ffmpeg is installed, and the script is in the same folder as the other files.
Share
Edit
Follow
edited Oct 10, 2021 at 8:43
Lance U. Matthews's user avatar
Lance U. Matthews
35111 silver badge1717 bronze badges
answered Jul 12, 2015 at 9:35
thevangelist's user avatar
thevangelist
49411 gold badge66 silver badges1111 bronze badges
3
Thank you so much for your script. I just tested it and it works great! –
orschiro
CommentedFeb 5, 2016 at 9:32
2
This script is exactly what I wanted - a super easy way to convert OBS screen captures to gifs for bug reporting –
jameh
CommentedMay 8, 2020 at 21:30
Add a comment
23
Linux/Unix/macOS
Following @LordNeckbeard approach with ffmpeg command, please find the following useful Bash function which can be added into your ~/.bash_profile file:
# Convert video to gif file.
# Usage: video2gif video_file (scale) (fps)
video2gif() {
ffmpeg -y -i "${1}" -vf fps=${3:-10},scale=${2:-320}:-1:flags=lanczos,palettegen "${1}.png"
ffmpeg -i "${1}" -i "${1}.png" -filter_complex "fps=${3:-10},scale=${2:-320}:-1:flags=lanczos[x];[x][1:v]paletteuse" "${1}".gif
rm "${1}.png"
}
Once the function is loaded (manually or from . ~/.bash_profile), you should have new video2gif command.
Example usage:
video2gif input.flv
or:
video2gif input.flv 320 10
Scale to 320 width with 10 frames per second.
You can also specify a different video format (such as mp4).
macOS
You can try GIF Brewery app which can create GIFs from video files.
Alternatively there are several websites which are doing conversion online free of charge.
Share
Edit
Follow
edited Jul 12, 2023 at 14:22
Jerry Shang's user avatar
Jerry Shang
322 bronze badges
answered Dec 9, 2016 at 17:34
kenorb's user avatar
kenorb
26.2k2727 gold badges135135 silver badges208208 bronze badges
1
Thanks. Params of 1500 and 40 for me personally generate perfect quality gifs. –
Siddhartha
CommentedMar 19, 2020 at 2:51
Show 1 more comment
18
The selected answer assumes you wish to scale the source video and change its fps in the gif produced. If you do not need to do this, the following works:
src="input.flv"
dest="output.gif"
palette="/tmp/palette.png"
ffmpeg -i $src -vf palettegen -y $palette
ffmpeg -i $src -i $palette -lavfi paletteuse -y $dest
This came in handy when I wanted a gif that faithfully recreated the source video I was using.
Share
Edit
Follow
answered Nov 14, 2017 at 23:01
Jet Blue's user avatar
Jet Blue
29733 silver badges88 bronze badges
Add a comment
16
The ffmpeg with palette method can be run in a single command, without intermediary .png file.
ffmpeg -y -ss 30 -t 3 -i input.flv -filter_complex \
"fps=10,scale=320:-1:flags=lanczos[x];[x]split[x1][x2]; \
[x1]palettegen[p];[x2][p]paletteuse" output.gif
This can be done thanks to the split filter.
Share
Edit
Follow
answered Sep 30, 2017 at 15:23
Stephane's user avatar
Stephane
17111 silver badge55 bronze badges
Add a comment
11
made a script, tested and works.
usage:
./avi2gif.sh ./vokoscreen-2015-05-28_12-41-56.avi
HAVE PHUN :)
vim avi2gif.sh
#!/bin/sh
INPUT=$1
# default settings, modify if you want.
START_AT_SECOND=0; # in seconds, if you want to skip the first 30 seconds put 30 here
LENGTH_OF_GIF_VIDEO=9999999; # in seconds, how long the gif animation should be
echo "Generate a palette:"
ffmpeg -y -ss $START_AT_SECOND -t $LENGTH_OF_GIF_VIDEO -i $INPUT -vf fps=10,scale=320:-1:flags=lanczos,palettegen palette.png
echo "Output the GIF using the palette:"
ffmpeg -ss $START_AT_SECOND -t $LENGTH_OF_GIF_VIDEO -i $INPUT -i palette.png -filter_complex "fps=10,scale=320:-1:flags=lanczos[x];[x][1:v]paletteuse" $INPUT.gif
btw: vokoscreen is an EXCELLENT ScreenCapturing tool for Linux :)
THANKS A LOT Michael Kohaupt :) Rock steady.
some file size stats:
5.3M = vokoscreen-2015-04-28_15-43-17.avi -> vokoscreen-2015-05-28_12-41-56.avi.gif = 1013K
see the results here.
Share
Edit
Follow
answered May 28, 2015 at 10:55
canoodle's user avatar
canoodle
23111 gold badge33 silver badges44 bronze badges
Add a comment
9
For Windows users: create a file \Windows\video2gif.bat with this content:
@echo off
set arg1=%1
set arg2=%arg1:~0,-4%
ffmpeg -y -i %arg1% -vf fps=10,scale=-1:-1:flags=lanczos,palettegen %TEMP%\palette.png
ffmpeg -i %arg1% -i %TEMP%\palette.png -filter_complex "fps=10,scale=-1:-1:flags=lanczos[x];[x][1:v]paletteuse" %arg2%.gif
del /f %TEMP%\palette.png
And then you can use it anywhere like this:
video2gif myvideo.mp4
Then you have myvideo.gif next to your original input file. If myvideo.gif already exists, you will be asked to overwrite it.
I suggest using this versatile batch script.
Share
Edit
Follow
edited Jan 30, 2023 at 7:09
AmigoJack's user avatar
AmigoJack
10511 silver badge77 bronze badges
answered Apr 21, 2017 at 15:36
Nabi K.A.Z.'s user avatar
Nabi K.A.Z.
48711 gold badge66 silver badges1111 bronze badges
2
I see that you have done two things here: (1) written the commands as a Windows (.BAT) command script, and (2) provided a different combination of filters (none of the other answers uses both fps=10 and scale=-1:-1). Sun’s answer already gave us a batch file, and that one (like the shell scripts in pje’s answer and thevangelist’s answer) has the advantage that it assigns the list of filters to a variable (once), … (Cont’d) –
Scott - Слава Україні
CommentedApr 21, 2017 at 19:09
1
(Cont’d) … so it doesn’t need to spell out the list twice (as your batch file does). (I presume that this creates a risk that, if the user edits the script to change one of the lists but not the other, the inconsistency will cause a problem.) Can you at least explain your choice of filters (fps=10,scale=-1:-1)? (See notedible’s answer for an example of an explanation of parts of a command.) –
Scott - Слава Україні
CommentedApr 21, 2017 at 19:09
1
@Scott You said correct, so I write a new useful script in here: github.com/NabiKAZ/video2gif –
Nabi K.A.Z.
CommentedApr 23, 2017 at 6:46
1
github.com/NabiKAZ/video2gif works great even in 2022! –
Ray Hulha
CommentedMar 17, 2022 at 15:49
Add a comment
7
ffmpeg commands:
Run this command so that ffmpeg can figure out a good palette:
ffmpeg -y -i foo.mp4 -vf fps=30,scale=320:-1:flags=lanczos,palettegen palette.png
Run this command to convert the mp4 file into gif:
ffmpeg -y -i foo.mp4 -i palette.png -filter_complex "fps=30,scale=320:-1:flags=lanczos[x];[x][1:v]paletteuse" foo.gif
You might want to tweak the fps and scale. Smaller for either will result in better file size.
Making a simple alias function
You can also create an alias function like this. I added it to my .bashrc or .bash_profile:
function makegif {
ffmpeg -y -i $1 -vf fps=30,scale=320:-1:flags=lanczos,palettegen palette.png
ffmpeg -y -i $1 -i palette.png -filter_complex "fps=30,scale=320:-1:flags=lanczos[x];[x][1:v]paletteuse" $1.gif
}
And then just makegif foo
Note: You'll need ffmpeg of course. Get it here https://www.ffmpeg.org/download.html or brew install ffmpeg
Share
Edit
Follow
edited May 6, 2020 at 23:37
answered May 1, 2020 at 22:22
Aphex's user avatar
Aphex
21111 gold badge44 silver badges88 bronze badges
Show 2 more comments
6
How to add a windows 7/10 "right-click" context menu entry to convert your video file to gif
Some of the other answers mentioned the video2gif script, which I used. But, you could use any script.
To create the context-menu option, you need to edit your registry. Open a powershell command prompt, running w/ admin privs. Execute these commands:
$key = "Registry::HKEY_CLASSES_ROOT\`*\shell\Run Video2Gif"
New-Item -Path $key"\Command" -Value "C:\dev\ffmpeg\ffmpeg-3.4.2-win64-static\bin\video2gif.bat `"%1`"" -Force
Now when you right click a file you'll have a "Run Video2Gif" option!
btw I installed ffmpeg to C:\dev\ffmpeg\ffmpeg-3.4.2-win64-static\ and put the video2gif.bat script in the bin dir right next to ffmpeg.exe. I also added C:\dev\ffmpeg\ffmpeg-3.4.2-win64-static\bin to my windows PATH, but I don't think you need to.
If you want the option of being able to supply some extra command line flags / args to the script, then make a new file named video2gif-prompt.bat, and have the registry referce it instead of video2gif.bat:
@echo off
set /p inp=Enter extrta args, if desired:
C:\dev\ffmpeg\ffmpeg-3.4.2-win64-static\bin\video2gif.bat %* %inp%
You can still just hit enter to quickly get the defaults.
Share
Edit
Follow
edited Jun 12, 2020 at 13:48
Community's user avatar
CommunityBot
1
answered Apr 15, 2018 at 23:48
chris's user avatar
chris
20122 silver badges66 bronze badges
Add a comment
4
Below is the batch file for Windows users:
gifenc.bat:
set start_time=0
set duration=60
set palette="c:\temp\palette.png"
set filters="fps=15,scale=-1:-1:flags=lanczos"
ffmpeg -v warning -ss %start_time% -t %duration% -i %1 -vf "%filters%,palettegen" -y %palette%
ffmpeg -v warning -ss %start_time% -t %duration% -i %1 -i %palette% -lavfi "%filters% [x]; [x][1:v] paletteuse" -y %2
Source: High quality GIF with FFmpeg: Extracting just a sample
If you just want to use one input variable and have the output name have just the GIF (pronounced JIF) extension, then use this instead:
set start_time=0
set duration=60
set palette="c:\temp\palette.png"
set filters="fps=15,scale=-1:-1:flags=lanczos"
ffmpeg -v warning -ss %start_time% -t %duration% -i %1 -vf "%filters%,palettegen" -y %palette%
set var1=%1
set var2=%var1:~0,-4%
ffmpeg -v warning -ss %start_time% -t %duration% -i %1 -i %palette% -lavfi "%filters% [x]; [x][1:v] paletteuse" -y %var2%.gif
Share
Edit
Follow
edited Jan 11, 2017 at 16:25
answered Jun 23, 2016 at 22:31
Sun's user avatar
Sun
6,4201111 gold badges3737 silver badges5555 bronze badges
Add a comment
1
My simple trick to GIF conversion is the HandBrake/ffmpeg NLmeans filter. In HandBrake, just tick the NLMeans options in the video config tab.
It smooths out the rough GIF image, making it more easily compressable. The output looks nicer AND has a smaller size.
Share
Edit
Follow
edited Jan 28 at 1:10
galacticninja's user avatar
galacticninja
6,3221818 gold badges8282 silver badges123123 bronze badges
answered Jan 27 at 2:23
Minh Nghĩa's user avatar
Minh Nghĩa
20611 gold badge44 silver badges1515 bronze badges
Show 2 more comments
1
ImageMagick can do this simply:
convert in.mp4 out.gif
Share
Edit
Follow
answered Jul 28, 2023 at 23:06
Geremia's user avatar
Geremia
55611 gold badge77 silver badges2929 bronze badges
1
@RohitGupta The ffmpeg example in llogan's example doesn't work with ffmpeg 6.0. I get an error about lanczos deprecated or not found. –
Geremia
CommentedJul 29, 2023 at 3:11
Show 6 more comments
0
You can do:
ffmpeg -i input.mp4 output.gif
Share
Edit
Follow
answered Jan 24, 2023 at 13:05
Ronnie Smith's user avatar
Ronnie Smith
17488 bronze badges
1
This works, but it's the problem the question is trying to solve (minus time, size and rate options) - the default quality is very low –
Xen2050
CommentedMay 2 at 6:44
Add a comment
0
Simple Bash Function
My most commonly used shell command these days
Usage
makeGif inputVideo.mp4
#DESC make a high-quality gif out of a video (esp. .mp4 or .mov)
makeGif () {
if [ -z "$1" ]
then
echo "makeGif inputVideo [outputGif]"
return 244
fi
vid="$1"
if [ -z "$2" ]
then
# remove extension
outputVideo="${vid%.*}.gif"
else
outputVideo="$2"
fi
ffmpeg -i "$vid" -vf "scale=1920:-1:flags=lanczos,split[s0][s1];[s0]palettegen=max_colors=256[p];[s1][p]paletteuse=dither=floyd_steinberg" -loop 0 "$outputVideo"
echo "GIF created: $outputVideo"
}
Share
Edit
Follow
answered Sep 3 at 23:53
Connor McCormick's user avatar
Connor McCormick
21322 silver badges66 bronze badges
Add a comment
0
Using a little bit of everyone's answer, here's a bash script with params and only one ffmpeg command (and show the final file size):
#!/bin/bash
# Default values
fps=15
scale=720
# Function to display usage
usage() {
echo "Usage: $0 [--fps ] [--scale ] "
echo " --fps: Optional. Set frames per second (default: 15)"
echo " --scale: Optional. Set output width in pixels (default: 720)"
exit 1
}
# Parse optional arguments
while [[ "$#" -gt 0 ]]; do
case "$1" in
--fps)
fps="$2"
shift 2
;;
--scale)
scale="$2"
shift 2
;;
-*)
echo "Unknown option: $1"
usage
;;
*)
input_video="$1"
shift
;;
esac
done
# Check if input file is provided and ends with .mp4
if [[ -z "$input_video" || ! "$input_video" =~ \.mp4$ ]]; then
echo "Error: Input file must be specified and have a .mp4 extension"
usage
fi
# Output GIF file name
output_gif="${input_video%.mp4}.gif"
# Generate the GIF in a single command using split for palette
echo "Creating GIF with fps=$fps and scale=$scale"
# ffmpeg -i "$input_video" -vf "fps=$fps,scale=${scale}:-1:flags=lanczos,split[s0][s1];[s0]palettegen[p];[s1][p]paletteuse" "$output_gif"
ffmpeg -i "$input_video" -vf "fps=$fps,scale=${scale}:-1:flags=lanczos,split[s0][s1];[s0]palettegen=max_colors=256[p];[s1][p]paletteuse=dither=floyd_steinberg" "$output_gif"
gif_size=$(stat -c %s "$output_gif" | numfmt --to=iec)
echo "Conversion complete: $output_gif (fps=$fps, scale=$scale, size=${gif_size})"
Example Usage:
mp4togif --fps 10 --scale 720 myvideo.mp4
--fps: Optional. Set frames per second (default: 15)
--scale: Optional. Set output width in pixels (default: 720)
a spec called endurance, measured as the cumulative amount of data written and erased in its lifetime, as total bytes written (TBW), or alternatively the total number of program and erase cycles (P/E) per unit memory and unit time. When the endurance limit is reached, the flash becomes unreliable or dead. Although endurance is mostly not specified on flash drives, it is as real and as important as it is with SSDs.
In some high-quality USB sticks, its firmware keeps track of this endurance. When this maximum figure is nearly reached, or a predetermined amount of errors occur during writes and reads, it automatically puts the stick in read-only mode. The idea here is to give you a chance to copy or backup all data on the wretched stick before it totally dies.
When this happens, there is nothing you can do to remove the read-only mode. Just backup its contents to a new stick pronto, before it bites the dust. USB sticks are cheap commodities; your manhours are more expensive than them so stop trying to remove read-only. Everything and everyone dies at some point, and USB sticks are no exception.
This is also the difference between high quality expensive sticks, and fake ali- or temu-bought or fleamarket or dollar-store sticks: unlike the former which goes into a read-only mode to give you a chance to backup its precious contents, the latter very abruptly dies just like that, taking all your precious data with it, and leaving you howling and shaking in abject disgust.