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.
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
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:
- Don’t forget to replace the input file name with your video file name.
- -vn is an option that we use to remove the video from the multimedia file.
- -f wav is the format we want our output file to use it, you can switch to “mp3” or “webm” if you want.
- sound.wav is the name of the output file.
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:
- -an is an option to drop the audio from the file.
- 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.
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
- -i source-file.avi is the file that we want to convert (-i = -input).
- -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.
- newfile.mkv is the output file name.
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
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
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
- -r 1: is the number of frames you want per image, the more it is, the more images are created.
- 1366×768: is the width and height you want for the images, you may replace it with any other size you want.
- 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.
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@example.com" output-video.avi
- -vf: is an option to apply a video filter (If you want to use an audio filter, replace it with -af).
- drawbox=x=50:y=50:width=400:height=300:firstname.lastname@example.org: 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.
And take the following command for example,
$ avconv -i input-file.avi -vcodec libx264 -vf "transpose=cclock" output-file.avi
- transpose=cclock is a video filter that rotates the video by 90 degree clockwise.
Here’s an image for what you’ll get.
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
- * -r 30: is the number of frames per second.
- * -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
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!