How to Convert Video

By Xah Lee. Date: .

You need to have ffmpeg installed. It's usually installed on linux.

If you don't have ffmpeg, try avconv. For some years around 2015, avconv is rename of ffmpeg.

Convert mov to MP4

# convert .mov to mp4 ubuntu 16.04
ffmpeg -f mov -i x.mp4

Note, .mov is Apple's movie format.

Convert webm to MP4

# convert webm to mp4. ubuntu 16.04
ffmpeg -f webm -i x.webm x.mp4

Note, .webm is Google's movie format.

Find Out What's Inside a Video Container

“.mp4”, “.mkv” etc are Video/audio container formats. They package together video file, audio files, and other files, of various formats into 1 file.

To find out what's inside, use ffprobe, e.g.

ffprobe file.mkv

Example output:

~/web/xahmusic_org/music/i $ ffprobe xx.mkv
ffprobe version 3.4 Copyright (c) 2007-2017 the FFmpeg developers
  built with Apple LLVM version 9.0.0 (clang-900.0.37)
  configuration: --prefix=/usr/local/Cellar/ffmpeg/3.4 --enable-shared --enable-pthreads --enable-version3 --enable-hardcoded-tables --enable-avresample --cc=clang --host-cflags= --host-ldflags= --enable-gpl --enable-libmp3lame --enable-libx264 --enable-libxvid --enable-opencl --enable-videotoolbox --disable-lzma
  libavutil      55. 78.100 / 55. 78.100
  libavcodec     57.107.100 / 57.107.100
  libavformat    57. 83.100 / 57. 83.100
  libavdevice    57. 10.100 / 57. 10.100
  libavfilter     6.107.100 /  6.107.100
  libavresample   3.  7.  0 /  3.  7.  0
  libswscale      4.  8.100 /  4.  8.100
  libswresample   2.  9.100 /  2.  9.100
  libpostproc    54.  7.100 / 54.  7.100
Input #0, matroska,webm, from 'xx.mkv':
    COMPATIBLE_BRANDS: iso6avc1mp41
    MAJOR_BRAND     : dash
    ENCODER         : Lavf57.83.100
  Duration: 00:05:04.90, start: 0.000000, bitrate: 1329 kb/s
    Stream #0:0: Video: h264 (Main), yuv420p(tv, bt709, progressive), 1280x720 [SAR 1:1 DAR 16:9], 29.97 fps, 29.97 tbr, 1k tbn, 59.94 tbc (default)
      HANDLER_NAME    : VideoHandler
      DURATION        : 00:05:04.871000000
    Stream #0:1(eng): Audio: vorbis, 44100 Hz, stereo, fltp (default)
      DURATION        : 00:05:04.903000000

Put a Opus Audio into a .Webm Container

ffmpeg -i x.opus -c:a copy x.webm

Add Opus Audio into Existing Webm

ffmpeg -i y.webm -i x.opus -c:v copy -c:a copy x.webm

Extract Audio from Video

extract audio file inside file x.mp4 and name it x.m4a

ffmpeg -i x.mp4 -vn -acodec copy x.m4a

ffmpeg -f mp4 -i x.mp4 -vn -c:a copy x.m4a


ffmpeg -f mp4 -i x.mp4 -map 0:1 -c:a copy x.m4a

-map 0:1 means stream number 1 from file number 0, which would usually be the audio track (edit as necessary). specifying a map at all disables the default map which would be to copy every stream, so you get only the audio, not both. -c:a copy means just copy it, no re-encoding. You may also want to specify a -f for the output to choose a container fomat; I am not sure what it will use by default, probably the same as the input.

Browser Support


2018-11-26 thanks to harvhat and matthew skala

If you have a question, put $5 at patreon and message me.

Image/Video Tutorial

  1. ImageMagick
  2. Convert WEBP to JPG
  3. Convert gif to Video
  4. Convert Video mov webm mp4
  5. View meta info in Image Files
  6. What's Gamma
  7. What's HDRI Image