How to apply any mask.png on a video with ffmpeg - ffmpeg

I am adding a 1.mp4 on a video 2.mp4, and i want to add a mask on overlay video(1.mp4)
I want to apply this mask on 1.mp4
I'm using chrome key right now
ffmpeg -t 5 -r 30 -f lavfi -i color=c=black:s=640x360
-i 1.mp4
-i mask2.png
-i 2.mp4
-filter_complex "
[1:v]scale=500x281[v1];
[2]scale=500x281[mask];
[v1][mask]overlay, chromakey=0x00FF00:0.25:0.08 [v2];
[3:v]scale=640x360[v3];
[0][v3]overlay [out1];
[out1][v2]overlay=0:0"
-y output.mp4
But it also removes color from videos.
I'm not sure but i think it can be done by negate
also i don't need audio command, i already done that part
Thanks

Related

ffmpeg, apply fade only to video input using filter_complex while concating

ffmpeg -i foo.mp4 -filter_complex "fade=d=0.5, reverse, fade=d=0.5, reverse" output.mp4
can be used to fade in and out foo.mp4 video. (we do not care about audio). According to https://video.stackexchange.com/questions/19867/how-to-fade-in-out-a-video-audio-clip-with-unknown-duration
It's good but only works in the simple situation of 1 input video, and 1 output. Now, how can I apply the fade in and out effect in the following more complex situation? I'm trying to concat a.jpg (a picture) with bar.mp4. I want only the bar.mp4 portion to fade in and out.
ffmpeg -loop 1 -t 2 -framerate 1 -i a.jpg -f lavfi -t 2 -i anullsrc -r 24 -i bar.mp4 -filter_complex "[0][1][2:v][2:a] concat=n=2:v=1:a=1 [vpre][a];[vpre]fps=24[v]" -map "[v]" -map "[a]" out.mp4 -y
Of course, I could first create a temporary temp.mp4 from bar.mp4 by running the first command, then input temp.mp4 in my second command. This involves an extra step and extra encoding. Could anyone help fix the commands or suggest something even better?
Use
ffmpeg -loop 1 -t 2 -framerate 24 -i a.jpg -f lavfi -t 2 -i anullsrc -r 24 -i bar.mp4 -filter_complex "[2:v]fade=d=0.5, reverse, fade=d=0.5, reverse[v2];[0][1][v2][2:a] concat=n=2:v=1:a=1 [v][a]" -map "[v]" -map "[a]" out.mp4 -y

How to add multiple audio files at specific times, on a silence audio file using ffmpeg?

I need to overlay audio files at specific times, on an existing silence.mp3. Something like that:
[----[...audio1...]----------[...audio2...]---------------]
I've tried the following but it doesn't work:
ffmpeg -y -i silence.mp3 -itsoffset 4 -i audio1.mp3 -itsoffset 30 -i audio2.mp3 -c:a copy final.mp3
Any help would be appriciated. Thank you.
There are several methods.
adelay, amix
Use the adelay and amix filters:
ffmpeg -i audio1.mp3 -i audio2.mp3 -filter_complex "[0]adelay=4s:all=1[0a];[1]adelay=30s:all=1[1a];[0a][1a]amix=inputs=2[a]" -map "[a]" output.mp3
Note that the amix filter will reduce volume of the output to prevent clipping. Followup with dynaudnorm or volume filters if desired.
adelay, concat filter
Or adelay and concat filters. This assumes audio1.mp4 is 10 seconds long, and both inputs have the same sample rate and channel layout:
ffmpeg -i audio1.mp3 -i audio2.mp3 -filter_complex "[0]adelay=4s:all=1[0a];[1]adelay=16s:all=1[1a];[0a][1a]concat=n=2:v=0:a=1[a]" -map "[a]" output.mp3
anullsrc, concat demuxer
Or generate silent files as spacers with the anullsrc filter:
ffmpeg -f lavfi -i anullsrc=channel_layout=stereo:sample_rate=44100 -t 4 4.mp3
ffmpeg -f lavfi -i anullsrc=channel_layout=stereo:sample_rate=44100 -t 16 16.mp3
Create input.txt:
file '4.mp3'
file 'audio1.mp3'
file '16.mp3'
file 'audio2.mp3'
Then use the concat demuxer:
ffmpeg -f concat -i input.txt -c copy output.mp3

How do I generate a color screen for the duration of an MP3 in ffmpeg?

I have successfully generated a blue screen to add to an mp3. But, I have always needed to include the length of the clip to match the mp3. When I don't include a timecode it continues to generate footage until I cancel the command.
ffmpeg -f lavfi -i color=blue:s=1920x1080 -i input.mp3 -t 00:02:08 output.mp4
How do I specify that I only want color generated during the length of the mp3 that I am adding?
ffmpeg -i <.jpg> -i <.mp3>
This worked too but I don't want to rely on a jpeg file.
Use -shortest:
ffmpeg -f lavfi -i color=blue:s=1920x1080 -i input.mp3 -shortest output.mp4

FFmpeg simple 1:1 overlay and concatenate?

I am using ffmpeg on Ubuntu 14.04 (Jon Severinsson's PPA) and am playing video files out of a folder - one by one.
First question I wasn't able to figure out yet - how can I add a simple overlay - 720p footage with 720p overlay (with partial transparency)? So there is no resize or alignment needed - just the 1:1 overlay. I tried a lot already with -vf and -filter_complex but didn't show up.
Second question - with concatenate, is it possible to have the switches between the files seamless? Best without creating a new file - so, on the fly? I need to reduce the gaps between the file switches or eliminate them completely.
This is my bash right now:
#!/usr/bin/env bash
while :; do
files=(*)
ffmpeg -re -i "${files[$RANDOM % ${#files[#]}]}" -acodec copy -vcodec copy -f flv ServerAddress
done
So I have everything in /vod - the videofiles, as well as the overlay.png
Thanks a bunch in advance,
Tim
For the overlay you need to scale the image to the original source dimensions.
To concat multiple source files that have the same codec use the concat demuxer.
Eg:
Make a playlist.txt with the following format:
file '/path/to/file_1'
file '/path/to/file_2'
file '/path/to/file_3'
[..]
And then:
ffmpeg -f concat -i playlist.txt -i overlay.png -filter_complex "[1:v] scale=1280:720 [ovr];[0:v][ovr] overlay=0:0" ...
If the video and the image are the same size you can just use:
ffmpeg -f concat -i playlist.txt -i overlay.png -filter_complex "[0:v] overlay"
Update:
Full example:
You cannot filter and copy the video stream at the same time!
ffmpeg -re -f concat -i playlist.txt -i overlay.png -filter_complex "[0:v] overlay" -c:v h264 -c:a libfdk_aac -ar 44100 -f flv rtmp://...
If your audio stream is valid and has one of the supported audio rates (44100, 22050, 11025) you can do:
ffmpeg -re -f concat -i playlist.txt -i overlay.png -filter_complex "[0:v] overlay" -c:v h264 -c:a copy -f flv rtmp://...

Applying multiple filters at once with FFMPEG

I have the need to apply fadein and overlay filters to a video. Is it possible to apply 2 filters at once?
I got:
ffmpeg -i input.mpg -vf "movie=watermark.png [logo]; [in][logo] overlay=W-w-10:H-h-10 [out]" output.mpg
I'm trying to add fade=in:0:20, but if I add a new -vf parameter, it will overwrite the preceding one, and if I add:
-vf "fade=in:0:20; movie=......"
it won't work.
Is this possible or do I have to run FFmpeg twice?
Okay, someone helped me somewhere.
I had to separate filters with commas:
ffmpeg -i input.mpg -vf "movie=watermark.png [logo]; [in][logo] overlay=W-w-10:H-h-10, fade=in:0:20 [out]" output.mpg
This will apply fadein to both the watermark and the video.
Yes it is possible .
ffmpeg.exe -i yourvideo.avi -vf "[in] scale=iw/2:ih/2, pad=iw+40:ih+40:10:10 [top]; movie=yourLogoOrVideo.pngOraviEtc, scale=iw/2:ih/2 , fade=out:400:40:alpha=1 [bottom]; [top][bottom] overlay=PaddingFromTop:PaddingFromLeft [out]" -f flv ff.flv

Resources