Changes between Version 16 and Version 17 of Slideshow


Ignore:
Timestamp:
Dec 14, 2016, 10:30:35 PM (2 years ago)
Author:
llogan
Comment:

cleanup and reorganized. added a concat demuxer example. fixed some nits.

Legend:

Unmodified
Added
Removed
Modified
  • Slideshow

    v16 v17  
    1 [[PageOutline(2, Contents)]]
     1[[PageOutline]]
     2
     3= Basic examples =
     4
     5You 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
     9In this example the input images are sequentially named `img001.png`, `img002.png`, `img003.png`, etc.
     10
     11{{{
     12ffmpeg -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
     21For example if you want to start with `img126.png` then use the `-start_number` option:
     22
     23{{{
     24ffmpeg -start_number 126 -i img%03d.png -pix_fmt yuv420p out.mp4
     25}}}
     26
     27== Glob pattern ==
     28
     29Bash-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{{{
     32ffmpeg -framerate 10 -pattern_type glob -i '*.jpg' -c:v libx264 -pix_fmt yuv420p out.mp4
     33}}}
     34
     35The glob pattern is not available on Windows builds.
     36
     37== Pipe ==
     38
     39You can use `cat` or other tools to pipe to `ffmpeg`:
     40
     41{{{
     42cat *.png | ffmpeg -f image2pipe -i - output.mkv
     43}}}
     44
     45== Concat demuxer ==
     46
     47You 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
     49First, make a text file with the appropriate info:
     50
     51{{{
     52file '/path/to/dog.png'
     53duration 5
     54file '/path/to/cat.png'
     55duration 1
     56file '/path/to/rat.png'
     57duration 3
     58file '/path/to/tapeworm.png'
     59duration 2
     60}}}
     61
     62Then run the `ffmpeg` command:
     63
     64{{{
     65ffmpeg -f concat -i input.txt -pix_fmt yuv420p output.mp4
     66}}}
     67
     68== Single image ==
     69
     70Example with output video duration set to 30 seconds with `-t 30`:
     71
     72{{{
     73ffmpeg -loop 1 -i img.jpg -c:v libx264 -t 30 -pix_fmt yuv420p out.mp4
     74}}}
     75
     76----
     77
     78= Additional Info =
    279
    380== Frame rates ==
    481
    5 Create a video (using the encoder `libx264`) from series of numerically sequential images such as `img001.png`, `img002.png`, `img003.png`, etc.
     82You can specify two frame rates: input and output.
    683
    7 {{{
    8 #!div style="border: 1pt dotted; margin: 1em"
    9 '''Important:''' All images in a series need to be the same size and format.
    10 }}}
     84* Set input frame rate with the `-framerate` input option (before `-i`). The default for reading inputs is `-framerate 25` which will be set if no `-framerate` is specified.
     85* 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 (meaning you can omit the `-r`).'''
    1186
    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.
     87By 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.
    1888
    1989In this example each image will have a duration of 5 seconds (the inverse of 1/5 frames per second). The video stream will have a frame rate of 30 fps by duplicating the frames accordingly:
     
    2393}}}
    2494
    25 == Starting with a specific image ==
    26 
    27 For example if you want to start with `img126.png` then use the `-start_number` option:
    28 
    29 {{{
    30 ffmpeg -framerate 1/5 -start_number 126 -i img%03d.png -c:v libx264 -r 30 -pix_fmt yuv420p out.mp4
    31 }}}
     95----
    3296
    3397== If your video does not show the frames correctly ==
     
    45109}}}
    46110
     111----
     112
    47113== Color space conversion and chroma sub-sampling ==
    48114
    49115By default when using `libx264`, and depending on your input, `ffmpeg` will attempt to avoid color subsampling. Technically this is preferred, but unfortunately almost all video players, excluding FFmpeg based players, and many online video services only support the YUV color space with 4:2:0 chroma subsampling. Using the options `-pix_fmt yuv420p` or `-vf format=yuv420p` will maximize compatibility.
    50116
    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----
    72118
    73119== Adding audio ==
     
    76122
    77123{{{
    78 ffmpeg -loop 1 -i img.jpg -i audio.wav -c:v libx264 -c:a aac -strict experimental -b:a 192k -shortest out.mp4
     124ffmpeg -loop 1 -i img.jpg -i audio.wav -c:v libx264 -c:a aac -b:a 192k -shortest out.mp4
    79125}}}
    80126
    81 If your audio file is using a codec that the output container supports (e.g. MP3 audio in AVI or M4A/AAC audio in MP4), you can copy it instead of re-encoding, which will preserve the audio quality:
     127If your audio file is using a codec that the output container supports (e.g. MP3 audio in AVI or M4A/AAC audio in MP4), you can [https://ffmpeg.org/ffmpeg.html#Stream-copy stream copy] (re-mux) it instead of re-encoding, which will preserve the audio quality:
    82128
    83129{{{
     
    85131}}}
    86132
     133----
     134
    87135== Also see ==
     136
    88137* [http://ffmpeg.org/ffmpeg-formats.html#image2-2 FFmpeg image file demuxer documentation]
    89138* [[Create a thumbnail image every X seconds of the video]]