Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Loop Input video x number of time using FFMPEG?

Tags:

ffmpeg

I want to loop same video 4 times and output as video using ffmpeg. SO I create code like this in ffmpeg.

ffmpeg -loop 4 -i input.mp4 -c copy output.mp4

but when i run it it give the error like this.

Option Loop Not Found.

how to do this withour error. Please Help Me

like image 468
Hitesh Shukla Avatar asked Jul 13 '15 09:07

Hitesh Shukla


2 Answers

In recent versions, it's

ffmpeg -stream_loop 4 -i input.mp4 -c copy output.mp4

Due to a bug, the above does not work with MP4s. But if you wrap to a MKV, it works for me.

ffmpeg -i input.mp4 -c copy output.mkv

then,

ffmpeg -stream_loop 4 -i output.mkv -c copy output.mp4
like image 96
Gyan Avatar answered Sep 28 '22 10:09

Gyan


I've found an equivalent work-around with input concatenation for outdated/bugged versions -stream_loop:

ffmpeg -f concat -safe 0 -i "video-source.txt" -f concat -safe 0 -i "audio-source.txt" -c copy -map 0:0 -map 1:0 -fflags +genpts -t 10:00:00.0 /path/to/output.ext

This will loop video and audio independently of each other and force-stop the output at 10 hour mark.

Both text files consist of

file '/path/to/file.ext'

but you must make sure to repeat this line enough times to keep the output satisfied.

For example, if your total video time is less than total audio time then video output will stop earlier than intended and the audio will keep playing until either -t 10H is reached or audio ends prematurely.

like image 20
BotOfWar Avatar answered Sep 28 '22 12:09

BotOfWar