Converting files with ffmpeg - the basics
ffmpeg is an open source video and audio converter. It is used by amateurs and pros alike to generate professional results. It is available for free for Windows, Linux, Mac OS and other operating systems. Because it's non-interactive it's controlled by entering a command, which might become quite complex, showing off it's incredible power and versatility.Whether you have to combine several video files or merge them with audio, flip or mirror a video, add effects (fading, wipes, transitions and more), or just want to covert a file from one format to another, ffmpeg does the job. Although it's a powerful video editor in the first place it even allows you to convert one audio format to another, and record videos (with audio) if you like. And the command line isn't one's cup of tea, there exist front ends, allowing for interactiveness.
If your choice is ffmpeg, go ahead and install it. I won't recommend any web pages, because while the official main page has executables for various operating systems, it lacks (last time I looked) front ends. Other pages providing front ends might offer tailored ffmpeg executables too.
And as for Linux (and probably Mac OS for Apple Macintosh computers), these operating systems come with a "package manager". A software pool which draws programs from Apple or Linux servers with all libraries and other things necessary, so no searching for a web page to download ffmpeg is necessary.
So go ahead and install it. On this page I want to show some of the basics of this powerful tool. We will barely scratch the tip of the iceberg, but you get a basic idea what the tool can and how to use it.
I'll focus on the Linux command line version of ffmpeg here, although I assume you can use the same lines for Windows and Macs. For Windows you might just use ffmpeg.exe at the command line.
The basic syntax is
ffmpeg -i input_file.mp4 [do stuff] output_file.mp4
Converting file formats
To convert a video (or audio) from one format to another you can use
ffmpeg -i input_file.mp4 output_file.mkv
The results might not be pretty, probably because ffmpeg lowers the resolution. There are switches, like telling the program what resolution to use, what frame or bit rate and many many other things. These usually hide behind vf=..., which stands for video filter.
Combining two video or audio files into one file.
Merging two or more files goes like
ffmpeg -i video_1.mp4 -i video_2.mp4 video_out.mp4
If you want to keep the quality (and I am sure you want), add "-codec copy", so the line looks like
ffmpeg -i video_1.mp4 -i video_2.mp4 -codec copy video_out.mp4
-codec copy does not re-encode the videos. Instead it just "glues" the files together into one - as they were. No quality loss here.
Suppose you have one video without audio and an accompanying audio file, you can combine them this
ffmpeg -i video.mp4 -i video.mp3 -codec copy video_out.mp4
Muting audio channel
Let's assume you recorded a video with your cam, filming ducks in a pond. Only later you realize you also recorded the sound of car traffic. To get rid of the audio by muting the audio channel, try
ffmpeg -i your_video.mp4 -an -codec copy your_mute_video.mp4
Note again the -codec copy so that the program does not re-encode the video. But if you only want to keep the video or audio part, there are -vcodec copy and -acodec copy. And those can also be written like
-c:v copy or -c:a copy.
A nice thing of the program is that you can often condense several processes into one command line. Here is how to add two videos and mute their audio tracks in one shot
ffmpeg -i your_video_1.mp4 -i your_video_2.mp4 -an -codec copy your_mute_video.mp4
Crop a video file
Want to only see some areas of the video, because some people in t eh background have the talent to ruin every recording? Now it becomes a little more complex (sorry, I promised only basics ;-), give
ffmpeg -i file.mp4 -filter:v "crop=408:210:0:0" -codec copy out.mp4
a try.
Trim the length of a video (and remove audio in one shot)
The following starts the video at second 22, ends it at second 52 and mutes the audio.
ffmpeg -i full_video.mp4 -codec copy -an -ss 0:00:22 -t 0:00:52 cut_video.mp4
The time codes also accept 1/10 of a second. So "-ss 0:00:22.7" could be used. That does not always work, because some video formats need a "full frame". If that doesn't come at 0:00:22.7 in this example the following full frame will be used instead.
Scale videos
To scale a video up or down, use something like
ffmpeg -i input.avi -vf scale="720:480" -c:a copy output.avi
Conclusion
That's it for this article. I tried not to go into the depths of this wonderful program, but give the reader a basic idea what it is capable of instead. Linux users have a man page as well as other comprehensive documentation about it on their computer already, once it is installed, if they want to did deeper. Then there are many sources found on various web pages showing all the bells and whistles. Enjoy your video edits!
Comments
Post a Comment