Answers.Body: <ol>
  <li><p>Your <code>ffmpeg</code> is old. Update it before doing anything else. See <a href="https://ffmpeg.org/download.html" rel="nofollow noreferrer">FFmpeg Downloads</a> for links to builds for Linux, Windows, and macOS.</p></li>
  <li><p>Use <code>-framerate</code> instead of <code>-r</code> for input.</p></li>
  <li><p>Change <code>-acodec libvo_aacenc</code> to <code>-c:a aac</code>. libvoaac_enc is a low quality encoder and support for it has been removed from FFmpeg.</p></li>
  <li><p>Some players do not like a low frame rate. Declare an output frame rate with <code>-r</code> or the fps filter when the input <code>-framerate</code> is below ~5 fps.</p></li>
  <li><p>Use <a href="https://trac.ffmpeg.org/wiki/Encode/H.264" rel="nofollow noreferrer"><code>-crf</code> instead of <code>-b</code> / <code>-b:v</code></a>.</p></li>
  <li><p>Output MP4 instead of AVI.</p></li>
  </ol>
  
  <p>Example command:</p>
  
  <pre><code>ffmpeg -y -pattern_type glob -loop 1 -framerate 1/4 -i "folder/*.jpg"  -i "folder/voice.mp3" -c:v libx264 -preset veryslow -crf 22 -pix_fmt yuv420p -r 25 -shortest -movflags +faststart folder.mp4
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-01-07T21:43:37.947Z
Answers.LastActivityDate: 2019-01-07T21:43:37.947Z
Answers.UserDisplayName: llogan
Answers.Body: <p><strong>Minimal runnable example</strong></p>
  <p>Extracted from this other answer: <a href="https://stackoverflow.com/questions/24961127/how-to-create-a-video-from-images-with-ffmpeg/37478183#37478183">https://stackoverflow.com/questions/24961127/how-to-create-a-video-from-images-with-ffmpeg/37478183#37478183</a></p>
  <p><a href="https://en.wikipedia.org/wiki/Human_evolution#History_of_study" rel="nofollow noreferrer">Inspired by this timeline</a>.</p>
  <p>Get the input media:</p>
  <pre><code>mkdir -p orig
  cd orig
  wget -O 1.png https://upload.wikimedia.org/wikipedia/commons/2/22/Australopithecus_afarensis.png
  wget -O 2.jpg https://upload.wikimedia.org/wikipedia/commons/6/61/Homo_habilis-2.JPG
  wget -O 3.jpg https://upload.wikimedia.org/wikipedia/commons/c/cb/Homo_erectus_new.JPG
  wget -O 4.png https://upload.wikimedia.org/wikipedia/commons/1/1f/Homo_heidelbergensis_-_forensic_facial_reconstruction-crop.png
  wget -O 5.jpg https://upload.wikimedia.org/wikipedia/commons/thumb/5/5a/Sabaa_Nissan_Militiaman.jpg/450px-Sabaa_Nissan_Militiaman.jpg
  wget -O audio.ogg https://upload.wikimedia.org/wikipedia/commons/7/74/Alnitaque_%26_Moon_Shot_-_EURO_%28Extended_Mix%29.ogg
  cd ..
  
  # Convert all to PNG for consistency.
  # https://unix.stackexchange.com/questions/29869/converting-multiple-image-files-from-jpeg-to-pdf-format
  # Hardlink the ones that are already PNG.
  mkdir -p png
  mogrify -format png -path png orig/*.jpg
  ln -P orig/*.png png
  </code></pre>
  <p>Now we have a quick look at all image sizes to decide on the final aspect ratio:</p>
  <pre><code>identify png/*
  </code></pre>
  <p>which outputs:</p>
  <pre><code>png/1.png PNG 557x495 557x495+0+0 8-bit sRGB 653KB 0.000u 0:00.000
  png/2.png PNG 664x800 664x800+0+0 8-bit sRGB 853KB 0.000u 0:00.000
  png/3.png PNG 544x680 544x680+0+0 8-bit sRGB 442KB 0.000u 0:00.000
  png/4.png PNG 207x238 207x238+0+0 8-bit sRGB 76.8KB 0.000u 0:00.000
  png/5.png PNG 450x600 450x600+0+0 8-bit sRGB 627KB 0.000u 0:00.000
  </code></pre>
  <p>so the classic 480p (640x480 == 4/3) aspect ratio seems appropriate.</p>
  <p>Do one conversion with minimal resizing to make widths even (TODO
  automate for any width, here I just manually looked at <code>identify</code> output and reduced width and height by one):</p>
  <pre><code>mkdir -p raw
  convert png/1.png -resize 556x494 raw/1.png
  ln -P png/2.png png/3.png png/4.png png/5.png raw
  ffmpeg -framerate 1 -pattern_type glob -i 'raw/*.png' -i orig/audio.ogg -c:v libx264 -c:a copy -shortest -r 30 -pix_fmt yuv420p raw.mp4
  </code></pre>
  <img src="https://i.sstatic.net/qc2n1.gif" width="300" />
  <p>This produces terrible output, because as seen from:</p>
  <pre><code>ffprobe raw.mp4
  </code></pre>
  <p>ffmpeg just takes the size of the first image, 556x494, and then converts all others to that exact size, breaking their aspect ratio.</p>
  <p>Now let's convert the images to the target 480p aspect ratio automatically by cropping as per <a href="https://stackoverflow.com/questions/21262466/imagemagick-how-to-minimally-crop-an-image-to-a-certain-aspect-ratio">https://stackoverflow.com/questions/21262466/imagemagick-how-to-minimally-crop-an-image-to-a-certain-aspect-ratio</a></p>
  <pre><code>mkdir -p auto
  mogrify -path auto -geometry 640x480^ -gravity center -crop 640x480+0+0 png/*.png
  ffmpeg -framerate 1 -pattern_type glob -i 'auto/*.png' -i orig/audio.ogg -c:v libx264 -c:a copy -shortest -r 30 -pix_fmt yuv420p auto.mp4
  </code></pre>
  <img src="https://i.sstatic.net/SzUlh.gif" width="300" />
  <p>So now, the aspect ratio is good, but inevitably some cropping had to be done, which kind of cut up interesting parts of the images.</p>
  <p>The other option is to pad with black background to have the same aspect ratio as shown at: <a href="https://stackoverflow.com/questions/18514083/resize-to-fit-in-a-box-and-set-background-to-black-on-empty-part/18514327">https://stackoverflow.com/questions/18514083/resize-to-fit-in-a-box-and-set-background-to-black-on-empty-part/18514327</a></p>
  <pre><code>mkdir -p black
  ffmpeg -framerate 1 -pattern_type glob -i 'black/*.png' -i orig/audio.ogg -c:v libx264 -c:a copy -shortest -r 30 -pix_fmt yuv420p black.mp4
  </code></pre>
  <img src="https://i.sstatic.net/b5gCg.gif" width="300" />
  <p>Generally speaking though, you will ideally be able to select images with the same or similar aspect ratios to avoid those problems in the first place.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-01-07T13:10:18.413Z
Answers.LastActivityDate: 2021-01-07T13:10:18.413Z
Answers.UserDisplayName: Ciro Santilli OurBigBook.com
Body: <p>I have a certain number of pictures that I want to repeat until the melody ends. The problem is that when I make settings it does not work.
  the process goes on forever</p>
  
  <pre><code>ffmpeg  -pattern_type glob -loop 1 -r:v 1/4 -i "folder/*.jpg"  -i "folder/voice.mp3" -acodec libvo_aacenc -shortest  -c:v libx264  -preset veryslow -pix_fmt yuv420p -b 20M -pix_fmt yuv420p  -y /folder.avi
  </code></pre>
  
Tags: <ffmpeg>
Title: How can I make a slideshow with ffmpeg?
UserDisplayName: Иван Иванов
ThreadText: # How can I make a slideshow with ffmpeg?
  
  (Asked by: username_0 on 2019-01-07)
  
  I have a certain number of pictures that I want to repeat until the melody ends. The problem is that when I make settings it does not work.
  the process goes on forever
  
  ```
  ffmpeg  -pattern_type glob -loop 1 -r:v 1/4 -i "folder/*.jpg"  -i "folder/voice.mp3" -acodec libvo_aacenc -shortest  -c:v libx264  -preset veryslow -pix_fmt yuv420p -b 20M -pix_fmt yuv420p  -y /folder.avi
  
  ```
  
  **Tags:** ffmpeg
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_1 on 2019-01-07. Score: 3
  
  1. Your `ffmpeg` is old. Update it before doing anything else. See [FFmpeg Downloads](https://ffmpeg.org/download.html) for links to builds for Linux, Windows, and macOS.
  2. Use `-framerate` instead of `-r` for input.
  3. Change `-acodec libvo_aacenc` to `-c:a aac`. libvoaac\_enc is a low quality encoder and support for it has been removed from FFmpeg.
  4. Some players do not like a low frame rate. Declare an output frame rate with `-r` or the fps filter when the input `-framerate` is below ~5 fps.
  5. Use [`-crf` instead of `-b` / `-b:v`](https://trac.ffmpeg.org/wiki/Encode/H.264).
  6. Output MP4 instead of AVI.
  
  Example command:
  
  ```
  ffmpeg -y -pattern_type glob -loop 1 -framerate 1/4 -i "folder/*.jpg"  -i "folder/voice.mp3" -c:v libx264 -preset veryslow -crf 22 -pix_fmt yuv420p -r 25 -shortest -movflags +faststart folder.mp4
  
  ```
  
  
  ---
  
  ### Answer by username_2 on 2021-01-07. Score: 0
  
  **Minimal runnable example**
  
  Extracted from this other answer: <https://stackoverflow.com/questions/24961127/how-to-create-a-video-from-images-with-ffmpeg/37478183#37478183>
  
  [Inspired by this timeline](https://en.wikipedia.org/wiki/Human_evolution#History_of_study).
  
  Get the input media:
  
  ```
  mkdir -p orig
  cd orig
  wget -O 1.png https://upload.wikimedia.org/wikipedia/commons/2/22/Australopithecus_afarensis.png
  wget -O 2.jpg https://upload.wikimedia.org/wikipedia/commons/6/61/Homo_habilis-2.JPG
  wget -O 3.jpg https://upload.wikimedia.org/wikipedia/commons/c/cb/Homo_erectus_new.JPG
  wget -O 4.png https://upload.wikimedia.org/wikipedia/commons/1/1f/Homo_heidelbergensis_-_forensic_facial_reconstruction-crop.png
  wget -O 5.jpg https://upload.wikimedia.org/wikipedia/commons/thumb/5/5a/Sabaa_Nissan_Militiaman.jpg/450px-Sabaa_Nissan_Militiaman.jpg
  wget -O audio.ogg https://upload.wikimedia.org/wikipedia/commons/7/74/Alnitaque_%26_Moon_Shot_-_EURO_%28Extended_Mix%29.ogg
  cd ..
  
  # Convert all to PNG for consistency.
  # https://unix.stackexchange.com/questions/29869/converting-multiple-image-files-from-jpeg-to-pdf-format
  # Hardlink the ones that are already PNG.
  mkdir -p png
  mogrify -format png -path png orig/*.jpg
  ln -P orig/*.png png
  
  ```
  
  Now we have a quick look at all image sizes to decide on the final aspect ratio:
  
  ```
  identify png/*
  
  ```
  
  which outputs:
  
  ```
  png/1.png PNG 557x495 557x495+0+0 8-bit sRGB 653KB 0.000u 0:00.000
  png/2.png PNG 664x800 664x800+0+0 8-bit sRGB 853KB 0.000u 0:00.000
  png/3.png PNG 544x680 544x680+0+0 8-bit sRGB 442KB 0.000u 0:00.000
  png/4.png PNG 207x238 207x238+0+0 8-bit sRGB 76.8KB 0.000u 0:00.000
  png/5.png PNG 450x600 450x600+0+0 8-bit sRGB 627KB 0.000u 0:00.000
  
  ```
  
  so the classic 480p (640x480 == 4/3) aspect ratio seems appropriate.
  
  Do one conversion with minimal resizing to make widths even (TODO
  automate for any width, here I just manually looked at `identify` output and reduced width and height by one):
  
  ```
  mkdir -p raw
  convert png/1.png -resize 556x494 raw/1.png
  ln -P png/2.png png/3.png png/4.png png/5.png raw
  ffmpeg -framerate 1 -pattern_type glob -i 'raw/*.png' -i orig/audio.ogg -c:v libx264 -c:a copy -shortest -r 30 -pix_fmt yuv420p raw.mp4
  
  ```
  
  ![](https://i.sstatic.net/qc2n1.gif)
  
  This produces terrible output, because as seen from:
  
  ```
  ffprobe raw.mp4
  
  ```
  
  ffmpeg just takes the size of the first image, 556x494, and then converts all others to that exact size, breaking their aspect ratio.
  
  Now let's convert the images to the target 480p aspect ratio automatically by cropping as per <https://stackoverflow.com/questions/21262466/imagemagick-how-to-minimally-crop-an-image-to-a-certain-aspect-ratio>
  
  ```
  mkdir -p auto
  mogrify -path auto -geometry 640x480^ -gravity center -crop 640x480+0+0 png/*.png
  ffmpeg -framerate 1 -pattern_type glob -i 'auto/*.png' -i orig/audio.ogg -c:v libx264 -c:a copy -shortest -r 30 -pix_fmt yuv420p auto.mp4
  
  ```
  
  ![](https://i.sstatic.net/SzUlh.gif)
  
  So now, the aspect ratio is good, but inevitably some cropping had to be done, which kind of cut up interesting parts of the images.
  
  The other option is to pad with black background to have the same aspect ratio as shown at: <https://stackoverflow.com/questions/18514083/resize-to-fit-in-a-box-and-set-background-to-black-on-empty-part/18514327>
  
  ```
  mkdir -p black
  ffmpeg -framerate 1 -pattern_type glob -i 'black/*.png' -i orig/audio.ogg -c:v libx264 -c:a copy -shortest -r 30 -pix_fmt yuv420p black.mp4
  
  ```
  
  ![](https://i.sstatic.net/b5gCg.gif)
  
  Generally speaking though, you will ideally be able to select images with the same or similar aspect ratios to avoid those problems in the first place.
  
  
  ---
  
  