I have some images and I'd like to make an animated gif with ffmpeg.
The images have names as:
837_1.png
838_1.png
...
I'm trying to unserstand the -i command line option of ffmpeg but I am crashing against some problems.
If I don't specify anything it ask me to replace the files:
ffmpeg -i * -vcodec libx264 out.mp4
ffmpeg version 1.2.1 Copyright (c) 2000-2013 the FFmpeg developers
built on Jul 26 2013 20:18:03 with Apple LLVM version 4.2 (clang-425.0.28) (based on LLVM 3.2svn)
configuration: --prefix=/usr/local/Cellar/ffmpeg/1.2.1 --enable-shared --enable-pthreads --enable-gpl --enable-version3 --enable-nonfree --enable-hardcoded-tables --enable-avresample --enable-vda --cc=cc --host-cflags= --host-ldflags= --enable-libx264 --enable-libfaac --enable-libmp3lame --enable-libxvid
libavutil 52. 18.100 / 52. 18.100
libavcodec 54. 92.100 / 54. 92.100
libavformat 54. 63.104 / 54. 63.104
libavdevice 54. 3.103 / 54. 3.103
libavfilter 3. 42.103 / 3. 42.103
libswscale 2. 2.100 / 2. 2.100
libswresample 0. 17.102 / 0. 17.102
libpostproc 52. 2.100 / 52. 2.100
Input #0, image2, from '358_1.png':
Duration: 00:00:00.04, start: 0.000000, bitrate: N/A
Stream #0:0: Video: png, rgb24, 550x550, 25 tbr, 25 tbn, 25 tbc
File '359_1.png' already exists. Overwrite ? [y/N]
And if I try to use one of the most used format (%d) in the internet.. ffmpeg does not find the files:
fmpeg -i '%3d_1.png' -vcodec libx264 out.mp4
ffmpeg version 1.2.1 Copyright (c) 2000-2013 the FFmpeg developers
built on Jul 26 2013 20:18:03 with Apple LLVM version 4.2 (clang-425.0.28) (based on LLVM 3.2svn)
configuration: --prefix=/usr/local/Cellar/ffmpeg/1.2.1 --enable-shared --enable-pthreads --enable-gpl --enable-version3 --enable-nonfree --enable-hardcoded-tables --enable-avresample --enable-vda --cc=cc --host-cflags= --host-ldflags= --enable-libx264 --enable-libfaac --enable-libmp3lame --enable-libxvid
libavutil 52. 18.100 / 52. 18.100
libavcodec 54. 92.100 / 54. 92.100
libavformat 54. 63.104 / 54. 63.104
libavdevice 54. 3.103 / 54. 3.103
libavfilter 3. 42.103 / 3. 42.103
libswscale 2. 2.100 / 2. 2.100
libswresample 0. 17.102 / 0. 17.102
libpostproc 52. 2.100 / 52. 2.100
[image2 @ 0x7f963a006600] Could find no file with with path '%3d_1.png' and index in the range 0-4
%3d_1.png: No such file or directory
So.. here is the question, how to use the -i command line option with ffmpg?
For sake of clarity, I am on Mac OSX 10.8, ffmpeg version 1.2.1, zsh 4.3.11
Best Answer
Without any further options, ffmpeg's
image2
demuxer will look for a sequence starting with 0. It'll also check around this index, with a default range of 5 (that's why it'll complain about no index in the range 0–4). Per the documentation, you have to set the start number if you want to start at an arbitrary index, like 837.Color space in PNG to H.264 conversion
Since PNG files use the RGB color space to represent pixels, the conversion to H.264 would end up being YUV 4:4:4 (non-subsampled). The resulting video may not be playable on all players, notably anything non-FFmpeg-based. Your player would show only black frames, or possibly crash. To fix that, change the pixel format to YUV 4:2:0:
In order to control the quality, use the
-crf
option. See the x264 encoding guide for more info.Why the
*
glob does not workDon't use the
*
as an input option. The shell will expand it to all files in the current directory beforeffmpeg
sees it, so the command would expand toffmpeg -i file1 file2 … filen
. Since all input files inffmpeg
need the-i
option, it'll takefile2 … filen
as output files instead and overwrite them. Not good.