Answers.Body: <p>Well, now the default behavior of current/latest ffmpeg via:</p>
  <pre><code>c:\sbin\ffmpeg.exe -i &quot;D:\video.m4s&quot; -i &quot;\audio.m4s&quot; -c:v copy -c:a copy &quot;D:\combined.mp4&quot;
  </code></pre>
  <p>is padding/looping the last frame of the video until <code>audio.length</code> === <code>video.length</code>.</p>
  <p>See if this is acceptable for you.</p>
  <p>For details behavior:</p>
  <ul>
  <li>if (<code>audio.length</code> &lt; <code>video.length</code>), then pad the audio with silent, so that <code>audio.length === video.length</code></li>
  <li>if (<code>audio.length</code> &gt; v<code>ideo.length</code>), then pad the video with the last frame of this video, so that <code>audio.length === video.length</code></li>
  </ul>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-08-09T15:08:50.320Z
Answers.LastActivityDate: 2021-08-09T15:08:50.320Z
Answers.UserDisplayName: Chen Tian
Answers.Body: <p>For video, stream_loop option should be used.</p>
  
  <pre><code>ffmpeg -y -stream_loop -1 -i video -i audio.mp3 -fflags +shortest -max_interleave_delta 50000 -c copy output.mp4
  </code></pre>
  
  <p>You'll have to use a very recent version of ffmpeg (> Nov '17) as stream_loop had a bug, only recently fixed.</p>
  
  <p>Since video encoding is expensive in terms of time and CPU, I've used streamcopy. For most videos, this is fine. Else, you'll have to re-encode.</p>
  
  <hr>
  
  <p><strong>Edit</strong>: another bug related to stream_loop, see workaround below</p>
  
  <pre><code>ffmpeg  -stream_loop -1 -i 1.mp4 -c copy -v 0 -f nut - | ffmpeg -thread_queue_size 10K -i - -i 1.mp3 -c copy -map 0:v -map 1:a -shortest -y out.mp4
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-02-11T20:18:46.497Z
Answers.Text: Hello. This just strips the audio to the length of video, I meant opposite. Loop video throughout to the length of the audio. For now I'm using solution at https://video.stackexchange.com/questions/12905/repeat-loop-input-video-with-ffmpeg
Answers.UserDisplayName: user3108268
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-02-12T05:23:59.133Z
Answers.Text: Use edited command.
Answers.UserDisplayName: Gyan
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-02-12T22:16:05.873Z
Answers.Text: I set the `video` part to video.mp4, video plays until it's original length and stops while audio keeps going, video just stills last frame throughout.
Answers.UserDisplayName: user3108268
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-02-13T05:05:41.467Z
Answers.Text: Share full log.
Answers.UserDisplayName: Gyan
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-02-13T13:20:30.480Z
Answers.Text: https://pastebin.com/nEcsD7H7 included MediaInfo, as you can see video and audio lengths differ.
Answers.UserDisplayName: user3108268
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-02-13T16:04:28.927Z
Answers.Text: See new command at end
Answers.UserDisplayName: Gyan
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-02-11T16:02:19.937Z
Answers.LastActivityDate: 2018-02-13T16:04:18.227Z
Answers.LastEditDate: 2018-02-13T16:04:18.227Z
Answers.UserDisplayName: Gyan
Body: <p>E.g. if video is 1 minute, but audio is 1 hour. Make video loop throughout for 1 hour of the audio track.</p>
  
  <p>I use this solution to loop image through the lenght of the audio</p>
  
  <pre><code>ffmpeg -y -loop 1 -r 6 -i image.jpg -i audio.mp3 -shortest -c:v libx264 -preset ultrafast -tune stillimage -pix_fmt yuv420p -c:a copy output.mp4
  </code></pre>
  
  <p>But it doesn't work for video, replacing image.jpg with video.mp4 will give error <code>no loop found</code>.</p>
  
Tags: <video><ffmpeg><audio><mp4><h.264>
Title: FFMPEG: Loop video to the length of audio
UserDisplayName: user3108268
ThreadText: # FFMPEG: Loop video to the length of audio
  
  (Asked by: username_0 on 2018-02-11)
  
  E.g. if video is 1 minute, but audio is 1 hour. Make video loop throughout for 1 hour of the audio track.
  
  I use this solution to loop image through the lenght of the audio
  
  ```
  ffmpeg -y -loop 1 -r 6 -i image.jpg -i audio.mp3 -shortest -c:v libx264 -preset ultrafast -tune stillimage -pix_fmt yuv420p -c:a copy output.mp4
  
  ```
  
  But it doesn't work for video, replacing image.jpg with video.mp4 will give error `no loop found`.
  
  **Tags:** video, ffmpeg, audio, mp4, h.264
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_2 on 2018-02-11. Score: 9 | Accepted answer
  
  For video, stream\_loop option should be used.
  
  ```
  ffmpeg -y -stream_loop -1 -i video -i audio.mp3 -fflags +shortest -max_interleave_delta 50000 -c copy output.mp4
  
  ```
  
  You'll have to use a very recent version of ffmpeg (> Nov '17) as stream\_loop had a bug, only recently fixed.
  
  Since video encoding is expensive in terms of time and CPU, I've used streamcopy. For most videos, this is fine. Else, you'll have to re-encode.
  
  ---
  
  **Edit**: another bug related to stream\_loop, see workaround below
  
  ```
  ffmpeg  -stream_loop -1 -i 1.mp4 -c copy -v 0 -f nut - | ffmpeg -thread_queue_size 10K -i - -i 1.mp3 -c copy -map 0:v -map 1:a -shortest -y out.mp4
  
  ```
  
  > **Comments:**
  > **username_0**: Hello. This just strips the audio to the length of video, I meant opposite. Loop video throughout to the length of the audio. For now I'm using solution at https://video.stackexchange.com/questions/12905/repeat-loop-input-video-with-ffmpeg  
  > **username_2**: Use edited command.  
  > **username_0**: I set the `video` part to video.mp4, video plays until it's original length and stops while audio keeps going, video just stills last frame throughout.  
  > **username_2**: Share full log.  
  > **username_0**: https://pastebin.com/nEcsD7H7 included MediaInfo, as you can see video and audio lengths differ.  
  > **username_2**: See new command at end  
  
  ---
  
  ### Answer by username_1 on 2021-08-09. Score: 1
  
  Well, now the default behavior of current/latest ffmpeg via:
  
  ```
  c:\sbin\ffmpeg.exe -i "D:\video.m4s" -i "\audio.m4s" -c:v copy -c:a copy "D:\combined.mp4"
  
  ```
  
  is padding/looping the last frame of the video until `audio.length` === `video.length`.
  
  See if this is acceptable for you.
  
  For details behavior:
  
  * if (`audio.length` < `video.length`), then pad the audio with silent, so that `audio.length === video.length`
  * if (`audio.length` > v`ideo.length`), then pad the video with the last frame of this video, so that `audio.length === video.length`
  
  
  ---
  
  