0

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, 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?
0

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.

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.
    – Gyan
    Oct 17 at 5:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.