| 1 | | [[PageOutline(2, Contents)]] |
| | 1 | [[PageOutline]] |
| | 2 | |
| | 3 | = Basic examples = |
| | 4 | |
| | 5 | You can input images sequentially, with a glob pattern, via piping, or with the concat demuxer. You can also make a video from a single image. |
| | 6 | |
| | 7 | == Sequential == |
| | 8 | |
| | 9 | In this example the input images are sequentially named `img001.png`, `img002.png`, `img003.png`, etc. |
| | 10 | |
| | 11 | {{{ |
| | 12 | ffmpeg -framerate 24 -i img%03d.png output.mp4 |
| | 13 | }}} |
| | 14 | |
| | 15 | * When outputting H.264, adding `-vf format=yuv420p` or `-pix_fmt yuv420p` will ensure compatibility so crappy players can decode the video. See the [#Colorspaceconversionandchromasub-sampling colorspace and chroma-subsampling] for more info. |
| | 16 | |
| | 17 | * If `-framerate` option is omitted the default will input and output 25 frames per second. See [#Framerates Frame rates] for more info. |
| | 18 | |
| | 19 | === Starting with a specific image === |
| | 20 | |
| | 21 | For example if you want to start with `img126.png` then use the `-start_number` option: |
| | 22 | |
| | 23 | {{{ |
| | 24 | ffmpeg -start_number 126 -i img%03d.png -pix_fmt yuv420p out.mp4 |
| | 25 | }}} |
| | 26 | |
| | 27 | == Glob pattern == |
| | 28 | |
| | 29 | Bash-style globbing (`*` represents any number of any characters) is useful if your images are sequential but not necessarily in a numerically sequential order as in the previous example. |
| | 30 | |
| | 31 | {{{ |
| | 32 | ffmpeg -framerate 10 -pattern_type glob -i '*.jpg' -c:v libx264 -pix_fmt yuv420p out.mp4 |
| | 33 | }}} |
| | 34 | |
| | 35 | The glob pattern is not available on Windows builds. |
| | 36 | |
| | 37 | == Pipe == |
| | 38 | |
| | 39 | You can use `cat` or other tools to pipe to `ffmpeg`: |
| | 40 | |
| | 41 | {{{ |
| | 42 | cat *.png | ffmpeg -f image2pipe -i - output.mkv |
| | 43 | }}} |
| | 44 | |
| | 45 | == Concat demuxer == |
| | 46 | |
| | 47 | You can use the [https://ffmpeg.org/ffmpeg-formats.html#concat concat demuxer] to manually order images and to provide a specific duration for each image. |
| | 48 | |
| | 49 | First, make a text file with the appropriate info: |
| | 50 | |
| | 51 | {{{ |
| | 52 | file '/path/to/dog.png' |
| | 53 | duration 5 |
| | 54 | file '/path/to/cat.png' |
| | 55 | duration 1 |
| | 56 | file '/path/to/rat.png' |
| | 57 | duration 3 |
| | 58 | file '/path/to/tapeworm.png' |
| | 59 | duration 2 |
| | 60 | }}} |
| | 61 | |
| | 62 | Then run the `ffmpeg` command: |
| | 63 | |
| | 64 | {{{ |
| | 65 | ffmpeg -f concat -i input.txt -pix_fmt yuv420p output.mp4 |
| | 66 | }}} |
| | 67 | |
| | 68 | == Single image == |
| | 69 | |
| | 70 | Example with output video duration set to 30 seconds with `-t 30`: |
| | 71 | |
| | 72 | {{{ |
| | 73 | ffmpeg -loop 1 -i img.jpg -c:v libx264 -t 30 -pix_fmt yuv420p out.mp4 |
| | 74 | }}} |
| | 75 | |
| | 76 | ---- |
| | 77 | |
| | 78 | = Additional Info = |
| 12 | | You can specify two frame rates: |
| 13 | | |
| 14 | | * The rate according to which the images are read, by setting `-framerate` before `-i`. The default for reading input is `-framerate 25` which will be set if no `-framerate` is specified. |
| 15 | | * The output frame rate for the video stream by setting `-r` after `-i` or by using the `fps` filter. If you want the input and output frame rates to be the same, then just declare an input `-framerate` and the output will inherit the same value. |
| 16 | | |
| 17 | | By using a separate frame rate for the input and output you can control the duration at which each input is displayed and tell `ffmpeg` the frame rate you want for the output file. If the input `-framerate` is lower than the output `-r` then `ffmpeg` will duplicate frames to reach your desired output frame rate. If the input `-framerate` is higher than the output `-r` then `ffmpeg` will drop frames to reach your desired output frame rate. |
| | 87 | By using a separate frame rate for the input and output you can control the duration at which each input is displayed and tell `ffmpeg` the frame rate you want for the output file. This is useful if your player cannot handle a non-standard frame rate. If the input `-framerate` is lower than the output `-r` then `ffmpeg` will duplicate frames to reach your desired output frame rate. If the input `-framerate` is higher than the output `-r` then `ffmpeg` will drop frames to reach your desired output frame rate. |
| 51 | | == Using a glob pattern == |
| 52 | | |
| 53 | | ffmpeg also supports bash-style globbing (`*` represents any number of any characters). This is useful if your images are sequential but not necessarily in a numerically sequential order as in the previous examples. |
| 54 | | |
| 55 | | {{{ |
| 56 | | ffmpeg -framerate 1 -pattern_type glob -i '*.jpg' -c:v libx264 out.mp4 |
| 57 | | }}} |
| 58 | | |
| 59 | | For PNG images: |
| 60 | | |
| 61 | | {{{ |
| 62 | | ffmpeg -framerate 1 -pattern_type glob -i '*.png' -c:v libx264 -pix_fmt yuv420p out.mp4 |
| 63 | | }}} |
| 64 | | |
| 65 | | == Using a single image as an input == |
| 66 | | |
| 67 | | If you want to create a video out of just one image, this will do (output video duration is set to 30 seconds with `-t 30`): |
| 68 | | |
| 69 | | {{{ |
| 70 | | ffmpeg -loop 1 -i img.png -c:v libx264 -t 30 -pix_fmt yuv420p out.mp4 |
| 71 | | }}} |
| | 117 | ---- |