Answers.Body: <p>To merge an audio stream with a repeated video stream</p>
  <pre><code>ffmpeg -stream_loop -1 -i 20s.ts -i 120s.mp3 -map 0:v:0 -map 1:a:0 -shortest -c copy output.mp4
  </code></pre>
  <ul>
  <li>-stream_loop -1 : to loop infinity of video input stream</li>
  <li>-map 0:v:0 : pick the video of the first input stream</li>
  <li>-map 1:a:0 : pick the audio of the second input stream</li>
  <li>-shortest : select the shortest length of input streams, which is the audio stream since the video will be looped infinity</li>
  <li>-c copy : no video and audio transcodes.</li>
  </ul>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-03-27T15:35:33.393Z
Answers.Text: It worked, thanks!
Answers.UserDisplayName: IvanD
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-03-26T09:13:20.973Z
Answers.LastActivityDate: 2022-03-26T09:13:20.973Z
Answers.UserDisplayName: xer-rex
Body: <p>I have a 10 seconds video clip and 60 seconds audio clip, so when I mux it with</p>
  <p><code>mkvmerge --output video.mkv ./a.mp3 ./a.mp4</code></p>
  <p>The output file shows the video only for the first 10 seconds, and then the last frame is displayed for 50 seconds.</p>
  <p>How can I loop the video in automatic mode so that it repeats for the whole 60 seconds with mkvmerge or any other command line tool (I need to automate it as I have to do it for 400 files)?</p>
  
Tags: <ffmpeg><mkv>
Title: Loop video for the duration of audio
UserDisplayName: IvanD
ThreadText: # Loop video for the duration of audio
  
  (Asked by: username_0 on 2022-03-18)
  
  I have a 10 seconds video clip and 60 seconds audio clip, so when I mux it with
  
  `mkvmerge --output video.mkv ./a.mp3 ./a.mp4`
  
  The output file shows the video only for the first 10 seconds, and then the last frame is displayed for 50 seconds.
  
  How can I loop the video in automatic mode so that it repeats for the whole 60 seconds with mkvmerge or any other command line tool (I need to automate it as I have to do it for 400 files)?
  
  **Tags:** ffmpeg, mkv
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2022-03-26. Score: 4 | Accepted answer
  
  To merge an audio stream with a repeated video stream
  
  ```
  ffmpeg -stream_loop -1 -i 20s.ts -i 120s.mp3 -map 0:v:0 -map 1:a:0 -shortest -c copy output.mp4
  
  ```
  
  * -stream\_loop -1 : to loop infinity of video input stream
  * -map 0:v:0 : pick the video of the first input stream
  * -map 1:a:0 : pick the audio of the second input stream
  * -shortest : select the shortest length of input streams, which is the audio stream since the video will be looped infinity
  * -c copy : no video and audio transcodes.
  
  > **Comments:**
  > **username_0**: It worked, thanks!  
  
  ---
  
  