ffmpeg

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 ffmpeg

Linux Install

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:

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.

For Fedora use the following. It isn't known if this installs the library header files or not.

Update libavutil/common.h

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.

Mac Install

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.

Windows Install

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.

Using ffmpeg

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