ffmpeg

Table of Contents

1. Basics

  • input files and their streams are numerically differentiated with a 0-based index.
    • Eg. 1:0 means the first(0) stream of the second(1) input file.
    • Eg. 0:1 means the second(1) stream of the first(0) input file.
  • CLI options

    ffmpeg [global_options] {[input_file_options] -i input_url} ... {[output_file_options] output_url} ...
    
    • i/o options come BEFORE the i/o specification.
  • Useful global options
    • -hide_banner
    • -y : Override output file if exists

1.1. Filters

  • Added using -vf or -af (video/audio)

2. Usage

2.1. Common

2.1.1. Convert video to audio (transcode)

ffmpeg -i video.mp4 audio.wav

2.1.2. Extract out different audio streams

ffmpeg -y -i vid.mp4 -map 0:1 stereo_audio.wav -map 0:2 ac3_audio.wav

2.1.3. Extract out to different formats

ffmpeg -y -i vid.mp4 stereo_audio_only.wav  stereo_audio_only.mp3

2.1.4. Extract out to different qualities

ffmpeg -y  -i vid.mp4 \
    -map 0:1 -b:a 320k stereo_audio_hq.mp3 \
    -map 0:2 -b:a 64k  ac3_audio_lq.mp3

2.1.5. Process file from network

ffmpeg -t 5 -i http://remote_video/vid.mp4 first_5_seconds.mp4

Neat thing about this is that this does not download the whole video just the first 5 seconds.

2.1.6. TODO Capture from webcam

ffmpeg -f v4l2 -framerate 25 -video_size 640x480 -t 10 -i /dev/video0 10seconds_of_webcam.webm

2.1.7. Show info about encoder and supported pixel format etc

ffmpeg -h encoder=mjpeg -hide_banner

2.1.8. Get JSON info about a file

ffprobe -v error -hide_banner -print_format json -show_streams [path_to_file]
# There's also
# -show_format
# -show_packets
# -show_frames

2.2. Specific

2.2.1. Convert to wav at 16Hz

ffmpeg -i <input_file> -ar 16000 -f wav -ac 2 -ar 16000 <output_file>

3. Other commands

Created: 2024-07-16 Tue 16:44

Validate