Linux Tools - FFMPEG to Convert and Resize Video Files

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
please remember that the complete information for the class that you are about to view is at Eli the computer guy comm not only do we have our videos there but we have parts lists diagrams pictures and even complete code examples so if you are watching this video and you want more information please go to Eli the computer guy comm welcome back as you know I am Eli the computer guy in today's class I'm going to be showing you how to use ffmpeg on Linux in order to resize and convert your video files so in the modern world we are surrounded by video files but one of the problems that we run into as many times when we go to play those video files on whatever device that we want to use either it is in a format that that device does not understand or possibly it's in a size that's just too darn a large you know some of us some of us for some stupid reason have decided to start trying to encode our videos at higher and higher rates and so like if you want to watch one of my videos and you download it it may be at 1080p 60 frames per second and so it may be a very large file and you don't necessarily want to put that large file onto your smart phone your iPhone your mobile device and you may be sitting there going oh if only I had this video but in simply a smaller size I don't need 1080p for 60 frames per second I don't need 4k for 80 is fine or possibly possibly what if you only want an audio file so a lot of people you know they they have their their favorite content creators that they follow and their content creators are frankly too lazy to create podcasts it's true it's true so you sit there and you download the video file and like darn it why doesn't this person just create audio files to make my life easier well one of the cool things with ffmpeg is it's it's actually very very easy to be able to turn a video files even just simply to mp3 files so you can take the of the content on the road and you can simply listen to it and you don't have to worry about dealing with the full video so ffmpeg is an incredibly good tool this is one of those things don't overthink it don't overthink ffmpeg ffmpeg is incredibly powerful and it's great because at the command line basically you only have to put in a couple of commands you simply do ffmpeg - I for the input what video file you're inputting and then you say and simply say what the name of the output file should be and then what the extension should be so basically if you have an mp4 video file and you want to turn it into a dot MOV file you literally just say movie dot movi and it will auto convert it into it to a movie file if you want an audio file you simply do whatever the name is dot mp3 and it'll turn it into an audio file so that's one of the cool things about ffmpeg not only is it actually really useful but it is incredibly easy to use so the warning warning Will Robinson warning warning for today is before before before you think ffmpeg has completely screwed the pooch and out loaded a piece of crap that is completely unusable for you make sure to actually take the video file or the audio file that you've created and actually use it on a different system or the mobile device that you're planning to use it on so one of the things whenever I do these demonstrations I do these demonstrations in a virtual machine on my macbook pro so I have MacBook Pro I have VirtualBox and within VirtualBox I have an instance of Ubuntu desktop and I use that to do a lot of the demonstrations to show you what's going on here's a curious thing here's a curious thing I may have not given my monty desktop operating system very many resources again I didn't want to overload my computer so I didn't give it very many resources I haven't optimized it to really be a desktop computer so one of the curious things is especially since it's running within virtualization is when ffmpeg spits out the the finished the finished file and then I try to play it within the virtual machine it's like water what did ffmpeg do oh I thought this wasn't gonna be a great great product and it's obviously just garbage that's not ffmpeg fault that's the the crappy ass virtual machine that you're trying to play the finished file on so one of the things that I would say is like what I've done and I'll show you in the demonstration today is I've connected to a shared directory on the host machine so basically I have the MacBook Pro then I have VirtualBox with in VirtualBox I have about two desktop so for a bunch of desktop I've simply connected to the shared folder on the Mac and then what I do is I copy and paste the outputted files from from the Ubuntu from the ffmpeg into that shared folder on the Mac and then I open up in the video or the audio files in the Mac so that that actually will show me what the files will play play like and how they'll actually display on a full fledge system so this may be one of the issues that you run into again this is one of those weird things with the Linux world Linux is great don't get me wrong Linux is absolutely a wonderful machine but especially if you're only using Linux for demonstration purposes if you're only using it for like projects and lab environments one of the issues you get into is again with some of this these types of things where you're used to just being able to very easily consume it on a Windows platform on a Mac proper platform sometimes in Linux and can be a little bit more difficult and so one of the issues you may run into is ffmpeg will output something if you simply go and try to outplay that outputted file from your Linux especially a virtual machine how it may play will be incredibly substandard that's just something to keep in mind so it's not necessarily ffmpeg fault take that file put it somewhere else put it on to whatever your planned destination is play it there see how it works I would bet you nine times out of 10 when you do that you'll realize oh that's the issue so now that you have an idea of what's going on let's go over to the demonstration computer and I'll show you how a ffmpeg works so we're going to be installing ffmpeg onto the system I'm going to show you the commands for how to simply convert a file from one format to the other and then one of the things I'll do is I'll actually show you how to use a command in order to resize your video files so this can be an important thing again imagine if you have a if you have a 4k video file or a 1080p video file and you're just simply going to be watching that video file on a little mobile device if you take that down to something like 480p that way you may get a fine a fine video a video file that you can use but it will be a lot smaller and easier to use so what I'm going to be showing you how to do today is how to convert the video files and then how to resize the video files so that let's go over to computer and I'll show you how this works so here we are at my demonstration machine again I am using a MacBook Pro and on that I've installed VirtualBox within VirtualBox I've been installed Ubuntu desktop I am using 18.04 LTS but basically any version of Ubuntu it should work for you I am using the graphical user interface again the desktop version of Ubuntu but do you realize that ffmpeg is a command-line tool so if you don't need the the GUI component you can run this from just the command line server again if you don't need any of the graphical stuff so just kind of keep that in mind so that let's login with my super-secret password of 1 2 3 4 5 6 and now we are logged in now the first thing I have opened up I just did want to show this to you is I have these two folders and so basically this folder right here this is the ffmpeg test folder and it's sitting in my home directory so these are the examples that I've created playing around to this particular class and these are all sitting on this particular Linux machine again one of the issues you run into though if you try to double-click if you actually try to open up these files it's a mess it's just not good it's just not good so one of the things that I did is I connected I connected to the shared folder on my macbook pro so on the host machine and basically what I did is I copied and pasted these these files into that folder on the host machine so that I can then play the files right so these these are actually on the host machine and if I go here I can go to - to me you go to public so what I connected to is the public and then I can go and basically I can play any of these files that I've pasted there so if I want to go when I see you want to see this to a hundred three hundred this example that I did I can simply double click on that and as we can see that that is actually playing so again this is what I would recommend that you do is that you basically offload the finished the finished files onto some other device before we try to play them because again I don't I don't even want to try to play them on this machine right now because it's just it's just so bad so anyways with that let's uh let's get to the terminal so you click on that little show applications thing down there if you don't have it showing up you then type in terminal up at the top and you hit enter once you're here the first thing that we're not going to need to do is actually install ffmpeg ffmpeg is a well-known tool so it is in the standard repository so we can simply do sudo apt-get install FFM misspelled that hit enter password is one two three four five six we hit enter and now it's going to go through and it's going to install anything for ffmpeg there's no there's no configuration files there's no real settings for you to modify basically this is just the command-line utility you feed a commands you feed it options and will do what you want so with that let's clear the screen the first thing we need to do is make sure what directory are in so PWD so we are on the Bob's home directory then LS - l to see what files and folders are here and so the folder that we want to go into this as our examples is ffmpeg tests so we're going to go into CD ffmpeg uppercase T est and now we're in there once we're in there do LS - L and now we have all of these different files so these are all the different examples that I've created now I'm not actually going to run through and actually do the examples for you because it takes a long time to do again one of the things we're thinking about is it's actually going to have to encode the video files which means it's going to have to open up essentially open up one video file read the information from that video file and then save it in the new format to a different video file and that can actually take a substantial amount of time so that that's one thing to realize this is not a copy and paste routine here this is not a you know three-second routine basically you're gonna plug in whatever the the the code is whatever you want to do is and then go grab a cup of coffee so that's an important thing to realize so let's say with this let's say I wanted to do things with this vid one dot mp4 file and that's actually what I did in order to create all these different demonstrations let me clear the screen and so the first thing if all I want to do is modify or basically convert the mp4 file into a different format all you have to do in order to do that is ffmpeg then you do space - I so this is the input what is the input file so we're gonna say what vid 1 mp4 so that's one of the the files that's there and then literally all you have to do is give a name and give an extension for the output file you want so you can just simply put out put file so you can name this whatever you want and then if you wanted this to be a MOV movie that's literally all you have to do so this calls ffmpeg the input it asks what the input is you say the input is bid 1 dot mp4 and the output file is you gotta be whatever the name is dot MOV and this will literally this will literally simply convert the mp4 to an MOV file the cool part is again the cool part with this and this may work what mate might be very useful for you is simply by doing this by simply doing mp3 that will literally turn the video file into an audio file so that you can play it so again if we go down here literally that's what I did sorry this audio mp3 file and that's all I did so i p-- this exact command and i simply did audio mp3 and the result was so you can see that then gives you the audio file if you want to listen to things in your car or whatever else that's an easy way to get the audio file so that's the basic way to simply if all you want to do is convert your video file into a different file format again dot MOV dot mp3 avi possibly whatever else this is literally the only command you have to worry about now the next thing that you can play around with is then resizing your video file so this can be very important if you're gonna be putting video files up online so again what if you're one of these people that's care that YouTube is gonna die YouTube is gonna die YouTube has got a die I need to have my own website and be able to distribute my own video content well one of the things is if you try to distribute your own video content you're gonna find out the problems of trying to distribute 1080p video files especially if you're not you know pretty good in the technical realm and understand how streaming services and all that work so one of the things that you may want to do is at least for the time being what you could do is you might want to shrink your video files so you're like okay well I have 1080p files but those are too large for me to put on my website easily so what if I get to shrink down the size of those files so that they're easier to embed on my website just as normal files and then later I'll figure out how to do the streaming service or or if you want to get more complicated and we'll talk about this in another video you could actually create your own script for multi bit rates to a chain so ffmpeg would take the original file it would encode it to 1080p and it would encode it to 720p and it would have coded 480p and it would encode at 144 and it would encode it to audio and then using using a modern streaming server and a player basically what's called a video player you can do something called multi bit rates to a chain where the video player and the streaming server they can communicate with each other or figure out what the most appropriate video file is to send to the end user or based off of the bandwidth and the speed and then it will be able to flip through those those different versions so basically I'm going to show you how to resize a video today so the first thing to do if you want if you want to resize a video file is simply we going to do what we have here so let's say we have ffmpeg you know I the input of a vid one at dot mp4 and then after that we're just going to use a couple of things so that the two options that we need is verbose and force so basically what this is going to do is this the V you may not need it's just going to tell us what's going on but the force is to actually force the file to be shrunk to whatever size we're gonna give it so with that we're then simply going to say so scale equals and we're gonna do width and height so for a 240 this will be 352 by 240 so this will give us 2 for TP and then we simply put the output dot mp4 let's say alright so basically what this is going to do we call ffmpeg we then say what the input is the input is going to be this video file then we're gonna say verbose force and then we're going to give it a scale the scale is going to be 352 wide by 240 tall and then we're going to output it to this particular file and so then we will get that smaller output so if we go over and we look at some of the examples that are created let's say here so like I create a 320 example so if I open up vid 1 so vid 1 was the original video file and if we take a look here we can see that's 305 Meg's right so I open this up and we can see ok this is this is more or less the type of video file that you're used to looking at right but you're like well I'd like something to be a little smaller again if this is showing up pretty nice on a MacBook Pro display and I think my viewers are going to be watching this on their little iPhones then I don't necessarily need a 300 Meg file so what I did is I created a 320 version here so the 320 version you'll see this is only 23 Meg's and then if you look at the resolution now it's pretty pixelated welcome back again so the audio the audio still sounds fine but you can now see that it is much more pixelated now if I shrink this down again imagine I shrink that down to that size so imagine that's now on a smartphone that may look a little better if I wanted to make it even smaller than that I created this you know hundred pixel cross version that goes down to eighteen point five Meg's so think about that that's a video file it's a video file it's a crappy video file it's eighteen point five Meg's oh if I open that up that's a video file I mean you may feel drunk watching it but I don't know maybe there's a purpose for this but anyways this is where you can go through and you can figure out again for the device how you think people are going to be consuming it you figure out what resolution is best and then you figure out what size constraints you're dealing with and you can shrink it down now here's one of the issues though one of the issues you get with this scale is what if you don't know what these numbers should look like so 240p so 240p means 352 wide right so you actually have to go to go to a little google research to make sure you know what the scale should look like because one of the issues you run into if you plug in these numbers manually like I've done here is you can get something weird so I did this 100 by 300 so basically what I did here for the scale is I did 100 wide by 300 tall just to show you what a mistake might look like and if I click on this this is literally the video file right so if I if I increase the site well I can actually can't increase the size of the flare it's a kind of a kind of stuck that way right and so that's one of the issues you can get into when you're trying to manually scale your video file is you can just screw it up now this this is obvious like if you do you know 100 by 300 that's very obvious you know there's a problem one of the issues you get into with this is what if you just screw this up a little bit right so you do 240 what if you do 240 by like 340 or something you know one of those where oh it's off the aspect ratio is off but as [Music] look and then you're looking at it and you're like oh this doesn't this doesn't seem right but it's not bad enough to really know what the problem is you can run into that kind of issue so one of the things that you can do is if you want to keep the aspect ratio but like you just want to put in the width so let's say I know what I want the width to be but I'm not really sure to keep the aspect ratio proper I'm not sure what the height should be one of the things I can do here that's before I'm used to using the mouse let me scroll back one of the things I can do here is I can do negative one so basically what this negative one does is it says keep the aspect ratio so however however tall and wide it currently is when we shrink it down to 352 then keep the aspect ratio for the height so this might be very important now especially with people creating video content with many different devices like with a lot of the devices people are using now the aspect ratios aren't necessarily the same so for a while there we were all using the same aspect ratios for our video files and so you can manually plug in aspect ratios and more or less horseshoes and hand-grenades you'd be fine one of the issues though is sometimes we're creating video files now we're creating square video files sometimes we're creating video files were created horizontal or horizontal vertical anyways vertical versus horizontal whatever right so we're doing video files in different ways now so one of the problems is is if somebody gives you a square video file and you don't realize it and then you scale it manually so you actually plug in the specific numbers how you think they should be the result yet that you may get maybe the equivalent of this maybe a hell of a lot closer to this than what you're looking for so one of the cool things here is you can do this so scale equals so this is whatever the width is then you do : and then you simply do negative one and what that does is that will keep the aspect ratio so in order to do this you do have to make sure you have these options - V F again for both and force and then this will scale your video file and keep the aspect ratio so that's a basic demo raishin of how this works again if you want to see just just to see why I'm not going to actually show everything to you if I hit enter now we can see that once I actually start the process basically this is literally what you're going to be seen for however long it takes again very important thing to understand the longer or the bigger your video file is the longer this process will take and the fewer resources your machine has the longer this process will take so again if you're running if you have a large video file and you're running this in a crappy virtual machine it may take forever to encode a video so if you're playing around with ffmpeg I would highly recommend even if you have high resolution videos make them short so like one minute of high resolution video so that it doesn't take forever to actually process those video files when you're playing around with it but that's really that's really how ffmpeg works so there you go now you know how to use ffmpeg in order to convert and resize your video files again in this modern world there is so much video content out there and again one of the big problems that we all run into is how to take that video content and then actually turn it into a format that we can use possibly the video file you have is in a format that your your computer or your device can't play so possibly like an FLV like a flash video file from years ago that's how I originally encoded my video files you know ten and a half years ago so maybe you have a bunch of flb files and you want to turn them into mp4 files and you're not really sure how to do it ffmpeg can do that for you again let's say you're like wow I really I really like this particular content creator but but I want to listen to them while I'm driving in the car and even though I have a mobile device and I can play a video file on the mobile device playing video files and mobile devices is different than audio files right with an audio file you can have it play while you're doing other things it doesn't take up everything on your mobile device the way a video file does and so this way you could download a video file simply all you do is again you ffmpeg - ah a space - aye from the input you give the video final space and then whatever you want the name to be and simply dot mp3 and that is literally all you have to do in order to turn that video file into an audio file and now away you go again one of the things to be thinking about one or think about command-line in the linux world this is useful as just a one-off tool but where this becomes very powerful is when you start using this in scripts for things like your servers so again basically you can come up with something where you dump a hundred or a thousand video files into one directory and then you create a script so that your server just sits there knocks through and processes all those video files to output whatever is that you want again where this becomes very valuable it's like a Systems Administrator type thing if we think about infrastructure is if you're going to be distributing video content this is how you're able to create multiple quality video files if you're going to be doing something called multi bitrate sweater so if you're watching this video on YouTube or you're watching this video on Vimeo right depending on what your internet speed is YouTube or Vimeo or whatever site will determine the best quality video file to present to you so there's actually a numerous different video files so you have a 1080p version of 720p version 480p version of 360p version a 144p version and maybe an audio version right and so what happens is with these modern web browser video players they are able to communicate back with a streaming server they figure out what the internet speed is and then basically they figure out what is the best video file to present to the end user right okay so this person has a very fast ISP connection they get 1080p oh this person is a little bit slower well then we'll give this person a 320p how you can make this whole process a lot easier to actually implement is again if you come up with a script you basically upload your high quality video file into some directory your server then picks up video file it then converts that video file into two three seven and different versions I think like Netflix uses like ten different versions for how they do multi various watching so you create helmet however many versions you want and then you can have the whole infrastructure work that way so again ffmpeg is a very valuable and useful tool just for one off again literally type in in the command line and going for it but where it becomes really really cool is once you start using these scripts for servers and you can start to do a lot of fancy stuff so as always I enjoy doing this class and look forward to seeing the next one if you like the content that I create please think about going to Eli the computer guy comm and becoming a member or donating please understand that all the educational videos are in front of the paywall that includes the videos that includes the notes the diagrams and the code example all that is freely available and in front of the paywall but if you want to watch opinion videos or if you want to be able to comment you do need to become a member membership is $5 a month or $60 a year and gives you access to those opinion videos and the ability to comment if you don't want to become a member you just want to give a one-time donation there is also a donate button where you can do that please understand in order to provide the education that I am it does cost money the servers cost money equipment cost money travel cost money all of these things cost a reasonable amount of money and the fact of the matter is is YouTube's advertising program no longer supports creators the way that it used to so if you want to these classes to continue to stick around and you find them to be valuable please think about either becoming a monthly member or donating a few dollars for this project
Info
Channel: Eli the Computer Guy
Views: 7,182
Rating: undefined out of 5
Keywords: Eli, the, Computer, Guy, Repair, Networking, Tech, IT, Startup, Arduino, iot
Id: QTUzfshfOJw
Channel Id: undefined
Length: 27min 56sec (1676 seconds)
Published: Tue Apr 07 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.