I've came across two problems.
I'm trying to resize and set the opacity/transparency of a watermark, and I can't seem to do it in one command line.
command to rescale but not set transparency:
ffmpeg -i video.mp4 -i watermark.png -filter_complex "[1]scale=iw*0.1:-1[wm];[0][wm]overlay=x=15:y=10" output.mp4
Trying to set transparency of text but leave the border of the text greyish.
command to resize text and set border, but could not set transparency:
ffmpeg -i video.mp4 -filter_complex "drawtext=fontfile=wryh.ttf:text='sample':x=20:y=15:fontcolor=white#1:fontsize=15:fontcolor=white:bordercolor=black:borderw=0.51" output.mp4
Combined command:
ffmpeg -i video.mp4 -i watermark.png -filter_complex "[1]format=rgba,colorchannelmixer=aa=0.7,scale=iw*0.1:-1[logo];[0][logo]overlay=15:10:format=auto,drawtext=fontfile=wryh.ttf:text='sample':x=20:y=15:fontcolor=white#1:fontsize=15:fontcolor=white:bordercolor=black:borderw=0.51,format=yuv420p" -c:a copy video.mp4
Related
I am overlaying a video on top of an image.
Using this command:
ffmpeg -i image.png -i input.mp4 -filter_complex "[0:v][1:v] overlay=10:10:enable='between(t,0,38)'" -pix_fmt yuv420p -c:a copy output.mp4
I understand the overlay=10:10 is the positioning but I can't seem to work out how to resize the overlay video (input.mp4).
I think I need to use scale but not sure how to.
Any help on scaling the overlay video would be appreciated!
With filter_complex you can combine commands and make named outputs
Try something like this:
ffmpeg -i image.png -i input.mp4 -filter_complex "[1:v]scale=320x240[scaled_v];[0:v][scaled_v] overlay=10:10:enable='between(t,0,38)'" -pix_fmt yuv420p -c:a copy output.mp4
Just change resolution to what you need instead of 320x240.
If you need image overlay on top of video, swap [1:v] and [0:v]
Im using this ffmpeg command to overlay a video on image (with remove black background):
ffmpeg -loop 1 -i image.png -i video.mp4 -filter_complex [1:v]colorkey=0x000000:0.1:0.1[ckout];[0:v][ckout]overlay[out] -map [out] -t 5 -c:a copy -c:v libx264 -y result.mp4
But as you can see in the picture, the black parts of the ball have also disappeared. How can I solve this problem?
Not possible with colorkey/chromakey alone. The background is too similar to the color you want to remove. You have two options.
Mask
Use a mask. If the video comes with an alpha mask you can use it to cut out the background using the alphamerge filter:
ffmpeg -i bg.jpg -i video.mp4 -i alpha.mp4 -filter_complex "[1][2]alphamerge[alf];[0][alf]overlay" output.mp4
Use a different color
Replace the video that has a color that is different than the color you want to remove.
I am looking to overlay a video on top of another video and then also add a fade in and fade out PNG.
I have the current command which works perfectly in merging two video files one on top of the other.
ffmpeg -y -i output.mp4 -i transparent.mp4 -filter_complex "[1:v][0:v]scale2ref[ua][b];[ua]setsar=1,format=yuva444p,colorchannelmixer=aa=.7[u];[b][u]overlay=eof_action=pass[v]" -map [v] awsome.mp4
I need to now add a PNG on it as well that fades in at 1s and fades out at 9.5s.
Appreciate any and all advice.
Use
ffmpeg -y -i output.mp4 -i transparent.mp4 -loop 1 -t 10 -i image.png -filter_complex "[1:v][0:v]scale2ref[ua][b];[ua]setsar=1,format=yuva444p,colorchannelmixer=aa=.7[u];[b][u]overlay=eof_action=pass[v];[2]fade=in:st=0:d=1:alpha=1,fade=out:st=8.5:d=1:alpha=1[i];[v][i]overlay[v]" -map [v] awsome.mp4
If the PNG needs to be scaled to video size, use scale2ref for the image as well.
ffmpeg -y -i output.mp4 -i transparent.mp4 -loop 1 -t 10 -i image.png -filter_complex "[1:v][0:v]scale2ref[ua][b];[ua]setsar=1,format=yuva444p,colorchannelmixer=aa=.7[u];[b][u]overlay=eof_action=pass[v];[2][v]scale2ref[i][v];[i]fade=in:st=0:d=1:alpha=1,fade=out:st=8.5:d=1:alpha=1[i];[v][i]overlay[v]" -map [v] awsome.mp4
thanks to many posts on stack overflow I could come till here: How to add watermark in a gif with ffmpeg? which i can convert mp4 into animated gif with moderate quality and watermark on. But I'd like to add the drawtext too in these lines.
ffmpeg -i in.mp4 -i watermark.png -filter_complex "[0]fps=10,scale=320:-1:flags=lanczos[bg];[bg][1]overlay=W-w-5:H-h-5,palettegen" palette.png
ffmpeg -i in.mp4 -i watermark.png -i palette.png -filter_complex "[0]fps=10,scale=320:-1:flags=lanczos[bg];[bg][1]overlay=W-w-5:H-h-5[x];[x][2]paletteuse=dither=bayer:bayer_scale=3" output.gif
Would it be possible through filter_complex by adding another [ ]? Thanks a lot to everyone
You can add drawtext after overlay.
ffmpeg -i input.mp4 -i watermark.png -filter_complex "[0]fps=10,scale=320:-1[bg];[bg][1]overlay=main_w-overlay_w-10:main_h-overlay_h-10:format=auto,drawtext=text='your text here':fontsize=24:fontcolor=white:x=(w-text_w)/2:y=(h-text_h)/2,split[s0][s1];[s0]palettegen[p];[s1][p]paletteuse" output.gif
This will add text centered in video and overlay will be placed in the lower right.
I'm using ffmpeg to scale and change speed of my videos.
And below script was not worked:
ffmpeg -i input.mp4 -filter_complex "[0:v]setpts=0.666*PTS[i]; [i]scale=640:640[j]; [0:a]atempo=1.5[p]" -map "[j]" -map "[p]" output.mp4 2>&1
More simple script I testes also not working
ffmpeg -i input.mp4 -filter_complex "scale=640:640" output.mp4 2>&1
Original video have resolution 1280x720, and I want to resize to 640x640, with padding 320 left and right.
What are my wrongs in script?
Sorry for my bad English!
I suspect you have problem with the scaling part, so try this:
ffmpeg -i input.mp4 -filter_complex "setpts=0.666,scale=w=min(iw*640/ih\,640):h=min(640\,ih*640/iw),pad=w=640:h=640:x=(640-iw)/2:y=(640-ih)/2; atempo=1.5" output.mp4
Here's the scaling filter:
scale=w=min(iw*HEIGHT/ih\,WIDTH):h=min(HEIGHT\,ih*WIDTH/iw),pad=w=WIDTH:h=HEIGHT:x=(WIDTH-iw)/2:y=(HEIGHT-ih)/2
Source:
ffmpeg resize down larger video to fit desired size and add padding