FFMPEG Advanced Techniques Pt2 - Filtergraphs & Timeline

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
last time we started to explore the potential of ffmpeg outside of video conversion and well today we're gonna continue along those same lines last time we sort of restricted ourselves to just the filters and ffmpeg today we're gonna look beyond that and we're gonna see what other features in ffmpeg makes it all the more powerful you're watching another random Wednesday episode r06 wants you TV hello and welcome back to another random Wednesday episode today's video comes to you in two parts first and foremost how to actually mix multiple video streams and filters together this alone is extremely powerful and can actually allow you to do many cool things on top of this we'll also take a look at some editing features in particular how to actually make cuts within a video we'll also look at ways to switch effects on and off over time and then of course gives you all the more power we all further ado let's jump in to take a look at filter graphs your cool method of stringing together multiple filters now the basic filters we've been using so far can actually be expressed in sort of this graphical manner you know the computer science kind of graph not be math kind of graph basically you have an input video you stick it to a filter and well you get an output so take for example an actual ffmpeg command you have an input file and that of course is your inputs right here you put it through an EQ filter and you get an output so yeah fairly straightforward in fact if you were to actually string together multiple different filters it can still be expressed in the same way if you do EQ comma and sharp then of course EQ happens first the result is passed over to unsharped and unsharp does its work so yeah hopefully that's been pretty intuitive we're gonna basically expand upon this concept to do complex things take for example this sort of messy thing I showed you towards the end of the previous episode as you can probably recall our showing you the waves filter and I was actually mixing it onto the original video itself clearly this isn't going to be as straightforward as the filter graphs with in seeing so if let's actually try and draw this out to get a better understanding we start from our input video this of course works exactly as we expect that actually goes out to a split filter in which I've actually sort of duplicated a video three times into three different streams for the first two streams I've basically generated the wave form using the wave form filter and I've basically also used a pad filter and what that does is it creates a whole lot of blank space displaying the wave itself wherever I actually tell it to so yeah as you can see the results at this point of time is you know a wave at a side and a wave at the bottom the next order of business is to actually combine these two and I've achieved that using a blend filter as you can see from the arrows I've actually taken two video streams and combined it into what the results is something like this with the two waves now stacked on top of each other sending our attention back to the remaining video stream well I Pat it out so as to give it some borders towards the left and a bottom all that's left to do now is to blend everything together creating the final result what you see here is an example of well somewhat more complex filter graph all that's left to do now is to actually turn this into an actual ffmpeg command of course I shouldn't mention at this point that if you're gonna be using a complex filter graph you know one that isn't just a straight line you are going to have to use the filter complex command switch and not any of the others with C now instead of actually doing the extremely complex example we've looked at let's actually do something a little bit simpler and hopefully a little bit more fun basically I have a static image of you know the background from the video you've been seeing and what I also have is a little animation on a green background this of course means we can actually do chroma keying or you know in other words the green screen effect to sort of stack these two videos on top of each other let's first actually try to visualize how we're gonna do this of course we have the green video as well as the background and these two exist as two separate input streams we're gonna take the green video and perform what is known as color keying on it this allows us to generate a keyed version of the video all that's left to do then is to make use of an overlay filter to actually stick the keep video on top of the background so yeah hopefully that's not too complex let's begin by constructing our ffmpeg command core notice something that we haven't done before we've actually now specified two input files since that is of course what we need the two input files are the green-screen file as well as the background then of course we have to specify our complex filter string let's tackle the first part and that is doing the color key here you'll see the most important thing you need to do when you're actually constructing a complex photograph and that is to actually name your streams like so essentially this is just the color key filter and this is just normal filtering like we've seen previously however we now include something to its left in square brackets this in fact tells us which video to actually work with zero here actually has a special meaning you see the two inputs that are coming in actually named internally as input zero and input 1 since we want to actually run the color key effects on input 0 well we have two states it of course when we are done doing this we want to name the output of the filter as well and that of course comes at the end I've called it keyed and since this is actually arbitrarily defined by me well you can actually call it anything so yeah as a recap you're gonna have to specify the inputs in square brackets then the filter name then the output in we're brackets again so alright let us move on to do the next part which is to actually merge the two video streams together we start off with keet which is of course what we've just creates it and well we want to merge that onto the background aka inputs number one so here's how we're gonna do it all we have to say is one which is of course the background clip then keed and then the overlay filter notice that since we're dealing with two inputs here both of these video streams have to be specified before the filter and me you also find that the order of these two input streams actually do matter and the reason for this is because overlay is actually looking to well take one of these two inputs and overlay them on top of the other in this case well according to the documentation it wants the background first and then the overlay to come next so we do actually have to respect this which is why I answer them in this particular order of course basically we're done all we have to do now is to specify the file name and we get our result notice that I did not actually name the output stream coming out of the overlay filter that's because we don't need it there is an implicit connection on a graph between the last filter and the actual output file the same actually holds true for inputs if you only have one input then you don't actually need to specify the inputs like this in this case we're forced to be explicit about which input we are talking about because there are two of them of course in order to get the correct result I actually had to specify some parameters for the color key filter so yeah don't forget your parameters you can still specify them even if you have a complex filter graph the results of course look something like this the chroma keying has been correctly done and the two videos have been stacked together as we would expect so yeah those are filter graphs and they I actually what makes up of Ampex or flexible and powerful now we've already spent quite a bit of time so let's move through the next quickly we're gonna take a look at some simple trimming features available within ffmpeg as well as how it can actually turn certain effects on and off over time let's take a look ffmpeg has some timeline features both the ctrl D filters as well as to do some editing so let's take a look at both of these things when it comes to using the timeline to control filters well you could have to actually specify things in a kind of Matthew way basically if you want to actually have a blur function that only runs between you know with the fifth second and a 10 second you can actually say something like this you want to end able this filter when T is actually between 5 and 10 and yeah as you can see well it works do note that the unable feature isn't actually available in every single filter but many of the filters actually have it the things you can actually use in a similar way of course include T which is a timestamp in seconds and which is the actual frame number as well as W and H which are the width and height of the video if you need to perform comparisons well you have access to features like greater than greater than or equal less than or less than or equal these functions will give you one if the comparison is true and they'll give you zero if not same deal for between if X is actually between you know the minimum and maximum value then you'll get one otherwise you'll get 0 if you want to do more complex comparisons you can use if and if not basically a test is run against X in a case of if we want to make sure that X is not 0 in the case of if not the evaluation will only become true if X is 0 in any case if the result is true Y will be returned otherwise zette will be returned very interesting things can be done for example in this command call which actually comes from the official documentation what has been created is a transition essentially a blending operation is happening and the intensity of the blending between a and B which are the two inputs actually changes over time as you see there is a dependency on T basically over a period of four seconds one of the two inputs is being faded out while the other is being faded in so yeah this is actually an extremely powerful feature available in ffmpeg let's now talk about another editing feature and that is slicing in the sample video you've been seeing a lot what we've actually done is we've made a huge pen across the city skyline of Singapore now let's say I don't actually want the entire pan I only want the spots in which the Marina Bay Sands is actually visible I've scrubbed through the video and realized that really I only want the footage from the 14 second mug to the 18 second mug well you can of course do this with ffmpeg and there are several different methods to do so to actually get to the start time we use a feature called speaking that actually two ways to do this input seeking and output seeking and that command calls a little bit different as you can see in this case what I've actually done is we've made use of the SS commands which to specify the start time of the video the only difference between these two command calls is the order in which we do things in input seeking we specify the time first before we specify the input fault in output seeking well we specify the time after the input file oh and incidentally speaking I'm specifying that time the format being used here is hours minutes and seconds of course since this is a very short video we don't have to do this we can simply specify the number of seconds and ffmpeg understands that as well now don't worry too much about the difference between input and output seeking I'll talk about that in a minute for now let's take a look at how to actually specify the end point as it turns out that also two different ways to do this you can either specify duration of the final output or you can actually give an ending time step for the end according to actually stop the methods to do this as follows to give a duration you simply need to say - T followed by well how long you actually want your video to be to specify an end time you're gonna have to say - - and gif well the end time so why are there so many different ways of doing things well as it turns out there are very good reasons let's first talk about using output seeking and that is where we actually have the seeker part of the command come after the input file specification what this actually means is ffmpeg will open the file at the beginning and actually waste time decoding the first 14 seconds while not doing anything that is why when he actually make the command call you realize that the command line sort of sits there apparently idle for a while before it actually starts doing the encoding so come on light isn't actually being idle it's just basically sitting through the first 14 seconds of the video the advantage of doing things this way is that ffmpeg knows that this is the 14 second mark as a result you can tell it to actually go to the 18 of second and it will know what you want compared to be hey VI we've seen here two inputs seeking now an input seeking remember that we actually specify these fat points before specifying the input fault when we do things this way ffmpeg knows to jump directly ahead to the 14 second mark then of course means we save some time but there is a tiny drawback in a sense that ffmpeg actually thinks that well the video it has thoughts at here it recognizes this as zero seconds which is why we can no longer actually say we want to cut to the 18th second the 18 second is now a completely different place in a video so that's not going to work instead we are restricted to being only able to specify a duration in this case of course we only want to cut out four seconds which is why we say four so yeah as a very quick summary of what we've just said using input seeking as fast but we're restricted to only cutting by a duration using output seeking is slower but we actually have a choice whether we want to cut at a particular time stamp or if you want to cut by duration which is still of course accessible all right before we wrap up let's actually take a look at how we want to join multiple videos together using what is known as concatenation again concatenation also has two methods one method using a follow list and one method using a complex filter let's take a look at a full list first essentially your syntax now look something like this you have to say - F concat and your input becomes a text file containing a list of false instead of the actual files themselves your text file needs to look something like this every line needs the start of the word file followed by a fall name there can also be a fowl path specified here both absolute and relative file paths will work the alternative is to actually use a filter now this sort of works you know as you would expect you'll have to use the - I switch to bring in as many files as you need and then you simply have to use the concat filter and of course specified the relevant input streams to get ffmpeg to concatenate everything together you can specify as many inputs as you want you'll of course have to expand upon your list of input streams and you also have to tell the concat filter how many inputs they're up by actually using the end parameter and setting it to the number again concatenation using these two methods actually have their pros and cons I feel that the file list method is actually more convenient because you can easily generate a list of files if you want to use the filter method in a batch context you're going to have to sort of jump through more hoops to generate a proper command unfortunately the file list method actually has a drawback and that is in the fact that you do actually have some codec restriction in fact all the files in your file list must have similar codecs before this method can actually be used compare this to the filter method where this actually doesn't matter however restrictions still apply across the board your input videos actually have to be of the same physical dimensions there some other attributes as well that matter for example the pixel aspect ratio also matters and I believe the free read also matters as well so yeah whatever the case is concatenation has its fair share of limitations and you have to make sure that all the restrictions are being followed before I should be performing your concatenation so yeah if you've ever needed ffmpeg to do something more advanced or more complex for you well you've just seen two different tools that can really help you with that anyway with that sit that's all there is for this particular episode thank you very much for watching and until next time you're watching 0-6 watts UTV thank you very much for watching if you like this video consider checking out the rest of my work on my channel alternatively you may be interested in a playlist of my earlier work on computing and computer science topics if you'd like to show me some monetary support I am on patreon you can find a link to my campaign in the video description of course you can simply like this video or leave a comment I'll be sure to respond as soon as I can to keep in touch with my future uploads do subscribe to this channel and for even more updates check out the official Twitter account for this channel at 0 6 1 2 TV thank you for your support
Info
Channel: 0612 TV w/ NERDfirst
Views: 28,820
Rating: undefined out of 5
Keywords: ffmpeg, filters, tutorial, ffmpeg filters, filtering, filter, editing, filtergraphs, complex, filter_complex, mixing filters, combining filters, filter graphs, graph, graphs, timeline, enable, time, evaluation, equations, splitting, slicing, seeking, concat, concatenation
Id: hElDsyuAQDA
Channel Id: undefined
Length: 19min 30sec (1170 seconds)
Published: Tue Oct 04 2016
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.