How to Record Your Desktop Video and Audio Using “Avconv” Tool in Ubuntu

Libav is a set of cross-platform libraries and tools that are used to deal with multimedia files, streams and protocols, it was originally forked from the ffmpeg project. Libav includes many sub-tools like:

  1. Avplay: a video & audio player.
  2. Avconv: a multimedia converter plus a video & audio recorder from different sources.
  3. Avprobe: a tool that connects to the multimedia file stream and returns many useful information and statistics about it.
  4. Libavfilter: a filtering API for different Libav tools.

In this article, we’ll explain how to record the Linux desktop’s video & audio using the ‘Avconv’ program on Debian/Ubuntu/Linux Mint distributions.

Step 1: Installing Avconv Tool

1. avconv is a part from the “libav-tools” package, which is available to install from the official repositories for all Debian-based distributions like Ubuntu and Mint, using following commands.

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

Install Avconv in Ubuntu

Install Avconv Tool

Note: Installing packages from default repositories, might give you a little older version of ‘avconv‘ tool. Thus, we recommend you to get the latest version from the official git repository, as shown below.

$ sudo apt-get install yasm
$ git clone git://git.libav.org/libav.git
$ cd libav
$ ./configure
$ make
$ sudo make install

Note: You will have to run “./configure –help” in order to list all the available options for the configuration file and install codecs and libraries that you want, you will also need to do a lot of work in order to install the dependencies.

Also note, if you’re used the compile-from-source way, you’ll always have to use “sudo avconv” instead of “avconv” to run the tool.

Step 2: Start Video Recording of Desktop

2. You’re ready now, all what you have to do is to record your desktop video by issuing following command.

$ avconv -f x11grab -r 25 -s 1920x1080 -i :0.0 -vcodec libx264 -threads 4 $HOME/output.avi

Now let’s explain the command in short:

  1. avconv -f x11grab is the default command to capture video from the X server.
  2. -r 25 is the frame rate you want, you may change it if you like.
  3. -s 1920×1080 is your system’s screen resolution, change it to your current system resolution, it’s very important to do this.
  4. -i :0.0 is where we want to set our recording start point, leave it like this.
  5. -vcodec libx264 is the video codec that we’re using to record the desktop.
  6. -threads 4 is the number of threads, you may change it as well if you like.
  7. $HOME/output is the destination path where you want to save the file.
  8. .avi is the video format, you may change it to “flv”, “mp4”, “wmv”, “mov”, “mkv”.

3. After you enter the command, the recording will start automatically as a process running from the terminal, in order to stop it, hit “Ctrl + C” keys inside the terminal window.

Record Desktop Screen in Ubuntu

Record Desktop Screen

4. Now, you may run the file using VLC or any other multimedia player, or you may run it using “avplay” tool which is a multimedia player from the same Libav package.

$ avplay $HOME/output.avi

Note: Don’t forget to replace the destination file path. The recording’s quality is pretty good.

Play Recorded Video

Play Recorded Video

Here’s a video that I’ve recorded using the “avconv” tool.

Step 3: Start Video & Audio Recording of Desktop

5. If you want to record the audio as well, first run this command to list all the available input sources for the audio.

$ arecord -l

It will give you some output like this.

Check Audio Input in Ubuntu

Check Audio Input

In my case, I’ve one input source for audio only, and its number is “1”, that’s why I am going to use the following command to capture both video & microphone audio.

$ avconv -f alsa -i hw:1 -f x11grab -r 25 -s 1920x1080 -i :0.0 -vcodec libx264 -threads 4 output-file2.avi

You see that part which is colored in yellow? It’s the only modification that I did for the command. Now let’s explain the command in short:

  1. -f alsa is an option to capture the sound from the alsa device.
  2. -i hw:1 is an option to take the audio input source from the “hw:1” device which is the first – and the only – input sound device in my computer.

Note: Don’t forget to replace the “1” number with the number of the input device that you want when you list the available audio input sources using the arecord -l command.

To stop the recording, you may hit the “Ctrl + C” keys again.

Step 4: Start Audio Recording of Desktop

6. If you want to record the audio only, you may use the following command.

$ avconv -f alsa -i hw:1 out.wav

7. You may replace .mp3 with any supported audio format by Libav, you can now play the out.wav using any mutlimedia player like VLC.

Record Desktop Audio in Ubuntu

Record Desktop Audio

Conclusion

avconv” tool can be used to do many other things, not just to record the desktop’s video and audio. For further usage and details about the “avconv” tool, you may visit the official guide at.

https://libav.org/avconv.html

Read Also10 Avconv Commands to Record and Convert Multimedia Files

Have you used the “avconv” tool before to record your desktop? What do you think about it? Is there any other tools that you use to record your desktop? Share them with us in the comments.

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:color=red@0.5" 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:color=red@0.5: 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!

Source

Leave a Reply

Your email address will not be published. Required fields are marked *

WP2Social Auto Publish Powered By : XYZScripts.com