This article aims to explain how to perform the following operations on audio files using a linux terminal:
- Download a youtube video
- Convert Audio/Video files between various formats
- Combine two mp3 files
- Play audio and video files on the terminal
sudo apt-get update sudo apt-get install python3-pip sudo pip3 install youtube-dl sudo add-apt-repository ppa:mc3man/trusty-media sudo apt install libav-tools sudo apt-get install ffmpeg sudo apt-get install libid3-3.8.3-dev sudo apt-get install mp3wrap
- Download a youtube video:
Youtube videos can directly be downloaded from the terminal by using the youtube-dl library. Its usage is simple.
youtube-dl [options] [url]
There are several parameters that may be passed under options such as:
- -o [output file name]
- -i (ignore errors)
- –abort-on-error (stop download if any video is unavailable
youtube-dl https://www.youtube.com/watch?v=ka0tlCl7hwI -o geeksforgeeks
Below is an example of its usage. The file will be stored in the present working directory.
It is possible that you receive a warning saying that the avconv version is not upto date. This can be corrected by either upgrading (sudo apt-get upgrade) or by forcing youtube-dl to use ffmpeg instead as shown below
youtube-dl --prefer-ffmpeg [url]
The downloaded files can be played normally by any audio/video player.
- Convert A/V files between various formats:
avconv will be made use of here. For example, consider a file ‘g4g.mkv’. Suppose we want to convert this to an mp3 file. The following command must be used:
avconv -i "g4g.mkv" -c:a libmp3lame "g4g.mp3"
Notice how all that had to be done was change the extension. All Video files can be converted to audio files, and Video files can be interconverted between video formats, for example, avi to mp4. However, quality might degrade.
- Combine two mp3 files:
The following set of commands should be used to combine mp3 files.
mp3wrap tmp_MP3WRAP.mp3 [file 1] [file 2] ffmpeg -i tmp_MP3WRAP.mp3 -acodec copy [output name] && rm tmp_MP3WRAP.mp3
- Play audio and videos:
This operations makes use of ffplay, and is quite simple to use
ffplay [file name]
Many more interesting and useful applications of ffmpeg can be found here
This article is contributed by Deepak Srivatsav. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
- Introduction to React Native
- Speech Recognition in Python using Google Speech API
- Practical applications of ‘ls’ command in Linux
- Understanding Lvalues, PRvalues and Xvalues in C/C++ with Examples
- Knowing the complexity in competitive programming
- Basics of NS2 and Otcl/tcl script
- Internet of Things (IoT)
- Introduction to Apache Maven | A build automation tool for Java projects
- Ionic Framework : The Power Behind Modern Web Apps
- Understanding Digital Rights Management