Concat same video multiple times failed - ffmpeg

i am trying to concatenate the same video multiple times and it fails.
This is the command i used:
ffmpeg -i 1.mp4 -i 1.mp4 -i 1.mp4 -filter_complex [0:v:0][0:a:0][1:v:0][1:a:0][2:v:0][2:a:0]concat=n=3:v=1:a=1[concatv][concata] -map [concatv] -map [concata] output.mp4
The command fails and the error i am getting is:
Stream specifier ':a:0' in filtergraph description [0:v:0][0:a:0][1:v:0][1:a:0][2:v:0][2:a:0]concat=n=3:v=1:a=1[concatv][concata] matches no streams.
i expect that i will get the same video 3 times, one after one.
Can someone help?

Related

FFmpeg filter complex with bitdepth and sample rate

I've got this code to split audio files and I can't figure out how to set the bitdepth to s32 and sample rate to 48000. Here is the code
ffmpeg -i "audioFile.wav" -filter_complex channelsplit=channel_layout=stereo[FL][FR] -write_bext 1 -map [FL] "audioFile.L.wav" -write_bext 1 -map [FR] "audioFile.R.wav"
I can set it on its own without splitting with the command below, but can't figure how to combine the below code with the above one since you can't use -af and -filter_complex in the same command.
-af aformat=sample_fmts=s32:sample_rates=48000
This combination of -filter_complex should work for you:
-filter_complex "[0:a]aformat=sample_fmts=s32:sample_rates=48000[a];[a]channelsplit=channel_layout=stereo[FL][FR]"

concatenate audio files with an image

I am trying to concatenate multiple audio files and a single image into one video file using one command.
I have list of mp3 files and a playlist file (.m3u) in a direcotry.
I managed to do this but my solution is bad:
reading the playlist file and creating a new .txt in the ffmpeg required format
concatenating the audio files using the .txt into an .mp3
concatenating the large audio file and the static image into a video
This creates 2 unnecessary files that I have to delete.
I tried a different command
ffmpeg -loop 1 -framerate 1 -i myImage.jpg -i file1.mp3 -i file2.mp3 -i file3.mp3 -filter_complex '[0:0][1:0][2:0]concat=n=3:v=0:a=1' -tune stillimage -shortest output.mp4
however im getting a Error initializing complex filters.
Invalid argument error
Another kick in the nuts is that the system im working on has spaces in the folder names.
i tried using -i "concat:file1.mp3|file2.mp3|..." however i cannot use double quote marks to quote out the path so I get an invalid argument error.
Thank you very much for your help.
Method 1: concat demuxer
Make input.txt containing the following:
file 'file1.mp3'
file 'file2.mp3'
file 'file3.mp3'
Run ffmpeg:
ffmpeg -loop 1 -framerate 1 -i myImage.jpg -f concat -i input.txt -filter_complex "[0]scale='iw-mod(iw,2)':'ih-mod(ih,2)',format=yuv420p[v]" -map "[v]" -r 15 -tune stillimage -map 1:a -shortest -movflags +faststart output.mp4
All MP3 files being input to the concat demuxer must have the same channel layout and sample rate. If they do not then convert them using the -ac and -ar options so they are all the same.
Method 2: concat filter
Update: There seems to be a bug with -shortest not working with the concat filter (I keep forgetting about that). See the method above using the concat demuxer, or replace -shortest with -t. The value for -t should equal the total duration of all three MP3 files.
ffmpeg -loop 1 -framerate 1 -i myImage.jpg -i file1.mp3 -i file2.mp3 -i file3.mp3 -filter_complex "[0]scale='iw-mod(iw,2)':'ih-mod(ih,2)',format=yuv420p[v];[1:a][2:a][3:a]concat=n=3:v=0:a=1[a]" -map "[v]" -r 15 -map "[a]" -tune stillimage -shortest -movflags +faststart output.mp4
Option descriptions
scale filter makes image have even width and height which is required when outputting YUV 4:2:0 with libx264.
format filter sets chroma subsampling to 4:2:0, otherwise libx264 will try to limit subsampling, but most players can only handle 4:2:0.
concat filter is accepting file1.mp3, file2.mp3, and file3.mp3 as inputs. Your original command was trying to concat the video to the audio resulting in Invalid argument.
-map "[v]" chooses the video output from -filter_complex.
-r 15 sets output frame rate to 15 because most players can't handle 1 fps. This is faster than setting -framerate 15.
-map "[a]" chooses the audio output from -filter_complex.
-map 1:a chooses the audio from input #1 (the second input as counting starts from 0).
-movflags +faststart after encoding finishes this option moves some data from the end of the MP4 output file to the beginning. This allows playback to begin faster otherwise the complete file will have to be downloaded first.

audio is out of sync after concat 2 files

i want to show a video, that has 2 movies side by side. each movie is a result of one movie that concat 2 times. the problem is that the audio in the right side is out of sync.
i have 3 commands:
first command concat one movie 2 times
ffmpeg -i 1.mp4 -i 1.mp4 -filter_complex "[0:v:0][0:a:0][1:v:0][1:a:0]concat=n=2:v=1:a=1[concatv][concata]" -map "[concatv]" -map "[concata]" Concat1.mp4
second command concat the second movie 2 times
ffmpeg -i 2.mp4 -i 2.mp4 -filter_complex "[0:v:0][0:a:0][1:v:0][1:a:0]concat=n=2:v=1:a=1[concatv][concata]" -map "[concatv]" -map "[concata]" Concat2.mp4
at this point the audio is always synced.
the third command takes the 2 results and merge it to one movie side by side with a logo:
ffmpeg -i Concat1.mp4 -i Concat2.mp4 -i logo.png -filter_complex "[0:v]pad=width=iw+20:height=ih+20:x=10:y=10:color=black[a];[1:v]pad=width=iw+20:height=ih+20:x=10:y=10:color=black[b];nullsrc=size=640x480[base];[a]setpts=PTS-STARTPTS, scale=320x480[left];[b]setpts=PTS-STARTPTS, scale=320x480[right];[base][left]overlay=shortest=1[tmp1];[tmp1][right] overlay=320:0[video];[0:a]apad [apa];[apa][1:a]amerge=inputs=2,pan=stereo|FL<c0+c1|FR<c0+c1[audio];[2:v]scale=120:44 [ovrl];[video][ovrl]overlay=15:25[videoandlogo]" -map "[videoandlogo]" -map "[audio]" output.mp4
the problem is that in the output file the audio of the right movie is out of sync in its second time (the second concat). it always the right movie that is out of sync, even when i switch them.
can anyone help?
Thanks.
==============EDIT===================
the problem of the sync has solved by adding apad also to the second file, but after that the command never stops... how can i tell the command to stop when both movies ended if i have apad for both movies?
this is the new command that never stops:
ffmpeg -i 1.mp4 -i 2.mp4 -i logo.png -filter_complex "[0:v]pad=width=iw+20:height=ih+20:x=10:y=10:color=black[a];[1:v]pad=width=iw+20:height=ih+20:x=10:y=10:color=black[b];nullsrc=size=640x480[base];[a]scale=320x480[left];[b]scale=320x480[right];[base][left]overlay=shortest=1[tmp1];[tmp1][right] overlay=320:0[video];[1:a]apad [apa];[0:a]apad[apa1];[apa][apa1]amix=inputs=2:duration=longest[audio];[2:v]scale=120:44 [ovrl];[video][ovrl]overlay=15:25[videoandlogo]" -map "[videoandlogo]" -map "[audio]" output.mp4
Found the answer (hope it will help someone).
for the audio problem, i solved it by putting apad to all of the movies (need to put the apad of the longest movie first). and to fix the never ending movie i put "-t ".
Thanks.

FFMPEG - Filter volume has an unconnected output

I have the following FFMPEG command:
ffmpeg -i ./master_video.mp4 -i ./temp/temp1.mp4 -i ./temp/temp2.mp4 -y -filter_complex [0:v]setpts=PTS-STARTPTS[v0];[1:a]asetpts=PTS-STARTPTS,volume=0.1[aud1];[1:v]setpts=PTS-STARTPTS+5/TB,fade=t=in:st=5:d=1:alpha=1,fade=t=out:st=14:d=1:alpha=1[v1];[2:a]asetpts=PTS-STARTPTS,volume=0.1[aud2];[2:v]setpts=PTS-STARTPTS+10/TB,fade=t=in:st=10:d=1:alpha=1,fade=t=out:st=19:d=1:alpha=1[v2];[v0][v1]overlay=eof_action=pass[out1];[out1][v2]overlay=eof_action=pass[out2] -map [out2] -map [aud1][aud2] temp.mp4
But when I run it, I received the following error:
error: ffmpeg exited with code 1: Filter volume has an unconnected output
Any ideas why that error is occurring?
If you wish to mix the audio outputs, it needs to be done within the filtergraph.
Use
ffmpeg -y -i ./master_video.mp4 -i ./temp/temp1.mp4 -i ./temp/temp2.mp4 -filter_complex
"[0:v]setpts=PTS-STARTPTS[v0];
[1:a]asetpts=PTS-STARTPTS,volume=0.1[aud1];
[1:v]setpts=PTS-STARTPTS+5/TB,fade=t=in:st=5:d=1:alpha=1,fade=t=out:st=14:d=1:alpha=1[v1];
[2:a]asetpts=PTS-STARTPTS,volume=0.1[aud2];
[2:v]setpts=PTS-STARTPTS+10/TB,fade=t=in:st=10:d=1:alpha=1,fade=t=out:st=19:d=1:alpha=1[v2];
[v0][v1]overlay=eof_action=pass[out1];
[out1][v2]overlay=eof_action=pass[vout];
[aud1][aud2]amix[aout]"
-map [vout] -map [aout] temp.mp4
Note that any audio from the master video is ignored, as it would have been if your original command had worked. Also, the audio and video from the temp videos are no longer synchronized since the setpts expressions are different.

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

Resources