Skip to content

FFmpeg

Information

Program info

  • See FFmpeg version and compile flags:

      ffmpeg -version
  • Show supported decoders:

      ffmpeg -decoders
  • Show supported encoders:

      ffmpeg -encoders
  • Show supported demuxers and muxers:

      ffmpeg -formats
  • Show supported filters:

      ffmpeg -filters
  • Show supported codecs:

      ffmpeg -codecs
  • Show supported protocols:

      ffmpeg -protocols
  • Show available sources:

      ffmpeg -sources

File info

  • Get information about file:

      ffmpeg -i input.mp4 -hide_banner

Converting

  • Convert from MP4 container to MKV:

      ffmpeg -i input.mp4 output.mkv
  • Copy everything but re-encode audio:

      ffmpeg -i input.mp4 -map 0 -c copy -c:a libmp3lame output.mp4
  • Copy everything but re-encode video:

      ffmpeg -i input.mkv -map 0 -c copy -c:v mpeg2video output.mkv

Extracting

  • Create sample of 2 minutes:

      ffmpeg -ss 00:10:00 -i input.mp4 -t 00:02:00 output.mp4
  • Extract audio track only from video file:

      ffmpeg -i input.mp4 -vn audio.mp3
  • Extract video track only from video file:

      ffmpeg -i input.mp4 -an video.mp4
  • Extract video, audio and subtitle to separate files:

      ffmpeg -i input.mkv -map 0:0 video.mkv -map 0:1 audio.mkv -map 0:2 subtitle.srt
  • Extract and convert WebVTT subtitle to SubRip format:

      ffmpeg -txt_format webvtt -i input.mkv subtitle.srt
  • Extract and convert multiple WebVTT subtitles to SubRip format:

      ffmpeg -txt_format webvtt -i input.mkv -map 0:2 subtitle.spa.srt -map 0:3 subtitle.eng.srt

Modifying

  • Add subtitles to a video (with appropriate metadata):

      ffmpeg -i input.mp4 -i subtitle.spa.srt -i subtitle.eng.srt -map 0 -map 1 -map 2 -metadata:s:s:0 language=spa -metadata:s:s:1 language=eng -c copy output.mp4
  • Change resolution of video:

      ffmpeg -i input.mp4 -filter:v scale=1280:720 output.mp4
  • Crop video:

      ffmpeg -i input.mp4 -filter:v crop=640:480:100:100 output.mp4

Splitting and joining

  • Split video file into multiple parts of 20 seconds each:

      ffmpeg -i input.mp4 -map 0 -c copy -segment_time 00:20:00 -f segment -reset_timestamps 1 output%03d.mp4
  • Join multiple video files into one:

      printf "file '%s'\n" ./input*.mp4 > mylist.txt && ffmpeg -f concat -safe 0 -i mylist.txt -c copy output.mp4
  • Combine two videos in split screen (side by side):

      ffmpeg -i left.mp4 -i right.mp4 -filter_complex hstack output.mp4

References