How to Loop Input video x number of time using FFMPEG? - 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

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

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.

Related

how to use concat demuxer twice in the same ffmpeg command

For a complex ffmpeg filter I need the same input twice. For the sake of simplicity I will use a sample where I just overlay a video with itself. (In my real problem the filter is more complex):
ffmpeg -i vid -i vid -filter_complex '[0:v][1:v]overlay' -c:v libx265 -an result.mkv
This works, the result is the reencoded original video.
Sadly, my input is not a video file but a concat demuxer. This is my naive aproach:
ffmpeg -f concat -i vid_list -f concat -i vid_list -filter_complex '[0:v][1:v]overlay' -c:v libx265 -an result.mkv
And it fails. I get tons of error messages about missing frames and the resulting video is completely wrong.
How can I use concat demuxer twice as input within the same ffmpeg command?
NB: loading the concat only once and then using the split filter doesn't work for me. In combination with my complex filter it consumes all RAM.
Based on the assertion from llogan above, that my idea should work, I found a solution that I don't 100% understand but it seems to work....
The input videos do not all have the same framerate. I didn'T expect this to be important, since I am using the very same list of videos twice, so whatever the framerate is or what the concat demuxer does to it, it should be the same to both. Still, explicitly setting the input frame rate seems to solve my problem.
So this fails:
ffmpeg -f concat -safe 0 -i vidlist -f concat -safe 0 -i vidlist ...
but this works:
ffmpeg -f concat -r 15 -safe 0 -i vidlist -f concat -r 15 -safe 0 -i vidlist ...
As said I don't understand exactly why...
Thanks to all

ffmpeg - Concat multiple video files, add audio, set length to videos combined length

I have up until now done this in 2 steps.
Concat video files to outputNoAudio.mp4
Add audio to outputNoAudio.mp4 trimming with -shortest
Now I'm trying to do this in one step using this line
ffmpeg -f concat -safe 0 -i 'vidlist.txt' -i 'music.m4a' -c copy -movflags faststart -y 'test.mp4'
If I use -shortest I end up with an output the length of the shortest video in vidlist.txt. What I'm trying to achieve is the length of all videos combined.
As #Mulvya pointed out. The command works with -shortest. I had the times of my test videos wrong when I started testing. Leaving the answer here for for others trying to do the same.
ffmpeg -f concat -safe 0 -i 'vidlist.txt' -i 'music.m4a' -c copy -movflags faststart -shortest -y 'test.mp4'

ffmpeg write while converting video

I am trying to watermarking the video but after size of output video become larger than 800MB the ffmpeg stopped working without error. So what I think is that the buffer size is full. So my question is how to make ffmpeg release the finished part each 10 minutes instead of waiting after the full video being converted and then write it to the disk.
ffmpeg.exe -i input.mkv -i logo.png -report -filter_complex "overlay = 20:15,subtitles = 'sub.srt'" -codec:a copy output.mkv
What you can try is to output using the segment muxer and then stitch the various segments.
Step 1:
ffmpeg -i input.mkv -i logo.png -filter_complex "overlay=20:15,subtitles='sub.srt'"
-c:a copy -f segment -segment_time 600 out%d.ts
Step 2:
If you have three segments, it would look like this
ffmpeg -i "concat:out1.ts|out2.ts|out3.ts" -c copy output.mkv

Ffmpeg video overlay

I am trying to create a video output from multiple video cameras.
Following the example given here Presenting more than 2 videos using FFmpeg
and other similar examples.
but Im getting the error
Output pad "default" for the filter "src" of type "buffer" not connected to any destination
when i run
ffmpeg -i /dev/video1 -i /dev/video0 -filter_complex "[0:0]pad=iw*2:ih[a];[a][1:0]overlay=w[b];[b][2:0]overlay=w:h" -shortest output.mp4
Im not really sure what this means or how to fix it.
Any help would be greatly appreciated!
Thanks.
When using the "padding" option, you have to specify which is the size of the output image and where you want to put the input image
[0:0]pad=iw*2:ih:0:0
tested under windows 7 with file of same size
ffmpeg -i out.avi -i out.avi -filter_complex "[0:0]pad=iw*2:ih:0:0[a];[a][1:0]overlay=w" -shortest output.mp4
and with WebCam Cap (vfwcap) and a still picture (as i have only o=1 WebCam). BTW you can see how to scale one the source to fit in the target (just in case your source have different resolution)
ffmpeg -y -f vfwcap -r 10 -i 0 -loop 1 -i photo.jpg -filter_complex "[0:0]pad=iw*2:ih:0:0[a];[1:0]scale=640:480[b];[a][b]overlay=w" -shortest output.mp4
under Linux:
ffmpeg -i /dev/video1 -i /dev/video0 -filter_complex "[0:0]pad=iw*2:ih:0:0[[a];a][1:0]overlay=w" -shortest output.mp4
if it doesn't work test a simple record of video 1 and after of video 0 and check their properties (type, resolution, fps).
ffmpeg -i /dev/video1 -shortest output1.mp4
ffmpeg -I output1.mp4
If you still have issue, update your question with ffmpeg console output (as text) for video and video 0 capture and also of the call with the overlay

FFmpeg input duration?

With FFmpeg you have the option -t which will set the duration of the output. However I do not see a way to limit the duration of the input. Take this command
ffmpeg -i video.mp4 -c copy -t 60 out.mp4
This simply creates a 60 second clip of the original video. However if I wanted to clip the audio while keeping the full video stream, FFmpeg does not seem to have an option for this.
I have tried simply clipping the audio first, then combining the clipped audio with the video file, but this causes video/audio sync issues for me.
‘-aframes number (output)’
Set the number of audio frames to record. This is an alias for -frames:a.
§ Audio Options
ffmpeg -i video.mp4 -c copy -aframes 100 out.mp4
Use the "-itsoffset" option.
This makes the first 10 seconds mute.
ffmpeg -i video.mp4 -vn -acodec copy -ss 10.0 out_audio.mp4
ffmpeg -itsoffset 10.0 -i out_audio.mp4 -i video.mp4 -vcodec copy -acodec copy out.mp4

Resources