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
- Google Summer of Code Preparation
- Speech Recognition in Python using Google Speech API
- Practical applications of ‘ls’ command in Linux
- Run commands as root with sudo
- Depth wise Separable Convolutional Neural Networks
- Do programmers need a Computer Science degree to get a job?
- What is the future of those students who are getting selected in mass recruiting companies
- How do I become a good Java programmer?
- DBMS | Join operation Vs nested query