Answers.Body: <blockquote>
  <p>Is the -stream_loop option actually repeating the input video clip frames to make the loop?</p>
  </blockquote>
  <p>Yes.</p>
  <blockquote>
  <p>Is there a way to tell ffmpeg to instance the input video frames when creating the loop?</p>
  </blockquote>
  <p>No.</p>
  <blockquote>
  <p>Is this actually a limitation with video formats (e.g. mp4, mkv, etc.)?</p>
  </blockquote>
  <p>For MP4s and MKVs, yes.</p>
  <blockquote>
  <p>If ffmpeg is not sufficient for this, is there some way to create a video that efficiently (with respect to file size) loops the video clip for the duration of an audio clip?</p>
  </blockquote>
  <p>Not that I know of. Some vendors like Whatsapp have customized MP4s to allow this. However, the player has to recognize and implement the proprietary loop instruction.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-10-17T05:13:28.170Z
Answers.Text: In theory, one can use custom edit lists in MP4s to implement this in a backward compatible way, but I don't know of a tool that does so.
Answers.UserDisplayName: Gyan
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-10-17T05:11:34.987Z
Answers.LastActivityDate: 2021-10-17T05:11:34.987Z
Answers.UserDisplayName: Gyan
Body: <p>I am attempting to create a video loop by merging a 15 second video with about 4 minutes of audio. After finding a <a href="https://stackoverflow.com/questions/5015771/merge-video-and-audio-with-ffmpeg-loop-the-video-while-audio-is-not-over/55841289#55841289">similar question</a>, I found a command that loops the input video for the length of the audio, and results in a merged video file that plays like I intended.</p>
  <p><code>ffmpeg -stream_loop -1 -i loop.mp4 -i audio.mp3 -shortest -map 0:v:0 -map 1:a:0 -c copy output.mp4</code></p>
  <p>While the resulting video plays as I wanted, I noticed that the file size is much larger than I expected. I presume I am not understanding what the <em>-stream_loop</em> option is actually doing. In my case, I input a 45Mb video clip and a 6Mb audio clip, yet the resulting video is about 690Mb. The video loop repeats about 15 times before the audio is done. Since 45Mb * 15 + 6Mb is about 680Mb, it looks like <em>-stream_loop</em> is not instancing the clip, and is just repeating the memory. I expected a file size not much larger than the sum of the input files' sizes, just over 50Mb.</p>
  <p>I found several other questions and answers regarding merging a video loop with an audio track, but I didn't find anyone commenting about the resulting file size. Admittedly, I am a beginner with this process, but my expectation was the default behavior for a command that creates a loop from an input source would be to efficiently instance it whenever possible.</p>
  <ol>
  <li>Is the <em>-stream_loop</em> option actually repeating the input video clip frames to make the loop?</li>
  <li>Is there a way to tell ffmpeg to instance the input video frames when creating the loop?</li>
  <li>Is this actually a limitation with video formats (e.g. mp4, mkv, etc.)?</li>
  <li>If ffmpeg is not sufficient for this, is there some way to create a video that efficiently (with respect to file size) loops the video clip for the duration of an audio clip?</li>
  </ol>
  
Tags: <ffmpeg><video><audio><encoding><memory>
Title: FFmpeg Optimized File Size Video Loop
UserDisplayName: CgRobot
ThreadText: # FFmpeg Optimized File Size Video Loop
  
  (Asked by: username_0 on 2021-10-17)
  
  I am attempting to create a video loop by merging a 15 second video with about 4 minutes of audio. After finding a [similar question](https://stackoverflow.com/questions/5015771/merge-video-and-audio-with-ffmpeg-loop-the-video-while-audio-is-not-over/55841289#55841289), I found a command that loops the input video for the length of the audio, and results in a merged video file that plays like I intended.
  
  `ffmpeg -stream_loop -1 -i loop.mp4 -i audio.mp3 -shortest -map 0:v:0 -map 1:a:0 -c copy output.mp4`
  
  While the resulting video plays as I wanted, I noticed that the file size is much larger than I expected. I presume I am not understanding what the *-stream\_loop* option is actually doing. In my case, I input a 45Mb video clip and a 6Mb audio clip, yet the resulting video is about 690Mb. The video loop repeats about 15 times before the audio is done. Since 45Mb \* 15 + 6Mb is about 680Mb, it looks like *-stream\_loop* is not instancing the clip, and is just repeating the memory. I expected a file size not much larger than the sum of the input files' sizes, just over 50Mb.
  
  I found several other questions and answers regarding merging a video loop with an audio track, but I didn't find anyone commenting about the resulting file size. Admittedly, I am a beginner with this process, but my expectation was the default behavior for a command that creates a loop from an input source would be to efficiently instance it whenever possible.
  
  1. Is the *-stream\_loop* option actually repeating the input video clip frames to make the loop?
  2. Is there a way to tell ffmpeg to instance the input video frames when creating the loop?
  3. Is this actually a limitation with video formats (e.g. mp4, mkv, etc.)?
  4. If ffmpeg is not sufficient for this, is there some way to create a video that efficiently (with respect to file size) loops the video clip for the duration of an audio clip?
  
  **Tags:** ffmpeg, video, audio, encoding, memory
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2021-10-17. Score: 1 | Accepted answer
  
  > Is the -stream\_loop option actually repeating the input video clip frames to make the loop?
  
  Yes.
  
  > Is there a way to tell ffmpeg to instance the input video frames when creating the loop?
  
  No.
  
  > Is this actually a limitation with video formats (e.g. mp4, mkv, etc.)?
  
  For MP4s and MKVs, yes.
  
  > If ffmpeg is not sufficient for this, is there some way to create a video that efficiently (with respect to file size) loops the video clip for the duration of an audio clip?
  
  Not that I know of. Some vendors like Whatsapp have customized MP4s to allow this. However, the player has to recognize and implement the proprietary loop instruction.
  
  > **Comments:**
  > **username_1**: In theory, one can use custom edit lists in MP4s to implement this in a backward compatible way, but I don't know of a tool that does so.  
  
  ---
  
  