- AudioConverter
- Setup
- Install ffmpeg
- Install CLI
- Usage
- Experimental
- Accepted Formats
- Supported Codec
- ftransc 7.0.3
- Навигация
- Ссылки проекта
- Статистика
- Метаданные
- Сопровождающие
- Классификаторы
- Описание проекта
- What is ftransc
- Installing ftransc
- Examples
- ftransc Quality Presets
- ftransc Metadata Tags
- Screenshots
- ftransc plugin for Rhythmbox media player:
- Convert audio format using Python and FFmpeg
- ffmpeg
- Code
- Did you find this article valuable?
AudioConverter
I have some old music in a lossless format. Now that I am constantly jumping between computers, I wanted it to be converted in a more universal format such as mp3 so that I can play it with the simplest of players. I also wanted to avoid having to stream my music on cloud platforms. Upon a cursory and naive scan on the web, I found that existing scripts are defunct (again cursory) or was not as simple as I would like it to be. I did not want to download a GUI for a one time use or upload a directory of music online to have it be converted on some server and download it again either. Instead, I wrote this quick CLI to do it for me.
Setup
Install ffmpeg
Go follow the pydub tutorial on how to set up ffmpeg on the various platforms.
Install CLI
pip install --upgrade AudioConverter
Usage
audioconvert convert INPUT_DIRECTORY OUTPUT_DIRECTORY TARGET_FORMATThis will recursively search the INPUT_DIRECTORY for files with music extensions. Each file found will then be converted to the TARGET_FORMAT and placed in the OUTPUT_DIRECTORY with the same name but updated extension.
The —verbose/-v flag must be provided before the convert command. This will enable debugging logs and allow you to monitor progress.
For example — to convert the contents of the directory input/ , containing files of type .m4a and .flac , outputting to directory output/ , converting to type .mp3 run:
audioconvert convert input/ output/ --output-format .mp3
Experimental
Audio can be passed to be converted to specific codecs. This is an experimental now feature as it has no error checking that certain codecs are compatible with your desired output audio format. Depending on ffmpeg and/or pydub , there may or may not be error logging.
To use the new experimental feature:
audioconvert convert input/ output/ --output-format .wav --codec pcm_mulaw
Accepted Formats
Due to not being super savvy with audio formats, I hard coded the extensions that are searched for in the INPUT_DIRECTORY and acceptable TARGET_FORMAT . Here is a list of formats I thought were popular:
Supported Codec
ftransc 7.0.3
ftransc is a python library for converting audio files across various formats.
Навигация
Ссылки проекта
Статистика
Метаданные
Метки Audio, Convert, ffmpeg, avconv, mp3
Сопровождающие
Классификаторы
Описание проекта
What is ftransc
ftransc is the python audio conversion library. It can convert local files or files from youtube (even youtube playlists).
Installing ftransc
ftransc can be installed as follows:
Then FFMpeg must also installed as follows:
sudo apt-get install ffmpeg lame flac vorbis-tools
Examples
Example 1 — converting from MP3 to OGG:
ftransc -f ogg filename.mp3
The output file name for the above example will be ‘filename.ogg’
Example 2 — converting from MP3 to AAC, removing original file on success, using high quality preset:
ftransc -r -q extreme -f aac filename.mp3
Example 3 — extract audio content from a video files into the MP3 format, use best quality preset:
ftransc -q insane -f mp3 filename2.avi filename3.mpg filename4.vob .
Example 4 — convert all audio files inside a given folder into WMA format. (This option is not recursive to child-folders)
ftransc -f wma --directory /path/to/folder_name
Example 5 — convert all audio audio files (and extract all audio content from video files) inside a given folder recursively including all sub-/child-folders, ftransc should be used with the ‘find’ command in the pipeline as follows:
find /path/to/folder_name -type f -print0 | xargs -0 ftransc -f aac -q high
ftransc Quality Presets
ftransc uses quality presets called ‘insane’, ‘extreme’, ‘high’, ‘normal’, ‘low’, and ‘tiny’. These presets are specified by the ‘-q’ or ‘—quality’ option of ftransc and are defined in the ‘/etc/ftransc/presets.conf’ configuration file.
The /etc/ftransc/presets.conf presets file can be overriden by use of the —presets option and specify the custom presets file to use or, if you know what you are doing, make changes directly on the it.
ftransc Metadata Tags
The following is the list of supported tags across audio formats that ftransc can encode to. N means the tag is not supported and hence is lost during conversion. Y means the tag is supported and is present on the new file after conversion:
tag | m4a | mp3 | ogg | flac | wma | mpc | wav | wv |
---|---|---|---|---|---|---|---|---|
title | Y | Y | Y | Y | Y | Y | N | Y |
artist | Y | Y | Y | Y | Y | Y | N | Y |
album | Y | Y | Y | Y | Y | Y | N | Y |
genre | Y | Y | Y | Y | Y | Y | N | Y |
date | Y | Y | Y | Y | Y | Y | N | Y |
tracknumber | Y | Y | Y | Y | Y | Y | N | Y |
composer | Y | Y | Y | Y | Y | Y | N | N |
publisher | N | Y | N | N | Y | N | N | N |
lyrics | Y | Y | N | N | Y | N | N | N |
album art | Y | Y | N | Y | N | N | N | N |
album artist | N | N | N | N | N | N | N | N |
comment | N | N | N | N | N | N | N | N |
Screenshots
The image below shows ftransc command in action on Terminal as well as the ftransc manpage ( man ftransc ):
ftransc GUI front-end, ftransc_qt:
ftransc also uses Nautilus Scripts, so you can right click selection of files and convert like:
ftransc plugin for Rhythmbox media player:
- The ftransc plugin for rhythmbox media player allows one to send files from Rhythmbox music player to ftransc for conversion.
- Enabling the plugin:
- Converting songs with ftransc from Rhythmbox
Convert audio format using Python and FFmpeg
The dependencies can be installed by running the following commands on your terminal.
ffmpeg
FFmpeg is the leading multimedia framework, able to decode, encode, transcode, mux, demux, stream, filter and play pretty much anything that humans and machines have created. It supports the most obscure ancient formats up to the cutting edge. No matter if they were designed by some standards committee, the community or a corporation. It is also highly portable: FFmpeg compiles, runs, and passes our testing infrastructure FATE across Linux, Mac OS X, Microsoft Windows, the BSDs, Solaris, etc. under a wide variety of build environments, machine architectures, and configurations.
converting the audio / video using FFmpeg
ffmpeg -i input_audio.wav output_audio.mp3
Even a mp4 video can be converted to any of the audio formats
ffmpeg -i input_video.mp4 -b:a 192K -vn output_audio.mp3
-b:a : audio bitrate
Optional and it is used to mention a particular audio bitrate. The output audio will be encoded with the given audio bitrate.
-vn : disable video
For now we need only the audio so the -vn option is used to remove the video from the output file.
Conversion of video / audio is very simple using FFmpeg, But our requirement is to do this programmatically using python.
Now we are ready to move forward and start coding!.
Code
from pydub import AudioSegment given_audio = AudioSegment.from_file("path/to/input_audio.mp4", format="mp4") # or given_audio = AudioSegment.from_file("path/to/input_audio.mp3", format="mp3") # or given_audio = AudioSegment.from_file("path/to/input_audio.wav", format="wav") # or raw_audio = AudioSegment.from_file("path/to/input_audio.wav", format="raw", frame_rate=44100, channels=2, sample_width=2) # The above line of code is simply building the ffmpeg command from # the parameters and executing it in the background as a process. given_audio.export("path/to/output_audio.mp3", format="mp3") # or given_audio.export("path/to/output_audio.wav", format="wav") # or given_audio.export("output_audio.wav", format="wav") # file will be saved in the current working directory
Converted the Audio format!. You can find the converted audio file in the path which is passed to the export method.
Same things can be done by passing the ffmpeg command to python sub-process. But it may be difficult for the beginners. pydub will handle the ffmpeg command generation and sub-process parts for you.
Do share your valuable feedback and suggestions!
Thank you for reading, I would love to connect with you at LinkedIn.
Did you find this article valuable?
Support Balasundar by becoming a sponsor. Any amount is appreciated!