FFMPEG: Overlaying one video on another one, and making black pixels transparent -


i'm trying use ffmpeg create video 1 video overlayed on top another.

i have 2 mp4s. need make black pixels in overlay video transparent can see main video underneath it.

i found 2 ways overlay 1 video on another:

first, following positions overlay in center, , therefore, hides portion of main video beneath it:

    ffmpeg -i 1.mp4 -vf "movie=2.mp4 [a]; [in][a] overlay=352:0 [b]" combined.mp4 -y 

and, one, places overlay video on left, it's opacity set 50% @ least other 1 beneath visible:

ffmpeg -i 1.mp4 -i 2.mp4 -filter_complex "[0:v]setpts=pts-startpts[top]; [1:v]setpts=pts-startpts, format=yuva420p,colorchannelmixer=aa=0.5[bottom]; [top][bottom]overlay=shortest=0" -acodec libvo_aacenc -vcodec libx264 out.mp4 -y 

my goal make black pixels in overlay (2.mp4) transparent. how can done.

the notional way chroma-key black out , overlay, @modj said, won't produce satisfactory results. neither method suggest below, it's worth try.

ffmpeg -i 1.mp4 -i 2.mp4 -filter_complex "[1]split[m][a];  [a]geq='if(gt(lum(x,y),16),255,0)',hue=s=0[al];  [m][al]alphamerge[ovr];  [0][ovr]overlay" output.mp4 

above, duplicate overlay video stream, use geq filter manipulate luma values pixel luma greater 16 (i.e. not pure black) has luma set white, else zero. since haven't provided expressions 2 color channels, geq falls on luma expression. don't want that, use hue filter nullify channels. use alphamerge filter merge alpha channel first copy of overlay video. then, overlay. said, may not produce satisfactory results. can tweak value 16 in geq filter change black threshold. suggested range 16-24 limited-range (y: 16-235) video files.


Comments

Popular posts from this blog

jOOQ update returning clause with Oracle -

java - Warning equals/hashCode on @Data annotation lombok with inheritance -

java - BasicPathUsageException: Cannot join to attribute of basic type -