I have a .mov video with alpha channel and .png watermark. Is it possible to overlay watermark only over the non-transparent pixels of the video using ffmpeg?
Use
ffmpeg -i in.mp4 -i image \
-filter_complex "[0]split[o][a];[a]alphaextract[a];\
[o][1]overlay=format=auto[oc];[oc][a]alphamerge" -c:a copy out.mov
Choose a codec that preserves alpha like -c:v png.
Related
png images on an alpha video the images do not appear? on the alpha zone if I remove "colorchannelmixer=aa=0.01" it appears on the video
if you want i can send you the video
if a nice person could help me i'm a taker
ffmpeg/ffmpeg
-i agence_montage_video/6382315603f21_test_neutreb_VF.mp4
-i agence_quatre_img/"1669476945.png"
-i agence_quatre_img/"1669476908.png"
-i agence_quatre_img/"1669476891.png"
-i agence_quatre_img/"1669476831.png"
-filter_complex
"[1:v]format=rgba,scale=1080:1080,colorchannelmixer=aa=0.01 [logo];
[2:v]format=rgba,scale=1080:1080,colorchannelmixer=aa=0.01 [logo2];
[3:v]format=rgba,scale=1080:1080 ,colorchannelmixer=aa=0.01[logo3];
[4:v]format=rgba,scale=1080:1080 ,colorchannelmixer=aa=0.01[logo4];
[0:v][logo]overlay=(W-w)/2:(H-h)/2:enable='between(t,0,6)':format=auto,format=yuv420p [f0];
[f0][logo2]overlay=(W-w)/2:(H-h)/2:enable='between(t,6,8)':format=auto,format=yuv420p [f1];
[f1][logo3]overlay=(W-w)/2:(H-h)/2:enable='between(t,8,10)':format=auto,format=yuv420p [f2];
[f2][logo4]overlay=(W-w)/2:(H-h)/2:enable='between(t,10,"13")' [out]"
-map "[out]" agence_quatre_img/"19"_.mov
For example,
there is a jpeg with dimensions 1900x1000 and it has a frame (a rectangle) with pixel coordinates 490x100 and 1400x500
a video with resolution 720p needs to be placed within this rectangle
Could you pls share the ffmpeg command to concatenate the jpeg and video? I tried -hstack and -xstack filters. But, couldn't get the video inside the rectangle.
TIA
Your rectangle has a size of 910x400, so you have to downscale the 1280x720 video to fit. But the aspect ratios do not match. So you need to also pad or crop the 1280x720 video to properly fit inside 910x400 if you want to preserve the aspect ratio.
Combine these answers:
Resizing videos with ffmpeg to fit into static size
How to overlay with ffmpeg?
Crop to fit
ffmpeg -i image.jpg -i video.mp4 -filter_complex "[1]scale=910:400:force_original_aspect_ratio=increase,crop=910:400[fg];[0][fg]overlay=x=490:y=100,format=yuv420p" -c:a copy -movflags +faststart output.mp4
Pad to fit
ffmpeg -i image.jpg -i video.mp4 -filter_complex "[1]scale=910:400:force_original_aspect_ratio=decrease,pad=910:400:-1:-1[fg];[0][fg]overlay=x=490:y=100,format=yuv420p" -c:a copy -movflags +faststart output.mp4
Squish/stretch to fit
This will ignore the aspect ratio and will result in a distorted image.
ffmpeg -i image.jpg -i video.mp4 -filter_complex "[1]scale=910:400,setsar=1[fg];[0][fg]overlay=x=490:y=100,format=yuv420p" -c:a copy -movflags +faststart output.mp4
I've got an MKV that I would like to replace the first 5 seconds with a static png image that fades in/out from black. How can I accomplish this with just ffmpeg?
Easy method is to overlay the image:
ffmpeg -i input.mkv -loop 1 -t 5 -i image.png -filter_complex "[1]fade=type=in:duration=1,fade=type=out:duration=1:start_time=4[fg];[0]drawbox=t=fill:enable='lte(t,5)'[bg];[bg][fg]overlay=eof_action=pass:x=(W-w)/2:y=(H-h)/2" -c:a copy output.mkv
I added the drawbox filter to make a black background because I didn't know the size of your image.
See FFmpeg Filter Documentation.
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've 3 inputs (1st, 2nd and 3rd block)
1st a mp4 video with 600x400 aspect ratio
2nd a png image with 600x400 aspect ratio
3rd a jpeg image with red background
Output (4th block)
I need a mp4 video of 600x400 as output, it should have resized video of 422x282 and merge all three as shown in image.
Can we implement this via ffmpeg command line?
I'm able to resize video and image separately but having issue in creating desire output.
Use
ffmpeg -i 1.mp4 -i red.jpg -i frame.png
-filter_complex "[0]scale=422:-1[vid];[1][vid]overlay=(W-w)/2:(H-h)/2[bg];
[bg][2]overlay=(W-w)/2:(H-h)/2" out.mp4
First, the video is resized. Then that resized video is overlaid on the red background. Then, on top of that result, the PNG frame is overlaid.
With no red frame and white BG,
ffmpeg -i 1.mp4 -i frame.png
-filter_complex "[0]scale=422:-1,pad=600:400:(ow-iw)/2:(oh-ih)/2:color=white[vid];[vid][1]overlay=(W-w)/2:(H-h)/2" out.mp4