using ffmpeg for video converting

ffmpeg is a mighty tool for dealing with videos. Around the ffmpeg core is a rich ecosystem with video-editing related tools. First, we look at some handy examples to get a feeling how to deal with ffmpeg.

Converting different file formats

Getting basic information about a video is as easy as:

ffmpeg -i input.avi

Converting an mp4-video to an avi-video with ffmpeg:

ffmpeg -i input.mp4 output.avi

The quality of the output can be defined as well with a number between 1 (high quality) and 50 (low quality). If you output-video is an avi you use the -p parameter. If your output-video is mp4 you use the parameter -crf instead. Have a look at the exmaple:

ffmpeg -i input.mp4 -q 30 output.avi
ffmpeg -i input.avi -crf 30 output.mp4

Use ffmpeg to convert an input-video to an output-video and set the framerate (parameter -r) of the output video to 5 frames:

ffmpeg -i input.mp4 -r 5 output.avi

Scaling a video can be done with ffmpeg as well. Use the scale video filter. This filter has two parameters, notice that the second one is -1, this means that the scaling for the y-axis is proportional.

ffmpeg -i input5mb-1280x720.mp4 -vf scale=300:-1 out.mp4

Changing colors by using ffmpeg video filters

Convert input video to a greyscale output video with ffmpeg (see the -vf videofilter parameter):

ffmpeg -i input.mp4 -vf colorchannelmixer=.3:.4:.3:0:.3:.4:.3:0:.3:.4:.3 out.avi

Convert input video to a sepia output video with ffmpeg:

ffmpeg -i input.mp4 -r 15 -vf colorchannelmixer=.393:.769:.189:0:.349:.686:.168:0:.272:.534:.131 out.avi

Joining (concatenate) and cutting videos

Cutting video with ffmpeg is simple. You want to specify a start and end time to convert only a certain timeslice? No Problem. The parameter -ss 30:15 let the video start at 30 minutes and 15 seconds. The parameter -t 40 defines the length. Take care of the parameters orders. This example cuts a 40-second lasting piece and starts at 30 min and 15 seconds:

ffmpeg -ss 30:15 -i input.mp4 -t 40 output.mp4

You can even join (concatenate) videos together with ffmpeg. Concat two avi-videos together can be done with this command:

ffmpeg -i "concat:part1.avi|part2.avi" -codec copy output.avi

Joining mp4-videos doesn’t work the before mentioned way. Here we first create some intermediate ts files and join them afterwards:

ffmpeg -i in1.mp4 -c copy -bsf:v h264_mp4toannexb -f mpegts tmp1.ts
ffmpeg -i in2.mp4 -c copy -bsf:v h264_mp4toannexb -f mpegts tmp2.ts
ffmpeg -i in3.mp4 -c copy -bsf:v h264_mp4toannexb -f mpegts tmp3.ts
ffmpeg -i "concat:tmp1.ts|tmp2.ts|tmp3.ts" -c copy -bsf:a aac_adtstoasc result.mp4


Caturing video from webcam with ffmpeg

Capturing video from a webcam with ffmpeg and store it in output-video.
(It is important to know the name of your webcam device. In my case, it is /dev/video0 under linux. You can research this with the command: ffmpeg -sources)

ffmpeg -i /dev/video0 out.avi


Linux Tutorial Part1

These tutorials explain the Linux operating system (os) step by step. Starting with simple examples and getting more advanced each lesson.

The line where we type in the commands is called the prompt, the blinking something right to it is the cursor.

Lets show who is logged in:


And the hostname of the computer can be shown with:


As you can see, username and hostname are contained in the prompt.

If you want to know the name of the operating system, you can use:


How long the computer is up (not rebooted since) shows the following command:


Clear all the stuff on the screen with:


If you using the arrow keys (up and down), you can browse between the commands you already entered.

When you want to know in which folder you are, use:


It’s short for: print working directory.

Let’s go to your users home directory by typing:


At this location, all the files related to your current user are stored. You home-folder is a special folder. The tilde sign „~“ is a synonym for your home folder. Instead of typing „cd“ you can type „cd ~“ as well. When you’re in your home folder you can see the tilde in the prompt. The tilde sign is a variable. You can output its content to the screen:

echo ~

Create a directory named garage withe this command:

mkdir garage

mkdir is short for: make directory

Most important command of all is „cd“. It means change directory. With this command you can browse in the directory tree.
Let’s switch to the directory „garage“ you recently created by typing:

cd garage

The prompt, by the way, also shows you in which directory you are. (So you don’t have to type pwd all the time)


If I want to go back in the directory-tree, like one level up, we use:

cd ..

Don’t forget a space between cd and the two dots. The two dots are a symbol for the upper (superordinate) folder.

If you type the first letters of a command, try to press two times the tab-key, and the command will be completed.
This will save your time. It’s one of the most useful ways to increase your working speed.

Linux Tutorial Part2 >>