I need to add INTRO.mp4 at the beginning of video.mp4 and add watermark.png (bottom right corner)
How to do this using ffmpeg, because I'm lost?
log file
Copy and paste this command. It will work with any intro.mp4 and video.mp4 assuming they both have audio.
ffmpeg -i intro.mp4 -i video.mp4 -i watermark1.png -filter_complex "[0:v]scale=1920:1080:force_original_aspect_ratio=decrease,pad=1920:1080:-1:-1,setsar=1,fps=30000/1001,format=yuv420p[intro];[1:v]scale=1920:1080:force_original_aspect_ratio=decrease,pad=1920:1080:-1:-1,setsar=1,fps=30000/1001,format=yuv420p[video];[2]scale=96:-1[logo];[0:a]aformat=sample_rates=48000:channel_layouts=stereo[introa];[1:a]aformat=sample_rates=48000:channel_layouts=stereo[videoa];[intro][introa][video][videoa]concat=n=2:v=1:a=1[vid][a];[vid][logo]overlay=W-w-5:H-h-5[v]" -map "[v]" -map "[a]" -movflags +faststart output.mp4
See:
FFmpeg Filters Documentation
How to add watermark with ffmpeg?
How to concatenate videos in ffmpeg with different attributes?
Related
I edit the video with the command
ffmpeg -i video.mp4 -y -vf eq=saturation={rand_saturation},fade=in:st=0:d={rand_fade},hflip,noise=alls={rand_noise}:allf=t -c:a copy output.mp4
then the resulting video
ffmpeg -i output.mp4 -i logo.png -filter_complex "[0:v][1:v]overlay=x='if(lt(mod(t,10),5),1,W-w-10)':y='if(lt(mod(t,10),5),5,H-h-200)'" -c:a copy output_1.mp4
I tried to combine all this together so that I didn't have to spend time processing the video twice, but I couldn't do it because you can't use the -vf and -filter_complex commands together. How can this problem be solved?
First apply the video specific filters before using the result as overlay input.
ffmpeg -i video.mp4 -i logo.png -filter_complex "[0:v]eq=saturation={rand_saturation},fade=in:st=0:d={rand_fade},hflip,noise=alls={rand_noise}:allf=t[vid];[vid][1:v]overlay=x='if(lt(mod(t,10),5),1,W-w-10)':y='if(lt(mod(t,10),5),5,H-h-200)'" -c:a copy output_1.mp4
I am using FFmpeg to speed up a video and add a watermark. The watermark is a percentage of the video size.
To speed up I am using
ffmpeg -i input.mp4 -filter_complex "[0:v]setpts=0.5*PTS[v];[0:a]atempo=2.0[a]" -map "[v]" -map "[a]" output.mp4
And to add a watermark, I am using
ffmpeg -i input.mp4 -i watermark.png -filter_complex "[1][0]scale2ref=w=oh*mdar:h=ih*0.1[logo][video];[video][logo]overlay=5:H-h-5" -c:a copy output.mp4
Both work well on their own. I am trying to combine them into a single command. There are many questions/answers regarding similar problems that I could find, however they seem to either be outdated or I just can't get them to work.
To combine filters I have read to just add a comma, but that doesn't seem to work:
ffmpeg -i input.mp4 -i watermark.png -filter_complex "[1][0]scale2ref=w=oh*mdar:h=ih*0.1[logo][video];[video][logo]overlay=5:H-h-5,[0:v]setpts=0.5*PTS[v];[0:a]atempo=2.0[a]" -map "[v]" -map "[a]" output.mp4
The command will run without errors, and add the watermark, but the audio/video filter is not being applied.
How can I do it?
Combined command:
ffmpeg -i input.mp4 -i watermark.png -filter_complex "[1][0]scale2ref=w=oh*mdar:h=ih*0.1[logo][video];[video][logo]overlay=5:H-h-5,setpts=0.5*PTS;[0:a]atempo=2.0" output.mp4
Connect linear filters with a comma. Connect filterchains with a semicolon. See FFmpeg Filtering Intro.
So Im trying to overlay a video on top of an image and then add text over the image in ffmpeg I found that Im able to do all these separately but when combining it gives me the error of
Cannot find a matching stream for unlabeled input pad 0 on filter Parsed_drawtext_2
The line of code:
ffmpeg -loop 1 -i overlay.png -re
-i overlay.mp4
-filter_complex "[1]scale=1660:934[inner];[0][inner]overlay=0:0:shortest=1[out];
drawtext=fontsize=40:fontfile=FreeSerif.ttf:textfile=text.txt:x=(w-text_w)/2:y=(h-text_h)/2:reload=1"
-map "[out]" -map 1:a -c:a copy -y -s 1280x800 output.mp4
Can anyone help me with this?
You almost got it. Only needs some re-arranging:
ffmpeg -loop 1 -i overlay.png
-i overlay.mp4
-filter_complex "[1]scale=1660:934[inner];[0][inner]overlay=0:0:shortest=1,scale=1280:800,drawtext=fontsize=40:fontfile=FreeSerif.ttf:textfile=text.txt:x=(w-text_w)/2:y=(h-text_h)/2:reload=1[out]"
-map "[out]" -map 1:a -c:a copy output.mp4
See FFmpeg filtering intro for a quick explanation of the syntax.
I try concat two videos (1.mkv has 640:360 image size, 2.mkv has 1280:720 image size), both videos have 2 video tracks and 0 audio tracks. I tried this code:
ffmpeg -i 1.mkv -i 2.mkv -filter_complex "[0:v:0]scale=1280:720:force_original_aspect_ratio=decrease,pad=1280:720:(ow-iw)/2:(oh-ih)/2[v0];[0:v:1]scale=1280:720:force_original_aspect_ratio=decrease,pad=1280:720:(ow-iw)/2:(oh-ih)/2[v0];[v0][1:v:0][1:v:1]concat=n=2:v=2:a=0[v]" -map "[v]" -c:v "libvpx" 1+2.mkv
But I have wrong:
Filter pad has an unconnected output
Your filter labels need to be adjusted, and you need to change v=2 to v=1 in concat filter:
ffmpeg -i 1.mkv -i 2.mkv -filter_complex "[0:v:0]scale=1280:720:force_original_aspect_ratio=decrease,pad=1280:720:(ow-iw)/2:(oh-ih)/2[v0];[1:v:0]scale=1280:720:force_original_aspect_ratio=decrease,pad=1280:720:(ow-iw)/2:(oh-ih)/2[v1];[v0][v1]concat=n=2:v=1:a=0[v]" -map "[v]" -c:v libvpx 1+2.mkv
Since 2.mkv is already 1280x720 you can avoid processing that input:
ffmpeg -i 1.mkv -i 2.mkv -filter_complex "[0:v:0]scale=1280:720:force_original_aspect_ratio=decrease,pad=1280:720:(ow-iw)/2:(oh-ih)/2[v0];[v0][1:v]concat=n=2:v=1:a=0[v]" -map "[v]" -c:v libvpx 1+2.mkv
I am using ffmpeg on Mac to remove green background of video and add other background as image it is converting properly the video but auido is missing. I am using below command.
Am I doing anything wrong here?
ffmpeg -i bg.jpg -i input.mp4 -filter_complex "[1:v]colorkey=0x3BBD1E:0.3:0.2[ckout];[0:v][ckout]overlay[out]" -map "[out]" output.mp4
I solved it my own.
ffmpeg -i bg.jpg -i input.mp4 -filter_complex "[1:v]chromakey=0x3BBD1E:0.1:0.2[ckout];[0:v][ckout]overlay[o]" -map [o] -map 1:a output.mp4
we need to add flags for audio.
Once a map switch is added, only mapped streams are included. Add -map 1:a? -c:a copy