Changes between Version 9 and Version 10 of Create a video slideshow from images


Ignore:
Timestamp:
Aug 15, 2013, 2:21:16 AM (3 years ago)
Author:
llogan
Comment:

cleanup and expansion

Legend:

Unmodified
Added
Removed
Modified
  • Create a video slideshow from images

    v9 v10  
    1 This will create a video slideshow (using video codec libx264) from series of PNG images, named named img001.png, img002.png, img003.png, …  
     1== Frame rates == 
    22 
    3 Here, each image will have a duration of 5 seconds (the inverse of 1/5 frames per second). By telling FFmpeg to set the input file's FPS option (frames per second) to some very low value, we made FFmpeg duplicate frames at the output and thus we achieved to display each image for some time on screen: 
     3This will create a video slideshow (using the encoder `libx264`) from series of numerically sequential PNG images named `img001.png`, `img002.png`, `img003.png`, etc. 
     4 
     5In this example each image will have a duration of 5 seconds (the inverse of 1/5 frames per second). By using a separate `-r` (frames per second) 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 `-r` is lower than the output `-r` ffmpeg will duplicate frames to reach your desired output frame rate. If the input `-r` is higher than the output `-r` ffmpeg will drop frames to reach your desired output frame rate. 
     6 
     7If you want the input and output frame rates to be the same, then just declare an input `-r` and the output will inherit the same value. 
     8 
     9Default for input is `-r 25` which will be used if no `-r` is used. 
     10 
    411{{{ 
    5 ffmpeg -f image2 -r 1/5 -i img%03d.png -c:v libx264 -r 30 out.mp4 
     12ffmpeg -r 1/5 -i img%03d.png -c:v libx264 -r 30 -pix_fmt yuv420p out.mp4 
    613}}} 
    714 
    815This will create a slideshow in which each image has a duration of 15 seconds: 
     16 
    917{{{ 
    10 ffmpeg -f image2 -r 1/15 -i img%03d.png -c:v libx264 -r 30 out.mp4 
    11 }}} 
    12  
    13 If you don't have images numbered and ordered in series (img001.jpg, img002.jpg, img003.jpg) but rather random bunch of images, ffmpeg also supports bash-style globbing (`*` represents any number of any characters): 
    14 {{{ 
    15 ffmpeg -f image2 -r 1 -pattern_type glob -i '*.jpg' -c:v libx264 out.mp4 
    16 }}} 
    17 or for png images: 
    18 {{{ 
    19 ffmpeg -f image2 -r 1 -pattern_type glob -i '*.png' -c:v libx264 out.mp4 
     18ffmpeg -r 1/15 -i img%03d.png -c:v libx264 -r 30 -pix_fmt yuv420p out.mp4 
    2019}}} 
    2120 
    2221'''Important:''' All images in a series need to be of the same size and format. 
    2322 
    24 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`): 
     23== Color space conversion and chroma sub-sampling == 
     24 
     25By 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 and many online video services only support YUV 4:2:0. PNG uses the RGB color space, so when using PNG images as your input you must add `-pix_fmt yuv420p` or `-vf format=yuv420p` if you want maximum compatibility. You can omit this if you are using JPG images as inputs. 
     26 
     27== Using a glob pattern == 
     28 
     29ffmpeg 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. 
     30 
    2531{{{ 
    26 ffmpeg -loop 1 -f image2 -i img.png -c:v libx264 -t 30 out.mp4 
     32ffmpeg -r 1 -pattern_type glob -i '*.jpg' -c:v libx264 out.mp4 
    2733}}} 
    2834 
     35For PNG images: 
     36 
     37{{{ 
     38ffmpeg -r 1 -pattern_type glob -i '*.png' -c:v libx264 -pix_fmt yuv420p out.mp4 
     39}}} 
     40 
     41== Using a single image as an input == 
     42 
     43If 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`): 
     44 
     45{{{ 
     46ffmpeg -loop 1 -i img.png -c:v libx264 -t 30 -pix_fmt yuv420p out.mp4 
     47}}} 
     48 
     49== Adding audio == 
     50 
    2951If you want to add audio (e.g. `audio.wav`) to one "poster" image, you need `-shortest` to tell it to stop after the audio stream is finished. We use the internal AAC encoder, but you can [[AACEncodingGuide|use any other AAC encoder]] as well: 
     52 
    3053{{{ 
    31 ffmpeg -loop 1 -f image2 -i img.png -i audio.wav -c:v libx264 -c:a aac -strict experimental -b:a 192k -shortest out.mp4 
     54ffmpeg -loop 1 -i img.jpg -i audio.wav -c:v libx264 -c:a aac -strict experimental -b:a 192k -shortest out.mp4 
    3255}}} 
    3356 
    3457 
    35 '''See also:''' 
    36 [[Create a thumbnail image every X seconds of the video]] 
     58== See also == 
     59* [[Create a thumbnail image every X seconds of the video]] 
     60* [[x264EncodingGuide|x264 Encoding Guide]]