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


Are you a Linux user who frequently works with video and audio files? If so, you'll want to learn about versatile avconv tool. Avconv is a command-line utility that can record, convert, and extract videos and audios from Linux terminals. In this article, we'll explore 10 different avconv commands that you can use to accomplish a variety of tasks.

Record a Video

The first avconv command we'll look at is how to record a video. This is useful when you need to capture a video of your screen or webcam. Here's command −

avconv -f x11grab -s 1280x720 -i :0.0+0,0 -vcodec libx264 output.mp4

In this command, we use x11grab format to capture X11 display server's output. -s option sets video size to 1280x720 pixels. -i option specifies input source, which is screen at position 0,0. Finally, we use libx264 video codec and save output to a file called output.mp4.

Convert a Video

Avconv can also be used to convert a video from one format to another. For example, you might need to convert a video to a format that is compatible with a specific device. Here's command to convert a video −

avconv -i input.avi -codec:v libx264 -codec:a copy output.mp4

In this command, we use -i option to specify input file (input.avi). We then use libx264 video codec and copy audio stream with -codec:a copy option. Finally, we save output file as output.mp4.

Extract Audio From a Video

If you have a video with a great soundtrack that you want to listen to on its own, you can extract audio using avconv. Here's how to do it −

avconv -i input.mp4 -vn -codec:a copy output.mp3

In this command, we use -vn option to disable video processing. -codec:a copy option copies audio stream without re-encoding it. Finally, we save output file as output.mp3.

Extract a Specific Section of a Video

Sometimes, you may only need a specific section of a video. Avconv can extract a section of a video by specifying start time and duration. Here's command −

avconv -i input.mp4 -ss 00:01:30 -t 00:00:30 -codec copy output.mp4

In this command, we use -ss option to specify start time (00:01:30) and -t option to specify duration (00:00:30). We also use -codec copy option to copy video and audio streams without re-encoding them.

Merge Multiple Videos

If you have multiple videos that you want to combine into one, you can use avconv to merge them. Here's how −

avconv -i "concat:input1.mp4|input2.mp4|input3.mp4" -codec copy output.mp4

In this command, we use concat protocol to specify input files (input1.mp4, input2.mp4, and input3.mp4). We then use -codec copy option to copy video and audio streams without re-encoding them. Finally, we save output file as output.mp4.

Resize a Video

Avconv can also be used to resize a video. This is useful when you need to reduce file size of a video or make it compatible with a specific device. Here's command −

avconv -i input.mp4 -vf scale=640:360 output.mp4

In this command, we use -vf option to specify a video filter. scale filter resizes video to 640x360 pixels. Finally, we save output file as output.mp4.

Extract Frames From a Video

If you need to extract individual frames from a video, avconv can help. Here's command −

avconv -i input.mp4 -r 1 -f image2 %d.png

In this command, we use -r option to specify frame rate (1 frame per second). -f option specifies output format (image2). Finally, we use %d.png to specify output file name format (frame number.png).

Convert a Video to a GIF

GIFs are a popular format for sharing short animations on social media. You can convert a video to a GIF using avconv. Here's command −

avconv -i input.mp4 -vf scale=320:-1 -t 10 -r 10 output.gif

In this command, we use scale filter to resize video to a width of 320 pixels while maintaining aspect ratio. -t option specifies duration of GIF (10 seconds). -r option specifies frame rate (10 frames per second). Finally, we save output as output.gif.

Add Subtitles to a Video

If you have a video that needs subtitles, avconv can help. Here's how to add subtitles −

avconv -i input.mp4 -vf subtitles=subs.srt output.mp4

In this command, we use subtitles filter to add subtitles from a file called subs.srt. subtitles file must be in SRT format. Finally, we save output as output.mp4.

Remove Audio From a Video

Sometimes, you may want to remove audio from a video. Here's command to do it −

avconv -i input.mp4 -an -codec copy output.mp4

In this command, we use -an option to disable audio processing. -codec copy option copies video stream without re-encoding it. Finally, we save output as output.mp4.

Convert a Video to a Specific Format

Sometimes, you may need to convert a video to a specific format that is compatible with a certain device or software. Avconv can help with that. Here's command −

avconv -i input.mp4 -c:v libx264 -preset fast -crf 22 -c:a aac -b:a 128k output.mkv

In this command, we use -c:v option to specify video codec (libx264). -preset option specifies encoding speed and quality (fast). -crf option sets video quality (22). -c:a option specifies audio codec (aac), and -b:a option sets audio bitrate (128k). Finally, we save output as output.mkv.

Join Multiple Audio Files

If you have multiple audio files that you want to join together, avconv can help. Here's command −

avconv -i "concat:input1.mp3|input2.mp3|input3.mp3" -acodec copy output.mp3

In this command, we use concat protocol to specify input files (input1.mp3, input2.mp3, and input3.mp3). We then use -acodec copy option to copy audio stream without re-encoding it. Finally, we save output file as output.mp3.

Convert an Audio File to a Different Format

Avconv can also be used to convert an audio file from one format to another. Here's command −

avconv -i input.wav -vn -codec:a libmp3lame -qscale:a 2 output.mp3

In this command, we use -vn option to disable video processing. -codec:a option specifies audio codec (libmp3lame), and -qscale:a option sets audio quality (2). Finally, we save output as output.mp3.

Adjust Volume of an Audio File

If you have an audio file that is too quiet or too loud, you can use avconv to adjust volume. Here's command −

avconv -i input.mp3 -filter:a "volume=2" output.mp3

In this command, we use volume filter to increase volume by a factor of 2. Finally, we save output as output.mp3.

Extract a Specific Section of an Audio File

Just like with video files, you can extract a specific section of an audio file using avconv. Here's command −

avconv -i input.mp3 -ss 00:01:30 -t 00:00:30 -codec copy output.mp3

In this command, we use -ss option to specify start time (00:01:30) and -t option to specify duration (00:00:30). We also use -codec copy option to copy audio stream without re-encoding it.

Conclusion

Avconv is a powerful tool that can help you record, convert, and extract videos and audios from Linux terminals. With these 10 commands, you can accomplish a variety of tasks, including recording a video, converting a video, extracting audio from a video, merging multiple videos, resizing a video, extracting frames from a video, converting a video to a GIF, adding subtitles to a video, and removing audio from a video. Give these commands a try and see how avconv can simplify your video and audio tasks on Linux.

Updated on: 02-May-2023

123 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements