Answers.Body: <p>This was due to an imperfect implementation of -shortest, now rectified in version 5.0. So, upgrade.</p>
  <hr />
  <pre><code>ffmpeg -loop 1 -i MyInputImage.png -t 2 -c:v libx264 -pix_fmt yuv420p ^
     imagevideo.mp4
  
  ffmpeg -stream_loop -1 -i imagevideo.mp4 -i MyInputSound.m4a ^
     -c copy -shortest MyOutputVideo.mp4
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-06-25T04:18:23.750Z
Answers.Text: "ffmpeg -version" does not show version? ffmpeg version 2022-05-19-git-dd99d34d67-essentials_build-www.gyan.dev Copyright (c) 2000-2022 the FFmpeg developers
  built with gcc 11.3.0 (Rev1, Built by MSYS2 project)
  configuration: --enable-gpl
  libavutil      57. 24.101 / 57. 24.101
  libavcodec     59. 28.100 / 59. 28.100
  libavformat    59. 24.100 / 59. 24.100
  libavdevice    59.  6.100 / 59.  6.100
  libavfilter     8. 38.100 /  8. 38.100
  libswscale      6.  6.100 /  6.  6.100
  libswresample   4.  6.100 /  4.  6.100
  libpostproc    56.  5.100 / 56.  5.100
Answers.UserDisplayName: joedotnot
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-06-25T04:37:51.463Z
Answers.Text: That's a git build from 2022-05-19 so newer than 5.0 which was released on 2022-01-14
Answers.UserDisplayName: Gyan
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-07-03T07:15:56.787Z
Answers.Text: FYI I accepted your answer, but It never resolved the issue, I just ignored the BUGGY shortest cmd; Today I tried again, my audio is 18 secs long, but the video is 20 secs long (exactly as per my original question); And I used the build exactly as you see in my previous comment.
Answers.UserDisplayName: joedotnot
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-07-03T08:34:42.403Z
Answers.Text: Ok, so I rechecked and it seems the bug fix only works for streamcopy. Use commands in answer edit.
Answers.UserDisplayName: Gyan
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-07-03T09:38:37.187Z
Answers.Text: I don't understand your edited answer, you are doing a short video for 2 secs (-t 2) and then you are adding the sound and using -shortest. So the final output will always be 2 secs ? (even if the sound is longer)
Answers.UserDisplayName: joedotnot
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-07-03T09:56:27.047Z
Answers.Text: Edited to add looping.
Answers.UserDisplayName: Gyan
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-07-03T10:05:24.923Z
Answers.Text: Ok makes sense now; I may as well just use my original question, and instead of using -shortest, I will use -t secs (because I already know the length of my audio)
Answers.UserDisplayName: joedotnot
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-07-03T11:10:08.223Z
Answers.Text: You can still use -shortest in your original cmd but add `-fflags +shortest -max_interleave_delta 200M`
Answers.UserDisplayName: Gyan
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-06-07T06:16:04.527Z
Answers.Text: @Gyan 1) that only decreased the overextension for me, it did not eliminate it. 2) This is ridiculous.
Answers.UserDisplayName: Chris_F
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-06-03T14:10:11.980Z
Answers.LastActivityDate: 2022-07-03T09:56:12.577Z
Answers.LastEditDate: 2022-07-03T09:56:12.577Z
Answers.UserDisplayName: Gyan
Answers.Body: <p>I was lucky to find the version that works as expected. This one:</p>
  <ul>
  <li><strong>ffmpeg version 2023-04-17-git-65e537b833-essentials_build-www.gyan.dev</strong></li>
  </ul>
  <p>... or any other before Dec 2023</p>
  <p>On my Win7, most recent (april-october 2024) builds together with some rare old ones (2017) give totally random lengths. Like, 6 minutes of still image may become a 19 minute video. These were tested and failed:</p>
  <ul>
  <li>ffmpeg 2024-10-27-git-bb57b78013-essentials_build-www.gyan.dev</li>
  <li>ffmpeg N-114545-g199c479b9a-20240331 by BtbN</li>
  <li>ffmpeg N-86383-g4705edb</li>
  </ul>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-10-29T12:39:24.483Z
Answers.LastActivityDate: 2024-10-30T16:23:09.637Z
Answers.LastEditDate: 2024-10-30T16:23:09.637Z
Answers.UserDisplayName: postscripter
Answers.Body: <p>Also this workaround works in 2024. If we add two empty complex filters for audio and video, the total lengths become equal:</p>
  <pre><code>-filter_complex &quot;[1:v]null[v]&quot; -filter_complex &quot;[0:a]anull[a]&quot; -map &quot;[v]&quot; -map &quot;[a]&quot;
  </code></pre>
  <p>As for looping still images, there are at least three ways to achieve it in ffmpeg:</p>
  <ol>
  <li>-loop 1</li>
  <li>-stream_loop -1</li>
  <li>-vf tpad=stop_mode=clone:stop_duration=3600100</li>
  </ol>
  <p>Some may work in the given specific environment, some will fail. Curiously the last one used to give me a speed boost in 2023 build, but not in 2024.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-10-29T13:18:23.923Z
Answers.LastActivityDate: 2024-10-30T04:45:22.550Z
Answers.LastEditDate: 2024-10-30T04:45:22.550Z
Answers.UserDisplayName: postscripter
Body: <p>I am using the following command to make a video from a single image;</p>
  <pre><code>ffmpeg -loop 1 -i MyInputImage.png -i MyInputSound.m4a ^
    -c:v libx264 -pix_fmt yuv420p -c:a aac ^
    -shortest MyOutputVideo.mp4
  </code></pre>
  <p>Note that I have used the <em><strong>-shortest</strong></em> option;</p>
  <p>But I have noticed my resulting video IS ALWAYS 2 seconds longer than my AUDIO length. Why ?</p>
  <p>For example, if audio=5 secs, output vid lenght is 7 secs; if audio=9 secs, output video is 11 seconds long.</p>
  
Tags: <ffmpeg>
Title: Resultant Video is always longer than input audio, even though I am using -shortest option of ffmpeg
UserDisplayName: joedotnot
ThreadText: # Resultant Video is always longer than input audio, even though I am using -shortest option of ffmpeg
  
  (Asked by: username_0 on 2022-05-28)
  
  I am using the following command to make a video from a single image;
  
  ```
  ffmpeg -loop 1 -i MyInputImage.png -i MyInputSound.m4a ^
    -c:v libx264 -pix_fmt yuv420p -c:a aac ^
    -shortest MyOutputVideo.mp4
  
  ```
  
  Note that I have used the ***-shortest*** option;
  
  But I have noticed my resulting video IS ALWAYS 2 seconds longer than my AUDIO length. Why ?
  
  For example, if audio=5 secs, output vid lenght is 7 secs; if audio=9 secs, output video is 11 seconds long.
  
  **Tags:** ffmpeg
  
  
  ---
  
  ## 3 answers
  
  ### Answer by username_1 on 2022-06-03. Score: 0 | Accepted answer
  
  This was due to an imperfect implementation of -shortest, now rectified in version 5.0. So, upgrade.
  
  ---
  
  ```
  ffmpeg -loop 1 -i MyInputImage.png -t 2 -c:v libx264 -pix_fmt yuv420p ^
     imagevideo.mp4
  
  ffmpeg -stream_loop -1 -i imagevideo.mp4 -i MyInputSound.m4a ^
     -c copy -shortest MyOutputVideo.mp4
  
  ```
  
  > **Comments:**
  > **username_0**: "ffmpeg -version" does not show version? ffmpeg version 2022-05-19-git-dd99d34d67-essentials_build-www.username_1.dev Copyright (c) 2000-2022 the FFmpeg developers built with gcc 11.3.0 (Rev1, Built by MSYS2 project) configuration: --enable-gpl libavutil      57. 24.101 / 57. 24.101 libavcodec     59. 28.100 / 59. 28.100 libavformat    59. 24.100 / 59. 24.100 libavdevice    59.  6.100 / 59.  6.100 libavfilter     8. 38.100 /  8. 38.100 libswscale      6.  6.100 /  6.  6.100 libswresample   4.  6.100 /  4.  6.100 libpostproc    56.  5.100 / 56.  5.100  
  > **username_1**: That's a git build from 2022-05-19 so newer than 5.0 which was released on 2022-01-14  
  > **username_0**: FYI I accepted your answer, but It never resolved the issue, I just ignored the BUGGY shortest cmd; Today I tried again, my audio is 18 secs long, but the video is 20 secs long (exactly as per my original question); And I used the build exactly as you see in my previous comment.  
  > **username_1**: Ok, so I rechecked and it seems the bug fix only works for streamcopy. Use commands in answer edit.  
  > **username_0**: I don't understand your edited answer, you are doing a short video for 2 secs (-t 2) and then you are adding the sound and using -shortest. So the final output will always be 2 secs ? (even if the sound is longer)  
  > **username_1**: Edited to add looping.  
  > **username_0**: Ok makes sense now; I may as well just use my original question, and instead of using -shortest, I will use -t secs (because I already know the length of my audio)  
  > **username_1**: You can still use -shortest in your original cmd but add `-fflags +shortest -max_interleave_delta 200M`  
  > **username_2**: @username_1 1) that only decreased the overextension for me, it did not eliminate it. 2) This is ridiculous.  
  
  ---
  
  ### Answer by username_3 on 2024-10-29. Score: 0
  
  I was lucky to find the version that works as expected. This one:
  
  * **ffmpeg version 2023-04-17-git-65e537b833-essentials\_build-www.username_1.dev**
  
  ... or any other before Dec 2023
  
  On my Win7, most recent (april-october 2024) builds together with some rare old ones (2017) give totally random lengths. Like, 6 minutes of still image may become a 19 minute video. These were tested and failed:
  
  * ffmpeg 2024-10-27-git-bb57b78013-essentials\_build-www.username_1.dev
  * ffmpeg N-114545-g199c479b9a-20240331 by BtbN
  * ffmpeg N-86383-g4705edb
  
  
  ---
  
  ### Answer by username_3 on 2024-10-29. Score: 0
  
  Also this workaround works in 2024. If we add two empty complex filters for audio and video, the total lengths become equal:
  
  ```
  -filter_complex "[1:v]null[v]" -filter_complex "[0:a]anull[a]" -map "[v]" -map "[a]"
  
  ```
  
  As for looping still images, there are at least three ways to achieve it in ffmpeg:
  
  1. -loop 1
  2. -stream\_loop -1
  3. -vf tpad=stop\_mode=clone:stop\_duration=3600100
  
  Some may work in the given specific environment, some will fail. Curiously the last one used to give me a speed boost in 2023 build, but not in 2024.
  
  
  ---
  
  