User Tools

Site Tools





sudo apt-get install libx264-dev yasm //Install the VLC x264 library

Download the sources files of FFMpeg on the official website :

mkdir ffmpeg
cd mkdir/
tar -jvxf ffmpeg-XXX.tar.bz2
cd ffmpeg-XXX/

Configure the makefile:

./configure --disable-static --enable-shared --enable-libx264 --enable-gpl 

Start the compilation. If you get an error about yasm, you can try to add “–disable-yasm”. The compilation process will generate .so shared libraries files. You can specify where you want to put the resulting files by using adding “–sshlibdir=SO_DESTINATION_PATH”


Compilation with Windows Visual Studio compiler (MSVC): Compile FFMPEG under MSVC

Developer's corner

Generate CTags for the FFmpeg project

Go into the source folder of FFmpeg

ctags -R .

FFMpeg tool usage

List all available encoders/decoders/codecs

ffmpeg -codecs

 D..... = Decoding supported
 .E.... = Encoding supported
 ..V... = Video codec
 ..A... = Audio codec
 ..S... = Subtitle codec
 ...I.. = Intra frame-only codec
 ....L. = Lossy compression
 .....S = Lossless compression

List devices compatible with FFmpeg

  1. Check that you have a video device in your /dev folder, like /dev/videoX.
  2. Install video4linux control utility :
sudo apt-get install v4l-utils
v4l2-ctl --list-devices

List device capabilities (supported resolution, encoding...)

ffmpeg -f v4l2 -list_formats all -i /dev/video0

Adjusting camera parameters

v4l2-ctl -L
v4l2-ctl -c <option>=<value>

List audio inputs (ALSA)

Make sure that alsa is installed:

sudo apt-get install libasound2-dev
arecord -L

Encoding examples

  • Encoding example with v4l2:
ffmpeg -f v4l2 -framerate 25 -video_size 640x480 -i /dev/video0 output.mkv
* Raw recording in mkv file
ffmpeg -i /dev/video0 -vcodec copy output.mkv
  • Encode mkv raw file in h264 codec in a .mkv file at 120 fps:
ffmpeg -i inputRawFile.mkv -r 120 -vcodec h264 encodedOutputFile.mkv
  • Record 30 seconds of audio using the default input (must be generic), all of them can be seen with arecord -L, the output is stored in out.wav
ffmpeg -f alsa -i default -t 30 out.wav
* Record audio & video in out.avi file with native encoding
ffmpeg -f v4l2 -i /dev/video0 -f alsa -i default out.avi
  • Record audio in AAC & video in h264 in out.avi file
ffmpeg -f v4l2 -i /dev/video0 -vcodec h264 -f alsa -i default -c:a libfdk_aac out.avi

Streaming example

  • Stream video through the network:

Generate the .sdp file:

ffmpeg -f v4l2 -i /dev/video0 -r 50 -video_size 640x480 -f rtp rtp:// > myfile.sdp

Then CTRL+C to stop ffmpeg. The file myfile.sdp contains all the informations about the server that will be created. Re-execute the previous command without the redirection :

ffmpeg -f v4l2 -i /dev/video0 -r 50 -video_size 640x480 -f rtp rtp://

It's possible to read the stream with ffplay

ffplay myfile.sdp
  • Streaming using ffmpeg and vlc (UNICAST)
ffmpeg -f v4l2 -i /dev/video0 -vcodec h264 -f mpegts udp://<IP_ADDRESS>:1234 with 

where <IP_ADDRESS> is the PC address to which you want to stream.

To read the sream from VLC:

vlc udp://@:1234

Transformation example

Rotate a video:

./ffmpeg -i -vf "transpose=2"

Splitting example

Cut a video without re-encoding ([start] under the form 00:01:23.000 or the number of seconds [duration] duration in seconds):

ffmpeg -ss [start] -i in.mp4 -t [duration] -c copy out.mp4
ffmpeg.txt · Last modified: 2017/06/15 17:19 by louisbob_ext