FFMPEG Introduction & Examples

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
I want to show you some of the things that have been useful to me we'll talk about basically about the program in general and then most of the presentation will be examples it's an open source project its main executables are ffmpeg that's for converting video and audio FF probe getting the characteristics of media files containers and streams and FF server which streams video and audio you can also incorporate ffmpeg into your own projects they'll give you a native executables so soo and DLL files it runs on all three major platforms Windows Linux and OS X it's it for introduction all the rest will be examples it's pretty common you might want to extract audio from a video file in this case we could extract an mp3 from an mp4 file so on the command line you specify ffmpeg - I and then your input file which in this case is the video file and then your output file there's no corresponding - oh like there is - I anything on the command line is not interpreted as an option or an input file is considered the output file in this case the audio is transcoded from AAC format and the input file to an mp3 format in the output file and I'm gonna start introducing some of the terminology that's used with ffmpeg and containers and streams in general so technically imagine that mp4 first list D machst into its video stream and it's audio stream and then the video stream is dropped the audio stream is then decoded from an AAC format and then it's put through a filter which encodes it into an mp3 format and then it's must back into the container format of mp3 it's good to know these these terms like containers and streams and formats because it comes up a lot on the command yeah yeah is it none of those Omaha Yokota's like hundreds of them if you're interested I can I've got that output of all the audio codecs that it supports in the video codecs and containers to some formats so this is just a really simple first example a couple times in the previous slide I mentioned that I knew the audio stream was in AAC format you know so how do you know that the audio stream was in AAC format you can use FF Pro for these kinds of queries it has a lot of the same command-line syntax as ffmpeg they share a lot of the same options so you can you can call FF probe - I and then your input and here's the relevant out output from that that command it tells you your container information up here at the top that the container was detected to be of type mp4 or m4a those are synonymous tells you the duration of the input file it's bitrate and then we get down into the streams the video stream and the audio stream the video stream is in a h.264 format with 1280 by 720 size per frame audio stream is in an AAC format so that's that's how I knew in the previous example the audio stream was in the AAC format something else to get used to with ffmpeg is the way that streams are identified so it says stream pound zero colon zero and stream pound zero colon one what this means is the zero means the first file 0 and 1 are the stream numbers within the input file that becomes relevant because you have to identify what you want to do with particular streams or particular input files some other things to notice about the audio stream is that the sampling rate is 44 kilohertz and as a preview we can have more than one input file on the command line so another thing you might want to do is it's just copy a stream out of an existing video file a common thing to do is copy the audio out of a video file in the previous example we transcoded the audio stream out of a video file we've went from an AAC format to an mp3 format you might want to just just copy it because well you could introduce losses by converting from one audio stream format to another and you just you just want a copy so a copy can be a whole lot faster this is how you could just extract an exact copy of the audio out of the out of a video file as with the previous examples the input file is specified with the - I option and then VM means video and none or drop the video we don't care about the audio ca means C means codec a means qualify it to the audio stream only copy is the it's the codec so we're we're saying we want to copy the audio out of the out of the video and what this results in is just a bitwise copy out of the video input file this results in a very very fast rip of the video file to an audio it's a it's a bit of a misnomer because nothing is being encoded it really is just a bit for bit copy you may want to reduce a media file size because it's too big to put on your storage or to stream so one way you can do this with with audio is to reduce the bitrate so again we specify the input file with - I a be 96 K a means audio B means bitrate in 96 okay means 96 kilobits per second why that's relevant is because there's a couple different ways that you can specify numbers to ffmpeg a lowercase K means bits per second an uppercase K or uppercase M means bytes and then you can also slip in an eye which means use 1024 instead of 1000 since we're decoding the audio we have to re-encode it and so this is much slower than just a rip of the audio stream it's much slower than using the copy codec the output file name determines what kind of codec will be used you'll see come into play a couple more examples bitrate bit and sampling rate sometimes are confusing to people so if you imagine bringing up this audio screen and something like audacity where you can see the time amplitude plot your bit depth would be the number of possible values on the vertical axis your sampling rate would be the time between samples on the horizontal access and then the bitrate is the combination of bit depth and sampling rate so effectively we're changing the bit depth because ffmpeg won't change the sampling rate so you may have a long video clip from which you want to extract a certain clip a short short clip from a bond clip so you can use this kind of a command-line syntax to get to get a short clip out of a long clip so in this case I had a blink 182 Las Vegas concert and the song I miss you starts at 13 minutes and 38 seconds into the concert and goes for two minutes we'll say the - s s says for the input only start passing frames from the input to the output at 13 minutes and 38 seconds into the input and - T is a duration how long do you want to pass frames from the input to the output we'll use the copy codec again this time with a shorthand there's no qualifier on the - see so this is the same thing as saying copy the video copy the audio and that should say apps for subtitles I want to show you something about the about this clip because it'll come up again so it's completely blank at first I don't know if you you saw that the reason for that is there's keyframes in in the video and where I specified 1338 wasn't rate on a keyframe so we picked up some difference frames which caused that which caused the beginning of the video to be messed up and that's called GOP or group of pictures group of pictures specifies how often you get a full frame versus a different spring and I'll show you some ways to to deal with that kind of issue but it was a good good example to get question for you how much you're gonna get into later on does that depend upon the source the video type that you have yeah that's definitely so like an API equality versus an MPEG quality yes yep you may want a way to quickly review a very long video one way to do this would be to take video snapshots at a periodic rate say once a minute or however often you need to do that here's a way to do it again I use the same concert video file specify the rate at which the input will be processed that's specified in Hertz so a point of one Hertz means every 100 seconds it'll pass and frame from the input to the output and it knows just by the dot PNG extension how to encode that output file and you get like a printout style string here and D resolves to the output one-up number of the frame so you can get like hundred frames out of those so go real quickly I have all the files here so if you want to see any particular example run I can run it but I figured it would be too long to run all the examples so in previous example we showed how you could reduce the an audio file size by reducing its bitrate so one way that you could possibly reduce the size of a video file is by reducing its resolution say from 1080 to 720 this example we specified the VF option V stands for video f stands for we're gonna do a filter on the decoded frames the name of the filter is scale negative 1 means keep the aspect ratio from the input file and so this is width and this is height we keep the aspect ratio from the input file but we want the new height to be 720 pixels this does involve re-encoding the input because we in order to get those frames to put them through a filter we have to decode the input so if you decode it and you've changed the the frames you have to read and code it so it will be much slower than using a copy codec it illustrates some some defaults that ffmpeg I specified two two fathers write the input file with the dot MOV extension and an output file with the not MOV extension so you may think initially that they would have the same kind of audio and video streams but it doesn't but they don't this was taken with a camcorder which used a different kind of audio stream then ffmpeg uses as its default when you specify a dot MOV file on the command line so it's kind of hidden in here that not only do we have to transcode the video frames because we've performed a scale filter on them but also it transcoded the audio frames because there's a default with ffmpeg to have the AAC format within dot MOV file we can we could change that to keep the original audio by specifying - C : a copy to use the copy codec for the audio input something John would like animated gifts he posted at Google+ that he hates on that so you could create a animated gif this is just like taking periodic snapshots so again we specify the rate at which the process the input and really so the command line is identical to taking video snapshots except we've specified a gif file as the output and we didn't put any kind of printf format string with an output file so all that all of the frames get put into a single animated gif a lot of times you want to take an audio file and replace the audio in a video file so you want to merge you want to merge a movie with a different audio stream so here's here's a way that you can do that and it's the first example of specifying two inputs on to the ffmpeg command line so we specify an audio revolution mp3 and video my son playing soccer we say we want a copy of both the video and the audio the shortest option says cut off the output to the shortest input so one of these is longer than the other soccer is longer than the audio so we'll just cut it off when the song ends and again this illustrates some defaults in ffmpeg that you need to be aware of in this output file we get the video from soccer and we get the audio from from the song but why didn't we get say the audio from my son's locker or why don't we get both audios you know how did it know which audio to take there's some defaults that it uses in this case it's the audio with the highest sampling rate if there's a tie then it takes the audio that was first on the command line there's some ways that you can get around this with for instance the map option if you want to override the defaults and specify which audio or video should be used in the output file quick way to make a a ringtone for your Android phone uses the same techniques that we had done before to make any audio file you need to make it less than 30 seconds and then copy it into SD card music ringtones so a lot of times you have a bunch of input files you want to concatenate them all together this is how you can do that use the F option on the command line which again means format the format is cat which means concatenate usually you have like a whole directory and you want to put these all together so you put them in a file with this this format especially by specify that file on the command line and usually you'll have a codec of copy and it'll just concatenate them all together into one huge output file here's some PowerShell for when I had to do this you know you don't really want to be typing this in by hand especially if you have some programmatic solar order to do so that powershell will create this file for you so this copy wouldn't work if you had multiple codecs would it just fail because you're trying to copy the same input output I'm not sure actually I I've already tried it with the same kind of streams and input files I'm not sure how you would do that whenever transpose oh yeah we have to transpose for sure and if it if it worked if - of concat even worked with inputs of different types okay so I've been referring to container streams and codecs a container is pretty much synonymous with a file format except in the case of streaming so a container is how you can put multiple streams how you can store multiple streams together yeah for instance video and audio for subtitles so typically that itself to be a file format streams are the media components the the video the audio subtitle see some common video streams are h.264 and mpeg-2 some common audio streams are mp3 and AAC put it all together containers are D most into streams and then the streams are decoded into frames and that's where where your filtering happens then the frames the filtered frames are encoded back into streams the streams are MUX together back into a container which is usually a 5 GOP I mentioned before stands for group of pictures so in a video every so often you get a full frame for modern modern video streams every so often you get a full frame and then subsequent frames are some kind of differential frame because most of the pixels enough and a video frame don't change from one frame to the next so it's inefficient to keep on specifying the full frame there's different kinds of differential frames here if you're if you're interested but basically the GOP specifies at what interval are those full frames included in the output a larger GOP means a smaller file size typically because you're not specifying all the content all the time but then seeking it can become difficult if you remember when I tried to get a song out of the whole concert from a previous example the first few frames were blank and it's not like that in the output file so there's some playing around that you need to do with GOP depending on what your use case is general tips for using ffmpeg the order of options matters a lot for instance if you put the SS option on the command line in front of one input file or in front of another input file or at the in front of an output file they can be in completely different things so if you're having a problem where the command is not working like you I think it should be make sure your options are in the right place you might want to use ffmpeg and programmatically like kick it off from another program and you don't want all the licensing stuff to to be captured so you can use specify a lot of level panic will make that all go away that's why and n have to do with if you specify an output file that already exists you want it to overwrite automatically or never never overwrite and cancel the commands you can get the help with by specifying - H and then I recommend just redirecting that to a file and you know looking at it and a text editor instead of the command line any questions if you wanted to use this like including like an app or something one of the with certain video codecs and thick like h.264 some of the MPEG codecs technically you have to pay a licensing fee per CPU i think it's only like $1,000 so if you were gonna use this in a production that'd be better just pay I would say pay a thousand dollars with a CPU that's gonna be doing doing your processing but I don't know if any other licensing considerations definitely look at the help from - H and then there's the best best documentation is right on their website I wouldn't I mean I've really looked around a lot and I haven't found good documentation anywhere but their website ffmpeg work
Info
Channel: cbttjm
Views: 80,347
Rating: undefined out of 5
Keywords: FFmpeg (Software), Software (Industry)
Id: BiMP_hN8f6s
Channel Id: undefined
Length: 20min 43sec (1243 seconds)
Published: Fri Feb 13 2015
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.