Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
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 the 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 essential avconv commands that you can use to accomplish a variety of multimedia 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 the command
avconv -f x11grab -s 1280x720 -i :0.0+0,0 -vcodec libx264 output.mp4
In this command, we use x11grab format to capture the X11 display server's output. The -s option sets the video size to 1280x720 pixels. The -i option specifies the input source, which is the screen at position 0,0. Finally, we use the libx264 video codec and save the 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 the command to convert a video
avconv -i input.avi -codec:v libx264 -codec:a copy output.mp4
In this command, we use the -i option to specify the input file (input.avi). We then use the libx264 video codec and copy the audio stream with the -codec:a copy option. Finally, we save the 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 the audio using avconv. Here's how to do it
avconv -i input.mp4 -vn -codec:a copy output.mp3
In this command, we use the -vn option to disable video processing. The -codec:a copy option copies the audio stream without re-encoding it. Finally, we save the 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 the start time and duration. Here's the command
avconv -i input.mp4 -ss 00:01:30 -t 00:00:30 -codec copy output.mp4
In this command, we use the -ss option to specify the start time (00:01:30) and the -t option to specify the duration (00:00:30). We also use the -codec copy option to copy the 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 the concat protocol to specify the input files (input1.mp4, input2.mp4, and input3.mp4). We then use the -codec copy option to copy the video and audio streams without re-encoding them. Finally, we save the 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 the file size of a video or make it compatible with a specific device. Here's the command
avconv -i input.mp4 -vf scale=640:360 output.mp4
In this command, we use the -vf option to specify a video filter. The scale filter resizes the video to 640x360 pixels. Finally, we save the 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 the command
avconv -i input.mp4 -r 1 -f image2 %d.png
In this command, we use the -r option to specify the frame rate (1 frame per second). The -f option specifies the output format (image2). Finally, we use %d.png to specify the 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 the command
avconv -i input.mp4 -vf scale=320:-1 -t 10 -r 10 output.gif
In this command, we use the scale filter to resize the video to a width of 320 pixels while maintaining the aspect ratio. The -t option specifies the duration of the GIF (10 seconds). The -r option specifies the frame rate (10 frames per second). Finally, we save the 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 the subtitles filter to add subtitles from a file called subs.srt. The subtitles file must be in SRT format. Finally, we save the output as output.mp4.
Remove Audio From a Video
Sometimes, you may want to remove audio from a video. Here's the command to do it
avconv -i input.mp4 -an -codec copy output.mp4
In this command, we use the -an option to disable audio processing. The -codec copy option copies the video stream without re-encoding it. Finally, we save the output as output.mp4.
Advanced Format Conversion
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 fine-tuned encoding parameters. Here's the 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 the -c:v option to specify the video codec (libx264). The -preset option specifies encoding speed and quality (fast). The -crf option sets the video quality (22). The -c:a option specifies the audio codec (aac), and the -b:a option sets the audio bitrate (128k). Finally, we save the output as output.mkv.
Audio Processing Commands
Join Multiple Audio Files
If you have multiple audio files that you want to join together, avconv can help. Here's the command
avconv -i "concat:input1.mp3|input2.mp3|input3.mp3" -acodec copy output.mp3
Convert Audio Format
Avconv can also convert an audio file from one format to another
avconv -i input.wav -vn -codec:a libmp3lame -qscale:a 2 output.mp3
Adjust Audio Volume
If you have an audio file that is too quiet or too loud, you can adjust the volume
avconv -i input.mp3 -filter:a "volume=2" output.mp3
Extract Audio Section
Extract a specific section of an audio file using time parameters
avconv -i input.mp3 -ss 00:01:30 -t 00:00:30 -codec copy output.mp3
Conclusion
Avconv is a powerful command-line tool that simplifies multimedia processing on Linux systems. These commands cover essential tasks from screen recording and format conversion to audio extraction and video manipulation. With practice, avconv becomes an indispensable tool for efficient multimedia workflow automation in terminal environments.
