11 ‘Avconv’ Commands to Record, Convert and Extract Videos & Audios from Linux Terminal

In the previous article, we talked about How to Record Desktop Video & Audio Using ‘Avconv’ Tool. We mentioned that there are many other ways of usage for the “avconv” tool to deal with multimedia streams and files.

  1. Record Your Desktop Video and Audio Using ‘Avconv’ Command
Avconv Command Examples
Avconv Command Examples

In this article we’re going to discover the most important 10 commands to use with the “avconv” program.

Just to make sure, you need to have the “avconv” tool installed in order to use, to install it under Debian/Ubuntu/Mint, run the following commands:

$ sudo apt-get update
$ sudo apt-get install libav-tools

1. Get Video and Audio File Information

If you want to get some information about any multimedia file, run the following command using option ‘-i‘ (information) with avcon command and input your audio or video file.

$ avconv -i Michael-Jackson-You-Rock-My-World-HD.mp4 

avconv version 11-6:11-1, Copyright (c) 2000-2014 the Libav developers
  built on Sep 26 2014 14:34:54 with gcc 4.9.1 (Ubuntu 4.9.1-15ubuntu1)
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'Michael-Jackson-You-Rock-My-World-HD.mp4':
  Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: isommp42
    creation_time   : 2013-12-04 15:45:45
  Duration: 00:09:43.05, start: 0.000000, bitrate: 1898 kb/s
    Stream #0.0(und): Video: h264 (High), yuv420p, 1280x720, 1703 kb/s, 29.97 fps, 60k tbn, 59.94 tbc (default)
    Stream #0.1(und): Audio: aac, 44100 Hz, stereo, fltp, 192 kb/s (default)
    Metadata:
      creation_time   : 2013-12-04 15:46:06
At least one output file must be specified
Get Multimedia File Info
Get Multimedia File Info

2. Extract Audio from Video File

To extract the audio only from any video file, and to output it to another file, you may run the following command.

$ avconv -i Michael-Jackson-You-Rock-My-World-HD.mp4 -vn -f wav sound.wav

Some points about the above command:

  1. Don’t forget to replace the input file name with your video file name.
  2. -vn is an option that we use to remove the video from the multimedia file.
  3. -f wav is the format we want our output file to use it, you can switch to “mp3” or “webm” if you want.
  4. sound.wav is the name of the output file.
Extract Audio from Video
Extract Audio from Video

3. Extract Video from Audio File

You can also extract the video only from a multimedia file that contains both video & audio using the following command.

$ avconv -i You-Rock-My-World.avi -vcodec libx264 -an -f mp4 video.mp4

Description about the above command:

  1. -an is an option to drop the audio from the file.
  2. mp4 is the format we want to use for our new file, you can change to “mkv”, “ogg”.. etc, remember, you will have to change the “video.mp4” to “video.mkv” as well.
Extract Video from Audio in Linux
Extract Video from Audio

4. Convert .avi to .mkv Format

To convert an .avi file to .mkv format, use the following command.

$ avconv -i You-Rock-My-World.avi -vcodec libx264 You-Rock-My-World.mkv
  1. -i source-file.avi is the file that we want to convert (-i = -input).
  2. -vcodec is an option that we use to choose a video codec to use while processing the conversion, in our case it is “libx264”, this option is important in order to keep the video quality as it is.
  3. newfile.mkv is the output file name.
Convert Avi to Mkv Format in Linux
Convert Avi to Mkv Format

5. Convert .mp4 to avi Format

To convert n .mp4 file to .avi format, run the following command.

$ avconv -i Michael-Jackson-You-Rock-My-World-HD.mp4 -vcodec libx264 newfile.avi
Convert mp4 to Avi Format in Linux
Convert mp4 to Avi Format

6. Convert .mp3 to .wav Format

Nothing new here.. We inputed a file, we outputted another :) Note that here, we don’t have to use the -vcodec libx264 option, because we’re converting an audio file to another audio file, there’s no video here.

$ avconv -i michael-jackson-dangerous.mp3 newfile.wav
Convert mp3 to wav Format in Linux
Convert mp3 to wav Format

7. Convert .yuv to .avi Format

You can change the format depending on your needs in the previous commands if you want, make sure that the format you choose is supported by Libav.

$ avconv -i oldfile.yuv newfile.avi

8. Merge Video and Audio Together

To merge a video file with an audio file together, run the following command.

$ avconv -i the-sound-file.wav -i the-video-file.avi the-output-file.mkv

You can replace “the-output-file.mkv” with “the-output-file.avi” or any other supported format by Libav (Don’t ask me about it, try them all by yourself!).

9. Convert Video into Images

To convert a video file into several different images, you may run the following command.

$ avconv -i Michael-Jackson-You-Rock-My-World-HD.mp4 -r 1 -s 1366x768 -f image2 image-%03d.png
  1. -r 1: is the number of frames you want per image, the more it is, the more images are created.
  2. 1366×768: is the width and height you want for the images, you may replace it with any other size you want.
  3. image-%03d.png: is the image name format, if you tried the command, it’ll create many images like “image-001.png” , “image-002.png”.. etc, you can replace “png” with “jpg” or “jpeg” if you like.
Convert Video into Images
Convert Video into Images
Capture Images from Video
Capture Images from Video

10. More Options to use with Libav

In Libav, there are an amazing things called “filters”, using filters, you can do many great things to your multimedia files. For example, take the following command.

$ avconv -i input-video.avi -vcodec libx264 -vf "drawbox=x=50:y=50:width=400:height=300:[email protected]" output-video.avi
  1. -vf: is an option to apply a video filter (If you want to use an audio filter, replace it with -af).
  2. drawbox=x=50:y=50:width=400:height=300:[email protected]: Here we applied a filter called “drawbox” which draws a red box with 400 width and 300 height at x=50 and y = 50.

And here’s the result of the above command.

Use Filters with Libav
Use Filters

And take the following command for example,

$ avconv -i input-file.avi -vcodec libx264 -vf "transpose=cclock" output-file.avi
  1. transpose=cclock is a video filter that rotates the video by 90 degree clockwise.

Here’s an image for what you’ll get.

Rotate Videos from Terminal
Rotate Videos

11. Record tty as a Video

This command must be used by the root user, it won’t work without sudo, because it requires access to the framebuffer device (fbdev). fbdev is the Linux framebuffer input device, this device is the responsible device for showing the graphics in the console.

$ sudo avconv -f fbdev -r 30 -i /dev/fb0 out.avi
  1. * -r 30: is the number of frames per second.
  2. * -i /dev/fb0: is the running file device node, by using this option, we’ll be able to capture the video from the tty.

Amazing isn’t? There are many other good filters to use with your multimedia files beside many other ways of usage for avconv, you can check them all from the official documentation at

Avconv Command Usage

Have you tried the advance usage for Libav before? What do you think about it? Do you have any other important commands for avconv? Share them with us in the comments!

Hey TecMint readers,

Exciting news! Every month, our top blog commenters will have the chance to win fantastic rewards, like free Linux eBooks such as RHCE, RHCSA, LFCS, Learn Linux, and Awk, each worth $20!

Learn more about the contest and stand a chance to win by sharing your thoughts below!

Hanny Helal
A Linux & Foss user since 2010, working on many projects in the field of Free Software.

Each tutorial at TecMint is created by a team of experienced Linux system administrators so that it meets our high-quality standards.

Join the TecMint Weekly Newsletter (More Than 156,129 Linux Enthusiasts Have Subscribed)
Was this article helpful? Please add a comment or buy me a coffee to show your appreciation.

9 Comments

Leave a Reply
  1. With a video converter like wonderfox hd video converter factory, converting videos and audio files between kinds of formats is a easy task.

    Reply
  2. Using this command:

    $ avconv -i michael-jackson-dangerous.mp3 newfile.wav

    Is there a way to replace the “michael-jackson-dangerous.mp3” part with a name provided by a user? In other words, the user double clicks an icon, it asks for the file name, then that name is put into the command where the “michael-jackson-dangerous.mp3” part is now.

    Reply
  3. Can it convert video to the image? Seriously? I remembered that there are few such tools can do this like Movavi. I am using HD video converter factory pro now, it can do a good job on video conversion but has no idea of converting video to the image. If this one does do that, it deserves a try!

    Reply
    • @Jackson,

      Yes, the Avconv tool converts video into several images, i have tried and it worked perfectly. You should give a try and see..

      Reply
  4. Thank you for this sharing, really helpful. I’d also recommend Acethinker Video Converter which I have used for many years. It’s a free web-based application to convert videos, you don’t have to install anything. Share it here as an alternative method.

    Reply
  5. Have you tried Avdshare?
    It will show you a step by step guide on how to find and download the right ogv to mp4 videos as well as add ogv to MP4. In fact, this guide also applies to add subtitles to AVI, MKV, WTV, WMV, VOB, MPG, MOV, DV, FLV, WebM, OGV, and etc.

    Reply
  6. Hello.

    Does avconv support gpu? I mean if I compile avconv with –enable-vdpau and setup Nvidia video card

    E.g. simple command

    avconv -i video.wmv -c:v libx264 -c:a libmp3lame -b:v 1800K video.mp4

    Can it be faster than CPU processing?

    Reply

Got Something to Say? Join the Discussion...

Thank you for taking the time to share your thoughts with us. We appreciate your decision to leave a comment and value your contribution to the discussion. It's important to note that we moderate all comments in accordance with our comment policy to ensure a respectful and constructive conversation.

Rest assured that your email address will remain private and will not be published or shared with anyone. We prioritize the privacy and security of our users.