Introduction

ffmpeg is a powerful tool to encode and decode audios and videos. Some famous codec are the following:

  • libx264: most popular video codec that could be decoded in every devices nowadays
  • libx265: new efficient video codec that reduces bitrate to half of libx264 without reducing quality
  • libmp3lame, libvorbi, libfdk-aac: various audio codecs used by Amazon, Spotify, Apple, etc.

It is powerful in the sense that it could incorporate various encoder/decoder if you enable the plugin during the configuration before compilation. If you do not compile libx264, then you could not encode/decode in libx264.

ffmpeg is a backend responsible for generating animations in Matplotlib in Python. libx264 is the default video codec.

FFmpeg on HPC

The hpc admin compiled a ffmpeg at Purdue. However, it does not come with any codec, which defects the purpose of compiling ffmpeg. Here is the configuration option:

ffmpeg -version
ffmpeg version 4.2.1 Copyright (c) 2000-2019 the FFmpeg developers
built with gcc 4.8.5 (GCC) 20150623 (Red Hat 4.8.5-39)
configuration: --prefix=XXX --enable-pic --enable-shared --disable-libaom

You might see the following error if you specify this ffmpeg in matplotlib

  File "/XXX/lib/python3.7/selectors.py", line 40, in _fileobj_to_fd
    "{!r}".format(fileobj)) from None
ValueError: Invalid file object: <_io.BufferedReader name=6>

Here is a default configuration for the ffmpeg on MacOS provided by brew

ffmpeg version 4.3.1 Copyright (c) 2000-2020 the FFmpeg developers
  built with Apple clang version 12.0.0 (clang-1200.0.32.28)
  configuration: --prefix=/usr/local/Cellar/ffmpeg/4.3.1_9 --enable-shared --enable-pthreads --enable-version3 --enable-avresample --cc=clang --host-cflags= --host-ldflags= --enable-ffplay --enable-gnutls --enable-gpl --enable-libaom --enable-libbluray --enable-libdav1d --enable-libmp3lame --enable-libopus --enable-librav1e --enable-librubberband --enable-libsnappy --enable-libsrt --enable-libtesseract --enable-libtheora --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libxvid --enable-lzma --enable-libfontconfig --enable-libfreetype --enable-frei0r --enable-libass --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-librtmp --enable-libspeex --enable-libsoxr --enable-videotoolbox --enable-libzmq --enable-libzimg --disable-libjack --disable-indev=jack

THere are much more compilation flags included.

Compile ffmpeg on HPC

The linux kernel on the HPC is 3.10

uname -a
Linux XXX 3.10.0-1062.9.1.el7.x86_64 #1 SMP DATE UTC 2019 x86_64 x86_64 x86_64 GNU/Linux

We are also compiling without installing to root directories.

I follow the ffmpeg-build-script. It is not officially supported though.

Problems

  • Somehow, LV2 is not working, since I do not need it, I disabled LV2.
  • yasm or nasm is compiled but since it is not being put into the bin path, it could not find it (). I solved the problem by adding yasm to bin PATH and libyasm.so to LD_LIBRARY_PATH.

Results

After compilation, we obtained three binaries ffmpeg, ffprobe, and ffplay. Move them to your bin path. If you are using matplotlib in python, after

import matplotlib.pyplot as plt

You should specify the path to ffmpeg by appending the following

plt.rcParams['animation.ffmpeg_path'] ='/home/user/bin/ffmpeg'

Finally, we could produce animations in python using matplotlib on the HPC.