How to combine videos together with ffmpeg

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
how's it going everyone it's Donald back with another video and today I'm going to show you how to concatenate videos with ffmpeg if you're not sure with concatenation means it essentially means if I have a video file a video file B I'm going to take B and stick it at the end of a this can be useful if you've split sections of another video out in the clips done separate editing and then you want to basically put them back together but there are going to be three ways to do this to them are really quick but have some conditions with them then there's a third one that um takes a while to do because you have to it involves having to do a transcoding and also the syntax is probably going to be a little weird but I will explain all that to you but the advantage of the third way is is that you can essentially take as far as I've used it any files with anything at any codecs and concatenate them together before we get started I'd appreciate it if you left me a like and subscribe to my channel if you haven't I've been really trying to grow this channel and any help would be appreciated now the hell the wave let's get over to my terminal and if we look at my directory here I have a bunch of files left over from me basically doing I'll call it ffmpeg mad science experiments now I'm going to show you the first way is using the D mixer approach to doing this the condition was being able to do this approach is that the aisles that you are wanting to concatenate together have to have the same video and audio encoding if you do this with files that do not have the same encoding when it you get the result it's probably gonna be a little borked I accidentally did this deal a day with a file and the videos were the same encoding but the audio wasn't so whenever it got to the part where it would start playing the second video the audio was we're all screwed up this is but that way so the way you do the D MUX er approach or concatenating files is you start with - F which forces ffmpeg to use a certain format when it's processing the data stream and there's a there's a cares a concat format which basically says hey I just want you to take these inputs and put them together that's that's basically what it's saying now the way you usually do this is you don't specify multiple inputs like you do some other ways you you put all of the files that you want to concatenate together and just just in text file doesn't really matter what it is and it will read from that and concatenate them together in the order they appear in the file to show you what I have I have a file here you'll see it called list.txt if we look at it real quick you will deceide there's two files in there it's going to be using this intro clip that I took for my bigger recording and outro a clip from the same recording and it's going to combine them together so let me get that clan back up the way I was doing it - f I can't today so we were to pass in that text file as the input which is a little different because up at this point any time I've been showing you anything you were passing in aisles like actual files this time we're passing in a list of files into as an input and we're gonna do - copy this prevents it from doing a transcoding gets good at basically just take the files and cut it as they are and just basically put them in another container format but by concatenating the streams together and I'm going to call this D MUX yeah I'm actually going to let this run because this should take like maybe barely even a second yes overwrite okay took two seconds so to show you real quick what these two things are separately let's look real fast so you see it's just a little recording from Animal Crossing I think this one's like seven seconds long yeah that's good and now we're going to show you the the outro that was appended on to it dude that's where car games like yeah so this one is about 35 seconds long it's just hurt basically showing off the thing that you made so assuming that the command had this ran worked what happened was it'll play the first part and then immediately start playing the outro so we're gonna try that right now so me the the MUX concat lamp before it's running you'll see the length looks right okay we're about five seconds in so should I start and they're good the these two video files have been concatenated together with no problems now the second easy fast way to do this is called the what's called a concat protocol this essentially works on the fact that there are some very few mind you very few video and audio encoding that allow you to do what's called file level concatenation this essentially means you can combine them in the same way that you can say just add text to the end of a text file you can simply just take the first five the first file and just slap it onto the end of the second one initiative works fine there's only the only video encoding that I know of off top of my head that this works is something called like MPEG transport stream which has that file extension of like dot TS and I have a couple of these in here that I have made I thought I did maybe I don't I will edit in a part where I make those real quick because I thought I had those somewhere oh wait never mind I know where those are those are and mine I think see videos my stuff yeah ok they are so the way this works if you have a encoding that can do file level concatenation which the way you do it with this is you see yeah okay so it's gonna look a little weird because instead of having using like a filter passing in a list we're using this very specific like con cast protocol and then you you put the word con cats and then you put a colon and then you start putting in the name of the the files so I have two here ones called intermediate and about TS no it's called intermediate one TS and I will show you those two Clips individually I think it was just like these little simple things I did for like five seconds to test this so we're gonna have intermediate dot TS and then you put a vertical line in between each file enter me intermediate 1.2 yes and then let's see then you do you your copying again because you're not doing a reading code and then I think you just riff I call you just write it out so I'm gonna call that a michael call this I will call it protocol I'm cat dot mp4 of those do TS yeah sorry done so let's look at those two files individually so let's run this this be me ah deja vu I'm seeing double this should be like yeah it's like 12 seconds okay now we're going to look at the second one it is second test now what we should have now is these two things combined so will their protocol so we'll let this play for a minute listen to me you get to hear me twice isn't it amazing and there you go and apparently it did okay so that is you have seen the D Mok Singh approach and you have seen the protocol approach now for the third one which is going to be kind of weird so let me go back to the directory I was in originally okay so this one is gonna be a little weird you the advantages though is that you can combine videos that have different encodings with the caveat as I mentioned that this does do a transcoding so the way that this works is you have to build something called a complex filter graph and I will show you what that looks like so this doesn't you don't pass any list of the files like you do with the first one you explicitly list pass in separate input sources for this one so we're gonna have the overwatch being intro mp4 there we have another one where it's the outro but I rien coded it to be like like flash media Bank some other flash video encoding now let the option you more for this it's called filter complex as you see now I must start a new line because this this gets a little weird as you can see in the preview now normally when you do filters and ffmpeg you it just takes the video streams that you're giving it from your input files does something to it and then automatically will use it in the the write the output of the file the the thing that you're reading coding out to filter complex you have to explicitly specify what streams of data you're working on and the syntax is gonna be a little weird okay so I'm gonna try to take the slow because it might be looking for you so the syntax for specifying what you're working on is this weird syntax where it's in square brackets there's a number there's a colon then you will use this usually either C of V or a so what this is saying is that I want to work on the first video input and I want to you I want them the first input file I want to use its video stream now if you're not for my programming background you see a zero and go what the hell what do you mean it's the first one so a very minor programming lesson but in programming whenever you have like a collection of like data and I like a some kind of code some kind of like an array or a list they are indexed starting at zero not one zero so when you see this and you see zero this is saying whatever this list of inputs is that I gave at the very start of the command I when to use the first one an easy way to remember this especially if you're like does now learning coding and trying to get your head into the game of the whole like and lists started zero is that whatever you would normally think it is just take one from it so I want the first one well in programming world the first one has an index of zero not one okay so try to keep that mind as I keep going forward and I'm still operating on some other streams of data I'm gonna have again the first input that I want to use a which is the audio stream permit and then I want to use one which is the second input and I want to use the video from it and then as you might guess I want to use the audio from it as well this is specifying what the data stream inputs are for the filter now the filter everybody uses called Khun Kat which sounds familiar as we've already used something similar to this in other areas and let's see it's equals and the inputs for this are in which specifies the number of input sources in our case there are two and then you have two other ones that you have to specify or at least every time I've used as you have to specify you have V which says of those inputs of those input sources how many video streams does each one have individually and this will also decide to how many video streams get written out from the from the filter and in this case we each have one and then my guess the same thing for a a each one of those sources only has one audio stream so don't only write out one audio now normally when you run a filter the normal way and ffmpeg this automatically gets sent out to the output file but in this case you have to just basically store this in a named location so the first output of this will be the new concatenated video stream and I'm going to call it out V you have to wrap the name of the data you've created in this the same bracket the square brackets intact and then the second thing it created will be as you might guess the audio stream and I'm will call this alt a now you can keep going with this if you have like multiple things you want to do but at this point I am done with the complex filter draft part and so we passed in some data streams we concatenated them and then store them in these these names out a and out B how do we tell if if MPEG don't use the just don't use the straight input from the the files use these new data streams that I have created well there's them there's a option called map and this tells that the Venn peg hey don't use the normal video streams from the input use the thing this thing that was created during some process and you have to use the same square bracket syntax so I'm gonna tell it hey I want you to use out B and then you have to do the same thing and for the audio I want you to use out okay and then finally you say whatever you want this to be called I believe that I heard you make this somewhere I did ever watch beanie complex so I'm not going to let this run because this like I said this is this wool transcode this this will take at least a few minutes yeah I'm not gonna let it over right so but to show you what it would look like as you recall this is just a simple maybe like 40 second long clip when they're both combined so if we look at the overwatch beanie complex you will see that it is combined even though these two video files at completely different video and coatings and probably yet improperly audio two coatings so there you go now you know how to combine videos quickly they have be the same encoding or if they're one of those really special cases where you can do what's called file level concatenation and you even know how to combine video files that have different encodings as far as I've used so far there is no restrictions with that I have tried it with a couple different combinations and they all were fine not to say that this made that may not work sometimes but everything enough time I've tried it it's worked fine so that's all I have for this video today if this helped you out at all leave me a like subscribe down below you get confused and has a question leave me comment down below and I will try to answer the best as I can y'all come on back now and I'll see you next time [Music]
Info
Channel: Donald Feury
Views: 8,910
Rating: undefined out of 5
Keywords: ffmpeg combine videos together, ffmpeg combine videos, donald feury ffmpeg, ffmpeg filter complex, ffmpeg combine multiple videos, ffmpeg demuxer, ffmpeg join videos, donald feury, ffmpeg concat, ffmpeg filtergraph, demuxer, web developer, programming, ffmpeg, feurious, spotifyd, spotify-tui, spotify tui, linux, concat videos, combine videos, tutorial, ffmpeg tutorial, join vidoes, filter complex, filtergraph, Donald feury ffmpeg tricks, Ffmpeg combine videos
Id: qjumeCB1iEg
Channel Id: undefined
Length: 18min 4sec (1084 seconds)
Published: Fri May 01 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.