Home page Models Systems Tools IT staff References
Installing ffmpeg Using ffmpeg
ffmpeg is a set of programs for manipulating video files, including the main one called ffmpeg, along with a set of media libraries those programs use. The media libraries are used by the lymph node model to save png files and mpeg videos from the model graphics images in the openGL frame buffer. This is the ffmpeg main web site.
Installing from source rather than installing a pre-built package is generally necessary to have have the ffmpeg library header files installed. The header files are needed to use ffmpeg libraries from our model code. To install from source do the following, as specified at http://ffmpeg.org/download.html. This requires make version 3.81 or later. Older versions of make will result in a fatal make error ("unterminated call to function 'foreach': missing ')'" in the make step. In a terminal window:
This is an assembler needed by the ffmpeg build.
We want the ffmpeg source files in a temporary directory. They will be deleted once ffmpeg is installed.
git --version
to see if it is installed.
git clone git://git.videolan.org/ffmpeg.git
This will create a subdirectory called ffmpeg of the current directory. The git repository used here is not the one from the main ffmpeg page. The code from the 2 repositories is not identical. The effect of the differences, if any, are not known.
The file ~/ffmpeg/INSTALL contains build and installation instructions. Based on those instructions do the following: Use the defaults for the ./configure, especially since it isn't clear what to specify for the installation prefix/locations. It seems to specify an install prefix/location of /usr/local, which is consistent with Boost.
This uses a version of ffmpeg known to work with our lymph model. The lymph model won't build with some later versions of ffmpeg (udnefined references when linking) because our code calls deprecated ffmpeg functions that are no longer available in the newer versions, such as avcodec_init in the libavcodec.a library. The lymph model won't build with versions n0.9 and above (undefined references). The lymph model won't build with version n0.8.0 due to compiler errors. It will build with versions n0.8.3, n0.8,5. and n0.8.10 (not all versions were tested), except that the "--video" lymph model option to save a video file causes a seg fault in an ffmpeg function on one Mac laptop.
This creates the make files for building ffmpeg, based on the local system environment.
To build the libraries and programs. It builds programs such as ffmpeg in addition to the libraries such as libavcodec.a, libavutil.a, etc. It usually takes several minutes.
Copies the libraries to /usr/local/lib and the headers to subdirectories of /usr/include and /usr/local/include.
There are pre-built ffmpeg packages for some Linux distros. These will install the standalone ffmpeg programs and shared libraries, but don't necessarily install the header files needed for using the ffmpeg libraries from our model code.
For Ubuntu use the following. This does not install the library header files needed for using the libraries from our model code.
sudo apt-get update
sudo apt-get -y install ffmpeg
For Fedora use the following. It isn't known if this installs the library header files or not.
sudo yum install ffmpeg
Add the following lines to the beginning of the file /usr/include/libavutil/common.h (if installed using
a pre-built package) or /usr/local/include/libavutil/common.h (if not installed using a pre-built package).
Add them just after the #define AVUTIL_COMMON_H
line. Note that this must also be redone every
time this package is updated or re-installed, either directly (ex. via an apt-get install command) or by
using System | Update Manager). This will require root privileges (use sudo bash to get a privileged shell
session, then ctrl-D to exit it when you are done).
#ifdef __cplusplus
#define __STDC_CONSTANT_MACROS
#ifdef _STDINT_H
#undef _STDINT_H
#endif
# include <stdint.h>
#endif
This is needed to set up the ffmpeg header files correctly for using the ffmpeg libraries with C++ programs (like our models that use SDL). Otherwise the following error will occur when building a model that uses SDL:
/usr/local/include/libavutil/common.h: In function ‘int32_t av_clipl_int32_c(int64_t)’: /usr/local/include/libavutil/common.h:168: error: ‘UINT64_C’ was not declared in this scope
There are some internet forum postings that suggest this problem can be solved by running the following command before the ./configure:
export CXXFLAGS='-D__STDC_CONSTANT_MACROS'
However, as noted in many of the forum posts, this doesn always work, and does not work on our setup of Ubuntu 10.04.
There is no pre-built ffmpeg package for Macs, so use the precedure above for installing on a Linux distro which doesn't have a pre-built ffmpeg package that can be installed. This requires Mac OS/X 10.5 or greater. Earlier versions of OS/X will have a version of make that is too old for the ffmpeg build.
There are pre-built Windows ffmpeg packages available. If for some reason a pre-built package isn't available or doesn't work you can try using the precedure above for installing on a Linux distro which doesn't have a pre-built ffmpeg package that can be installed. Howoever, this will probably require first installing Unix like tools, such as Mingw.
To use ffmpeg, install it and then reference its header files and libraries in the build process of a model that uses it. For a make file build add a -I item to the compile include flags, for example "-I /usr/local/include", and add a -L item to the link flags for the library search locations, for example "-L /usr/local/lib", and add -l items to the link flags for each ffmpeg library to be used, for example "-lavcodec -lavformat -lavutil -lswscale -lm -lz -lpng". The -lm is needed for a math library used by ffmpeg, the -lz is for a compression library. The -lpng is needed when using ffmpeg to save png images to disk in png format.
The standalone ffmpeg program can be used to perform various operations on video files, such as changing from one video format to another. Here are some items found during web searches on using ffmpeg for this purpose. None of these have been tested, so it isn't known which really work and which do not, except as noted.
To convert from an avi file to an mpeg file.
ffmpeg -i file.avi -y -f vcd -vcodec mpeg1video -map 0.0:0.0 -b 1150 -s 352x240
-r 29.97 -g 12 -qmin 3 -qmax 13 -hq -acodec mp2 -ab 224 -ar 44100 -ac 2 -map
0.1:0.1 movie.mpg
Here is a web site with a number of ffmpeg commands
to perform various tasks. The one labeled "Convert .avi video to .mpg", ffmpeg -i video_origine.mpg video_finale.avi
,
does not work.
Combining a set of png files into an mpeg movie, from Joe Waliga: ffmpeg -f image2 -i %d.png -qscale 16 -s 516x512 ../movie.mpeg
.
We currently use various scripts to create avi or mpeg movies: makemovies.pl,
makemovies-lung3d.pl, snapshot_lhs.py