Use Avconv to Convert Video Format

avconv is a utility that belongs to Libav project. Similar to its precedent ffmpeg, it supports lots of mainstream encoders and decoders. Here I just put some simple commands as a personal memo and a brief guide.

Install libav-tools via apt-get on your Debian/Ubuntu machines. Note on my Fedora laptop, there is no libav but only the original ffmpeg packages. The command-line options are fairly similar (sometimes even identical). In that case, you only need to substitute ffmpeg for avconv.

Change Containers

Some media players don't recognize MKV files but only MP4 files. It's not just an extension name! For example, the SONY PS3 can't play MKV files. You can't just rename a MKV file as MP4 because they're two different containers.

If this is the only thing we need, the converting would be very fast! (because we won't decode and encode streams). Type avconv -i INPUT_FILE -c copy OUTPUT_FILE in your terminal and just wait for a few minutes. i.e. avconv -i demo.mkv -c copy demo.mp4

Change Formats

It'll take longer time than previous one because of the decoding and encoding thing. Much longer if you change the video format rather than audio format.

Change Video Format

Type avconv -i INPUT_FILE -c:v h264 -c:a copy OUTPUT_FILE to convert the video stream in INPUT_FILE to H.264 format and copy the audio stream and store them in the OUTPUT_FILE.

Change Audio Format

Type avconv -i INPUT_FILE -c:v copy -c:a aac OUTPUT_FILE to convert the audio stream in INPUT_FILE to AAC format and copy the video stream and store them in the OUTPUT_FILE.

Change Both Video and Audio Formats

As you can see, you need to give new formats for video and audio by -c:v and -c:a respectively. The copy is a special keyword which means instead of decode then encode, just copy.

Other Notes

  1. To see the codec information about a media file, just type avconv -i INPUT_FILE.
  2. To see what codecs avconv supports, type avconv -codecs.
  3. The command-option for subtitle is -c:s or -scodec in old syntax.
  4. The old syntax for video codec and audio codec are -vcodec and -acodec respectively.

Comments