How to add a simple animation to a video using ffmpeg and the overlay filter

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
what is going on y'all donald here with another video editing trick and holy crap i got a little mad scientist experiment to show you today um i managed to overlay a little sub animation over top of video using just ffmpeg it's quite little beast and i will get into all that uh very soon before we move forward uh do me a favor and drop me a like and subscribe and that would really help the channel out so let me show you what i have concocted um i want to show you these things in this order first i'm going to show you the actual sub animation that i wanted to overlay on top of another video so it's just this thing uh by the way shout out to brody for showing me where he got this i figured it was a good guinea pig to test this with so it's this little thing say on everything um it's like five seconds long it is the same dimension same resolution and everything as the video i was using so that's kind of important and the video that i want to overlay this on top of is um just like a little test recording i did real quick i'm going to test to see if i can hear like seven seconds long oh and click i'm going to show you what this looks like after i've ran this command on it so i have already overlaid this on this video and what it is it is this after you run this could this god-awful command i'm about to show you this is what you will get i'm going to test to see if i can hear this or not [Music] ain't that some now that ended up being kind of complicated for me to figure out how to do it uh and i'm going to show you the command and as soon as i open it up you're going to go donny what the actual hell am i staring at but do not worry i will try my best to explain what is happening so i stuck it in this script rub it up oh don't don't don't click off the video just yet i will explain this this god-awful thing so you can kind of ignore these right now this is just me passing in parameters for this script um the main thing you need to keep in mind is okay so it's whatever this main video that i want to overlay on top of is what i'm passing in so in this case would be like the test.mkv and then i'm declaring that i have a complex filter graph like a damn where i got a complex photograph so uh the first thing we're doing and i don't know if this is necessarily important but the example i kind of based this off of was doing it so i figured why the hell not i'll just leave it in there it's making sure that the the main video all of its um time stamps are basically starting from the zero time stamp to make sure that everything both the main video and the overlaying video are starting at the same time stamps now here i am basically loading in the um sub animation file and i am specifying here with this s option that i want both the video the default video in the default audio streams and i those um those two streams are being labeled as over v n over a over v for video and over a for audio next step i take the the the sub animation video stream and i uh basically add offset to its presentation timestamps so why am i doing this um there is an overlay that you there's a there's a filter you use to do this whole overlaying thing called overlay as you see down below now when you do this it will just overlay the like video b on top of video a and they'll both start playing at the same time well that's not really what i wanted i wanted the overlay the sub animation to only start playing after a certain time frame and i looked up like a shitload of different ways to try to figure out how to do this a lot of them seemed like really really overly complicated and i almost gave up at one point and then i found a solution where somebody was talking about resyncing a video's desynced audio and they showed this and i was like aha wait this is what i can use to do this so if i say you see it's referencing a variable i pass in called start so basically what's happening here is if i say that i want the sub animation to start playing uh 69 seconds into the main video it will take all of the presentation timestamps for the sub animation and basically bump them forward by 69 seconds so what you'll get is is that the video will start this sub animation will start playing 69 seconds into the main video as duration goes the whole time and then just be done uh so we do that uh then the next part is to actually do the overlay um the way the overlay filter works is the first input is the main video and then the second input is the thing being overlaid on top of the first input and we pass in a couple options here um these two first two are the x and y offsets or how the um the second video is overlaid on top of the first since these two videos are the same resolution if i leave these alone what you would get is the sub animation would basically pop up right in the middle of the main video because that's where it is in its own video but i didn't necessarily want it right in the middle i kind of just want it off the side a little bit so you'll see i am offsetting the x position the um the like the horizontal position by negative 600. so basically what it's done is instead of being right in the middle it's kind of like stuck over on the side like so it's not like obstructing my magnificent beard while the video is playing the y position i had no reason to change it so i left it alone this option called end of file action tells the overlay filter what to do when the overlaid video is done playing um this is just basically making sure that when the overlaid video is done playing the whole video just doesn't stop it just says just just keep playing just let the main video kind of take over and do its thing now that only solved the problem of getting the video part of the sub animation to play when i wanted it to this did not address the issue of the audio you have to also explicitly push the sub animation's audio back to the same time span in order for everything to be synced up so you will see that i am passing the sub animations audio stream into a filter called audio a delay which is audio delay and this one you specify um the time duration in milliseconds you want the audio stream to be delayed um i actually made a really funny mistake the first time i use this i didn't realize you had to specify both the like if it's stereo like the left and the right channels i left this a load like i only have one um one value you you specify the uh the left and right channel offsets with between these pipes and what happened was it started the video and played in the right ear immediately i was like what the hell that's not right and then i let it keep playing and then it played when it was supposed to the left one i went i made a booboo and then also before i am done with this step i'm just um i'm having the volume of the sub animation because it's kind of loud by default i thought it was a little too loud actually so i'm basically just making it not as loud so it doesn't just kind of overpower the main videos audio and then last but not least we are doing we are passing in the um the two audio channels from the main video because when i record my videos they have two separate audio channels the microphones one channel and then the desktop audio is a separate channel and then this delayed sub animation audio it's passing into a filter called audio mix which will basically just take all of these and just combine them into one audio channel here i'm specifying the number of inputs which is three the duration will determine how long this combined audio stream is uh i think there's like three main options there's first meaning it'll just set the duration equal to the first audio input which would be the the zero the first audio input of the first video um there's shortest and there's longest i think even though i just said the longest is to make sure a dropout transition so a mix does this kind of annoying thing and i i understand why it does it but it's still annoying where if it's mixing all these audio channels together it will adjust the volume of all of them down because if it didn't and it just played them all at max volume it might clip so when one audio stream ends there's this transition where it brings the volume of the other channels still playing back up this is basically just saying don't delay i just immediately change it back to normal and weights is the option that i was trying to use to make it so that the when the audio went back up the it wasn't such a noticeable difference if i take out these this weights option um as soon as the sub animation audio stream ends there's there's almost like a i don't know probably a good 5 or 10 decibel increase in volume for the rest of them so what i'm saying here is for the audio channels for the main audio i want you to basically put more weight on them to a scale of three this is because the way a mix lowers the volumes is you basically take the volume each um stream has and you divide it by the number of inputs so by default all three of these volumes basically have a they're playing in like one one third their normal volume until they're uh done with uh but i want these two to be as normal as they can be and this one i don't care so this is trying to make sure that when the uh sub animations audio uh stream ends that there's not like this god-awful increase in volume and then i'm writing this out to a stream called out a and then finally we get down here and i am writing i am specifying that i am mapping the uh processed video stream and the process audio stream out to the file name that specified as essentially what's happening now this probably seemed like it was more complicated than what it was worth but i assure you it wasn't uh because the main benefit of me figuring this out is i can take this section of this filter graph right and i can put this in another filter graph a more a longer complex filter graph my plan is to take this combine it with some other stuff i've been figuring out for doing most of my video editing with ffmpeg and make it so that basically once i'm done editing like individual clips of a video and i have like the final one left i'm just gonna run like one big finalize uh process and it's gonna do all the all this all in one go it's gonna add in the fade it might normalize audio it's gonna add in the overlay uh concatenate the little outro song stuff just without me having to touch anything that would be uh amazing and i will certainly let you all know when i have got to that point um if you liked the video drop me a like subscribe comment down below if you have any questions uh with that i'll y'all come on back now and i'll see you next time you
Info
Channel: Donald Feury
Views: 7,382
Rating: undefined out of 5
Keywords: ffmpeg overlay video on another video, ffmpeg overlay, donald feury add overlay, donald feury ffmpeg tricks, donald feury ffmpeg, donald feury, web developer, programming, ffmpeg, feurious, spotifyd, spotify-tui, spotify tui, linux, tutorial, how to, how to use, ffmpeg tutorial, help, quickstart, quick start, quick, start, basics, fundamentals, getting started, conversion, filters, effects, ffmpeg help, video, audio, automated video editing, donald fuery video editing, overlay video in imovie
Id: jIcVut4k6zc
Channel Id: undefined
Length: 13min 58sec (838 seconds)
Published: Sat May 02 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.