FFmpeg scripts

Last update : September 13, 2013

I use the following FFmpeg scripts to create or convert videos with FFmpeg to host them on the Synology DiskStation :

1. one image to video (15sec, 25 fps, AVC, mp4 container)

ffmpeg ^
-loop 1 ^
-f image2 ^
-i folder/imagename.png ^
-r pal ^
-vcodec libx264 ^
-t 15 ^

2.  image sequence to video with good quality (15sec, 25 fps, AVC, profile Baseline@L3.1, 1 Ref Frame, Chroma subsampling 4:2:0, mp4 container, start at image xxx, animation, preset very good quality, constant rate factor = 20)

ffmpeg ^
-f image2 ^
-start_number 1113 ^
-i folder/imagename_%%05d.png ^
-r pal ^
-vcodec libx264 ^
-crf 20 ^
-preset veryslow ^
-profile:v baseline ^
-level 3.1 ^
-refs 1 ^
-pix_fmt yuv420p ^
-tune animation ^
-t 15 ^

3. add audio stream to a mute video (15sec, AAC-LC, 48Kbps bitrate, 44.1 Kz sampling, one channel)

ffmpeg ^
-i folder/mymutevideo.mp4 ^
-i folder/mysound.flac ^
-vcodec copy ^
-acodec libvo_aacenc ^
-ar 44100 ^
-ab 48k ^
-ac 1 ^
-t 15 ^

4. change video container

ffmpeg ^
-i folder/myvideo.mp4 ^
-vcodec copy ^
-acodec copy ^

5. change framerate (stretch super8 film, digitized with 25 fps, to original framerate 18 fps)

ffmpeg ^
-i input01.avi ^
-target pal-dv ^
-vf "setpts=25/18*PTS" ^

Video X264 encoding

Last update : September 17, 2013

I wanted to know the best X264 parameters to encode my personal movies with ffmpeg for my family website. I rendered 375 frames (15 seconds) from the open-source Big-Buck-Bunny image files (360-png) with different settings, starting at frame 1.113. This post refers to my former post about AVC (H264) video settings.

The common parameters for the encoding are :

  • -vcodec libx264
  • -f image2
  • -pix_fmt yuv420p (chroma subsampling : 4:2:0)
  • -tune animation
  • resolution (pal) : 640 x 360 pixels
  • frame rate : 25 fps

1st Test

The ffmpeg settings for the first test series are :

  • -preset veryslow
  • -profile:v baseline
  • -level 3
  • -refs 1

The value of the Constant Rate Factor (CRF) was changed from 20 to 32, in steps of 3. Here are the results :

CRF Filesize (KB) Videostream (Kbps) Bits/(Pixel*Frame)
 20  2.430  1.326  0.230
 23  1.472  802  0.139
 26  877  478  0.083
 29  531  289  0.050
 32  338  183  0.032


Visually the quality difference between the movies with an CRF = 20 and CRF = 32 is not perceptible. These are snapshots of the two movies :

CRF = 20  Size = 39,6 KB

CRF = 20  Image size = 39,6 KB

CRF = 32 Size = 32,6 KB

CRF = 32  Image size = 32,6 KB

2nd Test

The ffmpeg settings for the second test series are :

  • -crf : 20
  • -profile:v baseline
  • -level 3
  • -refs 1

The three presets veryslow, medium and ultrafast have been used. Here are the results :

Preset Filesize (KB) Videostream (Kbps) Bits/(Pixel*Frame)
veryslow 2.430 1.326 0.230
medium 2.729 1.489 0.258
ultrafast 5.276 2.880 0.500


Presets are designed to reduce the work needed to generate sane, efficient commandlines to trade off compression efficiency against encoding speed. The default preset is medium. If you specify a preset, the changes it makes will be applied before all other parameters are applied.

The X264 settings of the different presets are :


  • –no-8x8dct
  • –aq-mode 0
  • –b-adapt 0
  • –bframes 0
  • –no-cabac
  • –no-deblock
  • –no-mbtree
  • –me dia
  • –no-mixed-refs
  • –partitions none
  • –rc-lookahead 0
  • –ref 1
  • –scenecut 0
  • –subme 0
  • –trellis 0
  • –no-weightb
  • –weightp 0


  • –b-adapt 2
  • –bframes 8
  • –direct auto
  • –me umh
  • –merange 24
  • –partitions all
  • –ref 16
  • –subme 10
  • –trellis 2
  • –rc-lookahead 60

3rd Test

The ffmpeg settings for the third test series are :

  • -preset veryslow
  • -crf : 20
  • -profile:v baseline
  • -level 3

The numer of reference frames was changed to the values 1, 2, 4, 8 and 16. Here are the results :

Ref frames Filesize (KB) Videostream (Kbps) Bits/(Pixel*Frame)
1 2.430 1.326 0.230
2 2.378 1.297 0.225
4 2.203 1.201 0.209
8 2.079 1.134 0.197
16 2.027 1.106 0.192


4th Test

The ffmpeg settings for the fourth test series are :

  • -crf : 20
  • -profile:v main
  • -level 3

The numer of reference frames was changed to the values 4, 8 and 16 for the two presets veryslow and medium (4 is the minimum number of reference frames of the main profile). Here are the results :

Preset Ref frames Filesize (KB) Videostream (Kbps) Bits/(Pixel*Frame)
 veryslow 4 1.517 826 0.143
 veryslow 8 1.411 768 0.133
 veryslow 16 1.389 756 0.131
 medium 4 1.700 926 0.161
 medium 8 1.636 891 0.155
medium 16 1.607 875 0.152


5th Test

The ffmpeg settings for the fifth test series are :

  • -preset veryslow
  • -crf : 20

The profiles and levels have been changed. Here are the results :

Profile@Level Filesize (KB) Videostream (Kbps) Bits/(Pixel*Frame)
baseline@3.0 2.430 1.326 0.230
main@3.0 1.517 826 0.143
high@3.0 1.405 765 0.133


Profiles are not set by default in X264. If a profile is specified, it overrides all other settings, so that a compatible stream will be guaranteed.

The X264 settings of the different profiles are :


  • –no-8x8dct
  • –bframes 0
  • –no-cabac
  • –cqm flat
  • –weightp 0
  • No interlaced
  • No lossless


  • –no-8x8dct
  • –cqm flat
  • No lossless


  • No lossless

A level inside a profile specifies the maximum picture resolution, frame rate and bit rate that a decoder may use.

The complete detailed informations about settings are available in the x264.exe inbuild documentation, accessible with the command x264 –fullhelp .

The following list provides some links to websites with more informations about ffmpeg and x264 video encoding :

FFmpeg formats and codecs

Last update : September 16, 2013

By typing ffmpeg -formats in the command prompt window, a list of all supported media formats by FFmpeg is returned. The same is true for ffmpeg -codecs to get the list of all supported video- and audio-codecs.

I am particularly interested in the following FFmpeg formats and codecs :

File formats :
D. = Demuxing supported
.E = Muxing supported

  • D aac                                           raw ADTS AAC (Advanced Audio Coding)
  • DE ac3                                         raw AC-3
  • DE amr                                        3GPP AMR
  • DE asf                                          ASF (Advanced / Active Streaming Format)
  • DE avi                                          AVI (Audio Video Interleaved)
  • DE dv                                           DV (Digital Video)
  • E dvd                                            MPEG-2 PS (DVD VOB)
  • DE flv                                           FLV (Flash Video)
  • DE h264                                      raw H.264 video
  • E ismv                                         ISMV/ISMA (Smooth Streaming)
  • DE m4v                                       raw MPEG-4 video
  • DE mjpeg                                    raw MJPEG video
  • E mov                                          QuickTime / MOV
  • D mov,mp4,m4a,3gp,3g2,mj2     QuickTime / MOV
  • E mp4                                          MP4 (MPEG-4 Part 14)
  • DE mpeg                                     MPEG-1 Systems / MPEG program stream
  • E mpeg2video                             raw MPEG-2 video
  • DE mpegts                                  MPEG-TS (MPEG-2 Transport Stream)
  • D mpegvideo                               raw MPEG video
  • DE u8                                          PCM unsigned 8-bit
  • E psp                                           PSP MP4 (MPEG-4 Part 14)
  • E vob                                           MPEG-2 PS (VOB)
  • D webvtt                                      WebVTT subtitle

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

  • D.V..S fraps                                 Fraps
  • DEV.LS h264                               H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10
  • DEVIL. mjpeg                              Motion JPEG
  • DEV.L. mpeg1video                    MPEG-1 video
  • DEV.L. mpeg2video                    MPEG-2 video (decoders: mpeg2video mpegvideo )
  • DEA..S pcm_u8                          PCM unsigned 8-bit
  • D.S… webvtt                               WebVTT subtitle

MPEG-4 Tools

Last update : September 16, 2013

To create and modify MPEG-4 Multimedia files, you need different MPEG-4 tools, e.g. an encoder, a multiplexer and a packager :

MPEG-4 Tools : Video encoder

x264  (Wikipedia) is a free software library (libx264) and application (x264.exe) for encoding video streams into the H.264/MPEG-4 AVC format, and is released under the terms of the GNU GPL. X264 provides best-in-class performance, compression, and features, gives the best quality and has the most advanced psychovisual optimizations. A comparison with other H264 codecs is available at the MSU Graphics & Media Lab (Video Group) of Lomonosov Moscow State University. The leader in this comparison for software encoders is x264, followed by MainConcept, DivX H.264 and Elecard.

X264.exe is a command line tool. A typical command to enter in the Command Prompt Window looks as follows :

x264.exe --crf 18 --ref 3 --bframes 2 --subme 3 --keyint 100 --sar 1:1 --output %1.mkv %1

All available parameters can be listed with the command x264 –fullhelp. The purpose and use of all x264 settings is also explained on the MeWiki website.

The fourcc code of the X264 codec is X264.

MPEG-4 Tools : Multiplexer

To encode videos, x264 is not sufficient. Audio, subtitles and metadata should be added, and all these data need to be multiplexed. Therefore other tools are needed. FFmpeg is one of these tools. FFmpeg is a free software project that produces libraries and programs for handling multimedia data. It includes libavcodec, the leading audio/video codec library and libavformat, an audio/video container mux and demux library. FFmpeg is published under the GNU Lesser General Public License 2.1+ or GNU General Public License 2+, depending on which options are enabled. The ffmpeg component is a command-line tool to convert one video file format to another. X264 is added as an external library to FFmpeg. Zeranoe has great static builds of FFmpeg for Windows with libx264 included. Other useful external libraries are the Fraunhofer AAC library for AAC encoding and the LAME library for MP3 encoding.

A very comprehensive documentation about ffmpeg , the libraries, utilities and tools is available at the FFmpeg website.

MPEG-4 Tools : Packager

A third command-line tool performing some manipulations on ISO media files like mp4 is MP4Box, the multimedia packager from GPAC (Project on Advanced Content). Dynamic Adaptive Streaming over HTTP (DASH) is one example. GPAC officially started as an open-source project in 2003 with the initial goal to develop from scratch, in ANSI C, clean software compliant to the MPEG-4 Systems standard, a small and flexible alternative to the MPEG-4 reference software. The GPAC framework is being developed at École nationale supérieure des télécommunications (ENST) as part of research work on digital media. A general documentation about MP4Box is available at the GPAC website.

MP4Box is a command-line tool, the following GUI’s are available :

  • MeGUI, by several authors (version 2356, released on June 8, 2013)
  • My MP4Box GUI, by Matthew Bodin (version, released on January 4, 2013)
  • Java MP4Box Gui, by Rune André Liland (version 1.7, released on May 18, 2013)
  • Yamb, by kurtnoise version beta 2, released on June 29, 2009)

The following list provides links to additional posts about MPEG-4 tools :

FFmpeg : record, convert and stream audio and video

Last update : August 29, 2013


FFmpeg Command Line Tool

FFmpeg is a complete, cross-platform solution to record, convert and stream audio and video. It includes libavcodec – the leading audio/video codec library.

The latest version is 2.0.1 released August 11, 2013. Version 0.6.x released in 2010 featured a lot of improvements that are relevant for HTML5 video. The H.264 and Theora decoders were significantly faster, the vorbis decoder has seen important updates and the release supported Google’s newly released libvpx library for the VP8 codec and WEBM container.

FFmpeg is free software licensed under the LGPL or GPL depending on the configuration options. Companies that violate the license terms are tracked and listed on the Hall of Shame and eventually sued.

ffdshow wrapper for Windows DirectShow

FFmpeg is developed under GNU/Linux, but it can be compiled under most operating systems. Windows distributions are available at the website ffmpeg.zeranoe.com. On Windows there are however some limitations, for instance up to now it’s not possible to capture audio in realtime.

To make the libavcodec decoders available to DirectShow-based applications (a proprietary Windows technology), you can use ffdshow. This DirectShow filter is a DirectShow-wrapper around the libavcodec (ffmpeg) decoders. Non DirectShow-based applications like Avidemux use libavcodec/ffmpeg through it’s native interface. There exist a fork of the original ffdshow project called ffdshow tryouts.

Paul Glagla developed a utility Filmerit (version 3.0.8 published on May 14, 2007) to show DirectShow filters and diagnose errors. Another similar tool called InstalledCodec (version 1.30) which allows to enable/disable codec drivers and DirectShow filters is available on the NirSoft website.

FFmpeg is a command-line based tool. There are however several graphical user interfaces (GUI) available :

  • SUPER from eRigthSoft
  • Avanti, a dedicated “workbench” for FFmpeg/Avisynth
  • HandBrake, an open-source, GPL-licensed, multiplatform, multithreaded video transcoder; I upgraded to version 0.9.5 in june 2011
  • WinFF, a free tool published under the GNU public license for Windows and Ubuntu

SUPER from eRigthSoft

Avanti GUI


FFmpeg or the libraries are also used by other video frameworks :

  • VLC from Videolan

A full list of all projects using FFmpeg is available on the official website.

A similar project as FFmpeg, using several components of this project, is MEncoder.

The following list provides some useful links about FFmpeg :