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 email@example.com. 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.
- Why are there two folders - Program Files and Program Files (x86) in 64-bit Windows OS?
- Encrypting and Decrypting the Files Using GnuPG in Linux
- Encrypt/Decrypt Files in Linux using Ccrypt
- Encrypting Files Using vim editor in Linux
- How to Recover Deleted Files Using Foremost in Linux?
- Downloading files from web using Python
- Working with csv files in Python
- Jar files in Java
- Working with PDF files in Python
- How to generate spring XMP configuration files programmatically ?
- Getting System and Process Information Using C Programming and Shell in Linux
- GET and POST requests using Python
- Cookie Tracking and Stealing using Cross-Site Scripting
- Reading and Writing data to excel file using Apache POI
- Guess Game using rand() and srand() in C
- Using fork() to produce 1 parent and its 3 child processes
- Chat application between two processes using signals and shared memory
- Python | System hardening and compliance reports using Lynis
- Data Visualization Using Chartjs and Django