How to Record, Convert and Extract Videos & Audios using Avconv on Ubuntu

avconv is a very fast video and audio converter that can also grab from a live audio/video source. It can also convert between arbitrary sample rates and resize video on the fly with a high quality polyphase filter.

Avconv

In this article we’re going to see how we use “avconv” command.

Install “Avconv”

avconv 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

Get Video and Audio Information

If you want to check the information about any multimedia file, then run the following command to know information:

# avconv -i My-Video-File.mp4

Extract Audio from Video File

To extract the audio file from any video file, you may run the following command:

# avconv -i My-Video-File.mp4 -vn -f mp3 My-Audio-File.mp3

Note:

  • vn is an option that we use to disable the video from the video file.
  • -f wav is the format we want our audio file, you can use “mp3” also if require.
  • Convert .avi to .mkv Format

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

    # avconv -i source_file.avi -vcodec libx264 output_File.mkv
    

    Note:
    -vcodec is an option that we use to choose a video codec, this option is important in order to keep the video quality as it is.

    Convert .mp4 to avi Format

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

    # avconv -i My-Video-File.mp4 -vcodec libx264 output_File.avi
    

    Convert .mp3 to .wav Format

    To convert an .mp3 file to .wav format, use the following command:

    # avconv -i My-Audio-File.mp3 output_File.wav
    

    Convert .yuv to .avi Format

    You can change the format accourding to your requirement. To convert an .yuv file to .avi format, use the following command:

    # avconv -i source_file.yuv output_File.avi
    

    Merge Video and Audio Together

    To merge video file with an audio file, use following command:

    # avconv -i My-Audio-File.wav -i My-Video-File.avi output_File.mkv
    

    Convert Video into Images

    To convert a video file into multiple images, you run the following command:

    # avconv -i My-Video-File.mp4 -r 1 -s 1366x768 -f image2 image-%01d.png
    

    Note:

  • -r 1: is the number of frames you want per image
  • 1366×768: is the width and height you want for the images
  • image-%03d.png: is the image name format

    More Options to use with Libav

    In Libav, there are an astounding things called “filters”, using filters, you can do numerous extraordinary things to your multiple files.

    # avconv -i input_file.avi -vcodec libx264 -vf "drawbox=x=50:y=50:width=400:height=300:color=red@0.5" output_File.avi
    

    Note:

  • -vf: is an option to apply a video filter
  • 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.
  • 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 output_File.avi
    

    Note:

  • -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.
  • Enjoy It!

    Leave a Reply

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

    This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

    The reCAPTCHA verification period has expired. Please reload the page.