Install ffmpeg

If we have root rights, we can install ffmpeg via package manager. On Centos 7, run the following command:

yum install epel-release
yum localinstall --nogpgcheck
yum install ffmpeg ffmpeg-devel

If you want to download binary releases, this site can help you. It has binary release for ffmpeg, ffprobe for different systems. It seems that the provided ffmpeg is statically linked, so all you need is that one file to get to work.

This site alao provides binary release for ffmpeg.

Run command ffmpeg -version to verify that ffmpeg has been correctly installed. You will see the following output:

ffmpeg version 3.4.8 Copyright (c) 2000-2020 the FFmpeg developers
built with gcc 4.8.5 (GCC) 20150623 (Red Hat 4.8.5-39)
configuration: --prefix=/usr --bindir=/usr/bin --datadir=/usr/share/ffmpeg
--docdir=/usr/share/doc/ffmpeg --incdir=/usr/include/ffmpeg --libdir=/usr/lib64
--mandir=/usr/share/man --arch=x86_64 --optflags='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2
-fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64
-mtune=generic' --extra-ldflags='-Wl,-z,relro ' --extra-cflags=' ' --enable-libopencore-amrnb
--enable-libopencore-amrwb --enable-libvo-amrwbenc --enable-version3 --enable-bzlib --disable-crystalhd
--enable-fontconfig --enable-gcrypt --enable-gnutls --enable-ladspa --enable-libass --enable-libbluray
--enable-libcdio --enable-libdrm --enable-indev=jack --enable-libfreetype --enable-libfribidi --enable-libgsm
--enable-libmp3lame --enable-nvenc --enable-openal --enable-opencl --enable-opengl --enable-libopenjpeg
--enable-libopus --disable-encoder=libopus --enable-libpulse --enable-librsvg --enable-libsoxr --enable-libspeex
--enable-libtheora --enable-libvorbis --enable-libv4l2 --enable-libvidstab --enable-libvpx --enable-libx264
--enable-libx265 --enable-libxvid --enable-libzvbi --enable-avfilter --enable-avresample --enable-libmodplug
--enable-postproc --enable-pthreads --disable-static --enable-shared --enable-gpl --disable-debug
--disable-stripping --shlibdir=/usr/lib64 --enable-libmfx --enable-runtime-cpudetect
libavutil      55. 78.100 / 55. 78.100
libavcodec     57.107.100 / 57.107.100
libavformat    57. 83.100 / 57. 83.100
libavdevice    57. 10.100 / 57. 10.100
libavfilter     6.107.100 /  6.107.100
libavresample   3.  7.  0 /  3.  7.  0
libswscale      4.  8.100 /  4.  8.100
libswresample   2.  9.100 /  2.  9.100
libpostproc    54.  7.100 / 54.  7.100


suppress excessive logging

Every time I run ffmpeg command, its version, compilation configuration and libary info is printed on the command line. This can be disabled using -hide_banner option:

ffmpeg -hide_banner ...

We can also use -loglevel option to specify the verbosity of logging.

ffmpeg -loglevel warning ...
ffmpeg -loglevel info

The log level quite will silence any logging. In case you use -loglevel, it is useful to specify -stats to print some running stats for ffmpeg.


Extract a frame every N seconds

How do we extract a frame from a video every N seconds?

ffmpeg -i input.mp4 -vf "fps=1/5" output_%3d.jpg


ffmpeg -i input.mp4 -r 0.2 output_%3d.jpg


Extract audio from video file

Run the following command to extract audio from a video file:

ffmpeg -i input.mp4 -vn -acodec copy output.aac

If we use this command, we need to know the audio format (i.e., acc, or other formats). Use ffprobe to get the audio format. The output contains something like the following:

Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 128 kb/s (default)

Other option to use to extract audio from video:

ffmpeg -i input.mp4 -map a output.mp3


ffmpeg -i input.mp4 -map a output.aac