Skip to content

Instantly share code, notes, and snippets.

@DustinAlandzes
Forked from pjobson/FFMPEG_Notes.md
Created August 7, 2017 20:33
Show Gist options
  • Save DustinAlandzes/66645ab6ef18ee64f6f9677fc2e29e10 to your computer and use it in GitHub Desktop.
Save DustinAlandzes/66645ab6ef18ee64f6f9677fc2e29e10 to your computer and use it in GitHub Desktop.
FFMPEG Notes

Some Recipies for ffmpeg Usage

I screw around with ffmpeg a lot, here are some recipies which I frequently use.

AUDIO

... to MP3

ffmpeg -i <input>.wav -codec:a libmp3lame -b:a 320k output.mp3
ffmpeg -i <input>.wav -codec:a libmp3lame -q:a 0 output.mp3
Average kbit/s Bitrate range kbit/s ffmpeg option
320 320 CBR -b:a 320k
245 220-260 -q:a 0
225 190-250 -q:a 1
190 170-210 -q:a 2
175 150-195 -q:a 3
165 140-185 -q:a 4
130 120-150 -q:a 5
115 100-130 -q:a 6
100 80-120 -q:a 7
85 70-105 -q:a 8
65 45-85 -q:a 9

... to FLAC

ffmpeg -i <input>.<ext> -c:a flac <output>.flac

... to WAV

Raw Audio Types

ffmpeg -i <input>.<ext> -acodec pcm_s32le output.wav

There are various encoders for the WAV format, you can list them by passing the -formats switch to ffmpeg. More on this below.

ffmpeg -formats | grep PCM

Change Speed

Decress speed by half.

ffmpeg -i input.wav -filter:a "atempo=0.5" -vn output.wav

Increase speed by half.

ffmpeg -i input.wav -filter:a "atempo=1.5" -vn output.wav

Double speed.

ffmpeg -i input.wav -filter:a "atempo=2.0" -vn output.wav

VIDEO

... to MKV

It is a bit easier to do stuff with MKV files using MKVToolNix – Matroska tools for Linux/Unix and Windows, but you can accomplish many things with ffmpeg.

ffmpeg -i <input>.<ext> -c:a flac -c:v ffv1 <output>.mkv

Remove Audio from an MKV

ffmpeg -i <input>.mkv -c copy -an <output>-nosound.mkv

Convert to Grayscale

ffmpeg -i <input>.mkv -vf hue=s=0 <output>-grayscale.mkv

Loop an Image into a Video

Convert an image into a 720p video which is 40m 1.04 seconds.

ffmpeg -loop 1 -i image.png -c:v libx264 -t 00:40:01.04 -pix_fmt yuv420p -vf scale=1280x720 out.mp4

Convert a Vertical Movie to Hoizontal with Black Bars

This is good for videos which were shot vertically on a phone 1080w x 1920h.

This is a two-step proces which I use, it could probably be made into one step.

ffmpeg -i vertical.1080x1920.mkv -vf scale=-1:1080 vertical.608x1080.mkv
ffmpeg -i vertical.608x1080.mkv -vf "scale=1920:1080:force_original_aspect_ratio=decrease,pad=1920:1080:(ow-iw)/2:(oh-ih)/2" horizontal.1920x1080.mkv

Extract JPGs from a Video

Extract 20 Frames per Second

ffmpeg -i example.mkv -r 20 img.%10d.jpg

Extract 1 Frame per Second

ffmpeg -i example.mkv -r 1 img.%8d.jpg

Convert a Series of Images to a Video

ffmpeg -framerate 24 -i img%03d.png output.mp4

Rotate Video and Convert to MKV

ffmpeg -i <input>.<ext> -c:v libx264 -preset ultrafast -crf 0 -vf "transpose=1" <output>.mkv

Rotations:

Num Rotation
0 90 Counter Clockwise and Vertical Flip (default)
1 90 Clockwise
2 90 Counter Clockwise
3 90 Clockwise and Vertical Flip

Add Subtitles to MKV

ffmpeg -i <input>.mkv -i <subtitle>.srt -map 0 -map 1 -c copy <output>.mkv

Many subtitles for movies may be downloaded from SubScene.

INFORMATIONAL

Media Info (Probe)

ffprobe gathers information from multimedia streams and prints it in human- and machine-readable fashion.

ffprobe example.mkv

Installed Capabilities

This shows what formats the installed ffmpeg supports for Muxing and Demuxing.

ffmpeg -formats

Output Example (Support, File Extension, File Description)

File formats:
 D. = Demuxing supported
 .E = Muxing supported
 --
 D  3dostr             3DO STR
  E 3g2                3GP2 (3GPP2 file format)
  E 3gp                3GP (3GPP file format)
 D  4xm                4X Technologies
  E a64                a64 - video for Commodore 64
 D  aa                 Audible AA format files
 D  aac                raw ADTS AAC (Advanced Audio Coding)
 DE ac3                raw AC-3
 D  acm                Interplay ACM
 D  act                ACT Voice file format
 D  adf                Artworx Data Format
 D  adp                ADP
 D  ads                Sony PS2 ADS
  E adts               ADTS AAC (Advanced Audio Coding)
 DE adx                CRI ADX
 D  aea                MD STUDIO audio
...etc...
 DE wav                 WAV / WAVE (Waveform Audio)
 D  wc3movie            Wing Commander III movie
  E webm                WebM
  E webm_chunk          WebM Chunk Muxer
 DE webm_dash_manifest  WebM DASH Manifest
  E webp                WebP
 D  webp_pipe           piped webp sequence
 DE webvtt              WebVTT subtitle
 D  wsaud               Westwood Studios audio
 D  wsd                 Wideband Single-bit Data (WSD)
 D  wsvqa               Westwood Studios VQA
 DE wtv                 Windows Television (WTV)
 DE wv                  raw WavPack
 D  wve                 Psion 3 audio
 D  xa                  Maxis XA
 D  xbin                eXtended BINary text (XBIN)
 D  xmv                 Microsoft XMV
 D  xvag                Sony PS3 XVAG
 D  xwma                Microsoft xWMA
 D  yop                 Psygnosis YOP
 DE yuv4mpegpipe        YUV4MPEG pipe
 DE adx                 CRI ADX
 D  aea                 MD STUDIO audio

Installed Devices

FFmpeg Devices Documentation

This shows the available devices the installed ffmpeg supports for Muxing and Demuxing.

ffmpeg -devices

Output example for OS X MacBrew installation.

Devices:
 D. = Demuxing supported
 .E = Muxing supported
 --
 D  avfoundation    AVFoundation input device
  E caca            caca (color ASCII art) output device
 D  lavfi           Libavfilter virtual input device
 D  qtkit           QTKit input device
  E sdl             SDL output device

Output example for Linux Mint installation.

Devices:
 D. = Demuxing supported
 .E = Muxing supported
 --
 DE alsa            ALSA audio output
 D  dv1394          DV1394 A/V grab
 DE fbdev           Linux framebuffer
 D  lavfi           Libavfilter virtual input device
 DE oss             OSS (Open Sound System) playback
  E v4l2            Video4Linux2 output device
 D  video4linux2,v4l2 Video4Linux2 device grab
 D  x11grab         X11 screen capture, using XCB
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment