Search notes:

ffmpeg

ffmpeg is a Hyper fast Audio and Video encoder.
ffmpeg [options] [[infile options] -i infile]... {[outfile options] outfile}...

Convert between different media types

The following command converts file.mp4 to file.mp3.
The -i flag specifies the input file.
ffmpeg -i file.mp4 file.mp3

Cutting/extracting parts from an existing video

The following command extracted the part from 00:48 through 02:39. Is this the canonical way to do that? I don't know.
ffmpeg -i inputfile.mp4 -ss 00:00:48 -to 00:02:39 -async 1 -strict -2 outputfile.mp4

Merging mp3 files

The concat: instruction combined with -acodec copy allows to concatenate multiple mp3 into one.
ffmpeg -i "concat:one.mp3|two.mp3|three.mp3|four.mp3" -acodec copy merged.mp3

Print duration of an mp3

ffmpeg -i Multiverse/Mutliverse.mp3  2>&1 | grep Duration
Compare with mp3info.

Compiling ffmpeg under Cygwin 64

Based on How to compile ffmpeg under Cygwin, I was able to compile ffmpeg (plus libmp3lame) for Cygwin 64 like so:
First, I had to compile libmp3lame
The configure.guess script (apparently dating back to 2003) had to be replaced by http://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.guess;hb=HEAD
As per https://github.com/HPCE/hpce-2015-cw2/issues/3, the lines 138 and 139 in frontend/lametime.c had to be commented:
       //#elif defined __CYGWIN__
       //    setmode(fileno(fp), _O_BINARY);
Then, with the usual ./configure, make, make install trilogy, libmp3lame could be built and installed.
After that, ffmpeg could be build:
apt-cyg install binutils, gcc-core, git, make, ming, mingw64-x86_64-runtime, yasm, texi2html, diffutils, dos2unix
git clone git://source.ffmpeg.org/ffmpeg.git ffmpeg
dos2unix configure
LDFLAGS=-L/usr/local/lib ./configure --enable-shared --disable-static --enable-libmp3lame
make
make install

Update 2023-08-27

A tweet by @ursgehrig suggests to add --disable-indev=gdigrab when configuring ffmpeg:
…
LDFLAGS=-L/usr/local/lib ./configure --enable-shared --disable-static --disable-indev=gdigrab --enable-libmp3lame
…

Showing available input devices

ffmpeg -list_devices true -f dshow -i dummy

Record (capture) screen

ffmpeg -y -f dshow -i audio="Mikrofon (High Definition Audio" -f gdigrab -video_size 1440x900 -i desktop -vcodec h264 foo.mkv
Find name of audio with -list_devices (see above).
dshow stands for DirectShow caputure, gdigrap for GDI PI Windows frame grabber (See ffmpeg -formats).
Recoding microphone and pc's audio (mixing both audio sources with -filter_complex amerge)
ffmpeg -framerate 10 -f dshow -i video="screen-capture-recorder":audio="virtual-audio-capturer" -f dshow -i audio="Mikrofon (High Definition Audio" -filter_complex amerge -ac 2 -ar 44100 -acodec aac -ab 192k -pix_fmt yuv420p -r 30 -vcodec h264 -crf 27 -preset ultrafast -f mp4 undo.mp4

Checking version

The version of ffmpeg can by checked with -version (one hyphen only!):
ffmpeg -version

Part of ImageMagick

Apparently, ffmpeg is also part of an ImageMagick distribution.

Command line options

Getting help: -h -- print basic options -h long -- print more options -h full -- print all options (including all format and codec specific options, very long) -h type=name -- print all options for the named decoder/encoder/demuxer/muxer/filter/bsf/protocol See man ffmpeg for detailed description of the options.

Global options

Global options affect whole programs rather than just one file
-loglevel loglevel set logging level
-v loglevel set logging level
-report generate a report
-max_alloc bytes set maximum size of a single allocated block
-y overwrite output files
-n never overwrite output files
-ignore_unknown Ignore unknown stream types
-filter_threads number of non-complex filter threads
-filter_complex_threads number of threads for -filter_complex
-stats print progress report during encoding
-max_error_rate maximum error rate ratio of decoding errors (0.0: no errors, 1.0: 100% errors) above which ffmpeg returns an error instead of success.
-vol volume change audio volume (256=normal)

Per-file main options:

-f fmt force format
-c codec codec name
-codec codec codec name
-pre preset preset name
-map_metadata outfile[,metadata]:infile[,metadata] set metadata information of outfile from infile
-t duration record or transcode "duration" seconds of audio/video
-to time_stop record or transcode stop time
-fs limit_size set the limit file size in bytes
-ss time_off set the start time offset
-sseof time_off set the start time offset relative to EOF
-seek_timestamp enable/disable seeking by timestamp with -ss
-timestamp time set the recording timestamp ('now' to set the current time)
-metadata string=string add metadata
-program title=string:st=number... add program with specified streams
-target type specify target file type ("vcd", "svcd", "dvd", "dv" or "dv50" with optional prefixes "pal-", "ntsc-" or "film-")
-apad audio pad
-frames number set the number of frames to output
-filter filter_graph set stream filtergraph
-filter_script filename read stream filtergraph description from a file
-reinit_filter reinit filtergraph on input parameter changes
-discard discard
-disposition disposition

Video options:

-vframes number set the number of video frames to output
-r rate set frame rate (Hz value, fraction or abbreviation)
-fpsmax rate set max frame rate (Hz value, fraction or abbreviation)
-s size set frame size (WxH or abbreviation)
-aspect aspect set aspect ratio (4:3, 16:9 or 1.3333, 1.7777)
-vn disable video
-vcodec codec force video codec ('copy' to copy stream)
-timecode hh:mm:ss[:;.]ff set initial TimeCode value.
-pass n select the pass number (1 to 3)
-vf filter_graph set video filters
-ab bitrate audio bitrate (please use -b:a)
-b bitrate video bitrate (please use -b:v)
-dn disable data

Audio options:

-aframes num set the number of audio frames to output
-aq quality set audio quality (codec-specific)
-ar rate set audio sampling rate (in Hz)
-ac channels set number of audio channels
-an disable audio
-acodec codec force audio codec ('copy' to copy stream)
-vol volume change audio volume (256=normal)
-af filter_graph set audio filters

Subtitle options:

-s size set frame size (WxH or abbreviation)
-sn disable subtitle
-scodec codec force subtitle codec ('copy' to copy stream)
-stag fourcc/tag force subtitle tag/fourcc
-fix_sub_duration fix subtitles duration
-canvas_size size set canvas size (WxH or abbreviation)
-spre preset set the subtitle options to the indicated preset

Print help / information / capabilities:

-L show license
-h topic show help
-? topic show help
-help topic show help
--help topic show help
-version show version
-buildconf show build configuration
-formats show available formats
-muxers show available muxers
-demuxers show available demuxers
-devices show available devices
-codecs show available codecs
-decoders show available decoders
-encoders show available encoders
-bsfs show available bit stream filters
-protocols show available protocols
-filters show available filters
-pix_fmts show available pixel formats
-layouts show standard channel layouts
-sample_fmts show available audio sample formats
-dispositions show available stream dispositions
-colors show available color names
-sources device list sources of the input device
-sinks device list sinks of the output device
-hwaccels show available HW acceleration methods

TODO

Was or is there not also a -movflags option?

See also

mp3 tools
Project homepage: https://ffmpeg.org/
tools

Index