combine two -filter_complex command together - ffmpeg

Below, I have two ffmpeg commands (1, 2) to be combined into (3).
add sounds from 1.mp3 and 1.3gp into muted 1.mp4
code works without error:
ffmpeg -i 1.mp3 -i 1.3gp -i 1.mp4 \
-filter_complex "[1]adelay=640|640[s1];[0][s1]amix=2[mixout];" \
-map 2:v -map [mixout] -c:v copy result.mp4
add watermark to top-right of 1.mp4
code works without error:
ffmpeg -i 1.mp4 -i logo.png \
-filter_complex "overlay=x=main_w-overlay_w:y=1" \
result.mp4
combine above two commands into one
My code fails
ffmpeg -i 1.mp3 -i 1.3gp -i 1.mp4 -i logo.png \
-filter_complex "[1]adelay=640|640[s1];[0][s1]amix=2[mixout];[2:v][3]overlay=x=main_w-overlay_w:y=1[outv]" \
-map [outv] -map [mixout] -c:v copy result.mp4
What am I doing wrong here?

Use
ffmpeg -i 1.mp3 -i 1.3gp -i 1.mp4 -i logo.png \
-filter_complex "[1]adelay=640|640[s1];[0][s1]amix=2[mixout];
[2:v][3]overlay=x=main_w-overlay_w:y=1[outv]" \
-map [outv] -map [mixout] result.mp4
If you're filtering the video stream e.g. adding an overlay, then you can't copy that video stream.

Related

ffmpeg read from a file and apply filter_complex at once

I am feeding fls.txt into ffmpeg -i and applying concat and a speedup.
fls.txt
file 'input1.mp4'
file 'input2.mp4'
file 'input3.mp4'
The command in one go looks as follows:
ffmpeg -i fls.txt \
-filter_complex "[0:v][0:a][1:v][1:a][2:v][2:a] concat=n=3:v=1:a=1 [v][a];\
[v]setpts=0.5*PTS[v1];[a]atempo=2,asetpts=N/SR/TB[a1]" \
-c:v h264_nvenc -map "[v1]" -map "[a1]" x2.mp4
The output is really weird and says something like a stream is not found. And it also looks like as if it's trying to understand the fls.txt itself and not its content as the parameters.
What am I doing wrong here and how can I correct it?
Also, it's a simplified example and I cannot write per hand 3 input file paths. I need it to be read from a file. I'm on windows 10 if that matters.
EDIT:
From doing the suggested edits and expanding the -filter_complex I get an error below.
ffmpeg -f concat -safe 0 -i fls.txt \
-filter_complex "[0:v]setpts=0.5*PTS[v1];[v1]setpts=0.5*PTS[v2];[0:a]atempo=2,asetpts=N/SR/TB[a1];[a1]atempo=2,asetpts=N/SR/TB[a2]" \
-c:v h264_nvenc -map "[v1]" -map "[a1]" x2.mp4 \
-c:v h264_nvenc -map "[v2]" -map "[a2]" x4.mp4
error:
Output with label 'v1' does not exist in any defined filter graph, or was already used elsewhere.
Stream specifier ':a' in filtergraph description … matches no streams.
To enable the concat demuxer you have to use -f concat before -i fls.txt.
ffmpeg -f concat -i fls.txt \
-filter_complex "[0:v]setpts=0.5*PTS[v1];[0:a]atempo=2,asetpts=N/SR/TB[a1]" \
-c:v h264_nvenc -map "[v1]" -map "[a1]" x2.mp4
Because you're attempting to use the concat demuxer there is no need for the concat filter as well, so you can simplify the command.
You may also have to use -safe 0 before -i which you can read about in the documentation.
Follow-up question: Output with label 'v1' does not exist in any defined filter graph, or was already used elsewhere
You can't reuse consumed filter output labels so this example avoids that:
ffmpeg -f concat -safe 0 -i fls.txt \
-filter_complex "[0:v]setpts=0.5*PTS[2xv];[0:v]setpts=PTS/4[4xv];[0:a]atempo=2,asetpts=N/SR/TB[2xa];[0:a]atempo=4,asetpts=N/SR/TB[4xa]" \
-c:v h264_nvenc -map "[2xv]" -map "[2xa]" x2.mp4 \
-c:v h264_nvenc -map "[4xv]" -map "[4xa]" x4.mp4

FFMPEG multiple file pattern not working in single command

I want to add multiple file sequences in single ffmpeg command, below is my code, video is getting created but only first image sequence is getting used, second is getting ignored
ffmpeg -y -i input.mp4 -start_number 0000001 -i 1/%07d.png -i 2/%07d.png -filter_complex "[0][1]overlay=x=10:y=10:enable='between(t,0,3)'[v1];[v1][2]overlay=x=10:y=10:enable='between(t,3.8561422222222,6.9761777777778)'[v2]" -map "[v2]" -map 0:a out.mp4
Now the problem is FFMPEG wants continous images, which i don't have i have images starting from 0000001.png in each folder, how can i accomplish this without changing much in my images
Try the glob pattern to deal with inconsistent numbering and pad the PTS with setpts so the overlay doesn't get consumed before it is displayed:
ffmpeg -y -i input.mp4 -pattern_type glob -i "1/*.png" -pattern_type glob -i "2/*.png" -filter_complex "[0][1]overlay=x=10:y=10:enable='between(t,0,3)'[v1];[2]setpts=PTS+3.856/TB[fg];[v1][fg]overlay=x=10:y=10:enable='between(t,3.8561422222222,6.9761777777778)'[v2]" -map "[v2]" -map 0:a out.mp4
Can you pipe the images to -f image2pipe ?
cat $(find 1 2 -name '*.png' -print) | ffmpeg -y -i input.mp4 \
-f image2pipe -vcodec png -i - \
-filter_complex "[0][1]overlay=x=10:y=10:enable='between(t,0,3)'[v1];[v1][2]overlay=x=10:y=10:enable='between(t,3.8561422222222,6.9761777777778)'[v2]" \
-map "[v2]" -map 0:a out.mp4

ffmpeg - executing 2 or more command in one time

I have 2 ffmpeg commands, I execute them respectively, they work, but I want to execute them in one time and one command. How to do that?
ffmpeg -i 1.mp4 -i logo.png -filter_complex "overlay=main_w-overlay_w-20:20" -codec:a copy 2.mp4
ffmpeg -i 2.mp4 -i picture.png -filter_complex "overlay=10:10" -codec:a copy 3.mp4
Use:
ffmpeg -i 1.mp4 -i logo.png -i picture.png -filter_complex "[0:v][1:v]overlay=main_w-overlay_w-20:20[bg];[bg][2:v]overlay=10:10[v]" -map "[v]" -map 0:a -c:a copy output.mp4
See the FFmpeg Filter Documentation for a description of the syntax.

FFMpeg - Combine multiple filter_complex and overlay functions

I am having trouble combining these 3 passes in ffmpeg into a single process.
Is this even possible?
Pass 1
ffmpeg -y -i C:\Users\MJ\Downloads\20151211_pmoney_pmpod.mp3 -loop 1 -i C:\Users\MJ\Documents\pm1080.png -filter_complex "[0:a]showwaves=s=1920x1080:mode=line,colorkey=0x000000:0.01:0.1,format=yuva420p[v];[1:v][v]overlay=0:270[outv]" -map "[outv]" -pix_fmt yuv420p -map 0:a -c:v libx264 -c:a copy -shortest C:\Users\MJ\Documents\20151211_pmoney_pmpod4.mp4
Pass 2
ffmpeg -i "C:\Users\MJ\Documents\20151211_pmoney_pmpod4.mp4" -vf drawtext="fontsize=50:fontcolor=white:fontfile=/Windows/Fonts/impact.ttf:text=Planet Money Podcast on NPR - A/B Split Testing:x=(w-text_w)/2:y=200" -acodec copy "C:\Users\MJ\Documents\20151211_pmoney_pmpod-overlay-text.mp4"
Pass 3
ffmpeg -i "C:\Users\MJ\Documents\20151211_pmoney_pmpod-overlay-text.mp4" -i C:\Users\MJ\Downloads\6.png -filter_complex "overlay=10:10" C:\Users\MJ\Documents\20151211_pmoney_pmpod-overlay-text1.mp4"
Thanks!
Join filters with a comma and filterchains with a semicolon:
ffmpeg -i audio.mp3 -i image1.png -i image2.png -filter_complex \
"[0:a]showwaves=s=1920x1080:mode=line[fg]; \
[1:v][fg]overlay=0:270,drawtext=fontsize=50:fontcolor=white:fontfile=/Windows/Fonts/impact.ttf:text='Planet Money Podcast on NPR - A/B Split Testing':x=(w-text_w)/2:y=200[bg]; \
[bg][2:v]overlay=10:10,format=yuv420p[outv]" \
-map "[outv]" -map 0:a -c:v libx264 -c:a copy -movflags +faststart -shortest out.mp4

Run FFMPEG multiple overlay commands in one command

I'm using ffmpeg to do more operation on one video
the operation that i want to do is add many text in difference time, audio and image.
i can do all of them but not in one command, Do all separately
any suggestions to do multiple text , overlay image and audio in one command
Thanks
To achieve the commands provided in comments in one execution, use
ffmpeg –i input.mp4 –i img.png -i audio.mp4 -filter_complex \
"[0:v][1:v]overlay=15 :15:enable=between(t,10,20), \
drawtext=enable='between(t,12,3*60)': \
fontfile=/usr/share/fonts/truetype/freefon‌​t/FreeSerif.ttf: text='Test Text'[v]" \
-map "[v]" -map 2:a -acodec copy -qscale 4 -vcodec mpeg4 outvideo.mp4
To add more drawtext filters, insert them after the first drawtext filter e.g.
ffmpeg –i input.mp4 –i img.png -i audio.mp4 -filter_complex \
"[0:v][1:v]overlay=15 :15:enable=between(t,10,20), \
drawtext=enable='between(t,12,3*60)': \
fontfile=/usr/share/fonts/truetype/freefon‌​t/FreeSerif.ttf: text='Test Text', \
drawtext=enable='between(t,12,3*60)': \
fontfile=/usr/share/fonts/truetype/freefon‌​t/FreeSerif.ttf: text='Text2'[v]" \
-map "[v]" -map 2:a -acodec copy -qscale 4 -vcodec mpeg4 outvideo.mp4

Resources