I recently discovered the wonders of ffmpeg, a command line based utility designed to convert media. Instead of messing around with online converters, or trying to use some “free” program that doesn’t quite do what you want — you just plug in your input and output and ffmpeg does all the work. As I’ve used Ubuntu more and more I have discovered that though people have come up with a number of good interfaces and programs, there is real power in the peculiar, off-putting syntax of the command line. Once an adjustment to accept the command line is made, things can progress smoothly. If you have any problems let me know in the comments and I will answer you and amend this guide. It should be noted that this guide is designed with Ubuntu in mind. Now, on with the brief ffmpeg guide.
Installing
- Open a terminal window (when you don’t know where to find a program, hit the Windows button (known as the super button by Ubuntu) and type the name into the box that appears).
- Type
sudo apt-get install ffmpeg.sudomeans do this as root a.k.a. administrator.apt-getis a program,installis a function of the program, andffmpegis the parameter to theinstallfunction telling it what program we want installed. Terminal will print some text, it might say that you already have it, excellent continue onwards. Else, if it gives you the option to install it, typeYand let it continue on its merry way. - Type
sudo apt-get install libavcodec-extra-53. This is an library that has additional codecs that you’ll probably want. - Now you should be all set up to start converting
ffmpeg Commands and Structure
ffmpeg has a lot of commands for manipulating media. The program is controlled through the command line. A basic command that you might enter into terminal looks like this:
ffmpeg -ss 00:00:10 -i gold.mp4 -t 00:03:33 -acodec copy -vcodec copy gold.mp4
Notice that you always start the line with the program you want to use (except when you are treating the running of the program in a certain way, such as with sudo. Next comes a series of option-argument pairs, options for the program followed by the value of that option: -option arguement. One example is the input option followed by the name of the input file -i gold.mp4. At the very end of the command is the output file name. Notice that there is no -option preceding it, it is simply the parameter entered into ffmpeg (like ffmpeg was the parameter for apt-get install). It’s not necessary to specify every option as most have default settings if nothing is specified. In ffmpeg Here’s a list of some of the options for ffmpeg:
-ss hh:mm:ssSpecify the start location. Note that this should come before-i-i xxxxx.yyyThe input file ffmpeg will base this operation on.-t hh:mm:ssSpecify the duration of the output file (relative to the start location). Note that this should come after-i.-acodec codec-vcodec codec-ar xxxSpecifies the audio sample rate. If unspecified it will use the default of the codec or the same as the input file (I'm not quite sure which). You do no good specifying a sample rate higher than that of the input, because it will yield no better quality. On the other hand, a lower sample rate will make for a smaller file (at the cost of quality).-vnDisable video recording.
The output audio codec. Most of the time ffmpeg will guess this parameter automatically based on you output file. For example if the output file is gold.mp3, then ffmpeg will automatically use libmp3lame as audio codec, no input required. The only time I've needed this option is to specify something other than what ffmpeg was automatically guessing, or to specify -acodec copy, which makes ffmpeg use the exact same audio codec as the source.
Used for specifying the video codec to use. All the usage rules of the -acodc apply to this one. Don't forget -vcodec copy if you want the output video to be the same as the input.
Converting
ffmpeg -i -ss 00:00:10 gold.mp4 -vn -t 00:03:33 gold.mp3
The above line takes the input file gold.mp4, starts ten seconds in and records for a total of three minutes and thirty-three seconds, before outputting the file as an mp3.
I am still pretty new to this. One thing I can't understand is if you enter something such as ffmpeg -i gold.mp4 gold.avi you get a resultant video that is of really low quality. Perhaps this is just due to codec limitations and/or ffmpeg's automatic guessing, I'm really not sure.
Trimming
ffmpeg can be really useful if you have a video and just want a section of that video. In that case, type:
ffmpeg -ss 00:00:10 -i gold.mp4 -t 00:03:33 -acodec copy -vcodec copy gold_trimmed.mp4
This line will take the input file gold.mp4, start ten secods in and capture a total of three minutes and thirty-three seconds, then output to gold_trimmed.mp4 using the exact same audio and video codec settings as the source. Note that the input file extension is the same as the output, and the -ss parameter comes before the -i and the -t come after the -i (I'm not sure why that order must be obeyed, but if you mix things up the results are off). Make sure that -acodec copy and -vcodec copy are specified, else you get a lower quality result (maybe just because of encoder defaults).
Willy's Disconnected Thoughts on Randomness








