[HOWTO] convert mp4/mpv/WebM sound files into mp3
Posted: 13 Sep 2022, 22:51
Maybe you also have the need for occasionally convert sound files from mp4/mpv/WebM fortats into mp3.
TL;DR version
use
(adjust the bit rate accordingly to the one in your source file. mp3con.sh always uses 320 kb/s regardless of what the source file has - often resulting in unneeded large target file while gaining nothing from that (what is lost due to smaller bitrate cannot be regained by converting into another file using larger bitrate)
Useto get the info on your multimedia file - in this case, the bitrate.
Know that "-v error" suppresses all output that are not errors (like the banner) - when you want to see all that omit "-v error" e.g. by using simply
____________________________________________________
Long version with the weirdness that is mp3con.sh:
I found a script that does that and it needs only ffmpeg and lame - both are already installed on your Port 4.* or 5.0 system.
Get the script via
Maybe you want to tweak the script or use parts of it for your own one-liner or your own conversion script.
The website describing it is this: https://computingforgeeks.com/how-to-co ... -on-linux/
What I dislike with mp3con.sh: it asks for the folder to convert, and then converts all mp4/mpv/WebM in that folder, but maybe you only want to convert a certain file, or you already have mp3 versions of some mp4/mpv/WebM files in that directory, mp3con.sh would again convert all the mp4/mpv/WebM files from that folder into mp3.
So, realizing that I created a "mp3con.sh.CONVERT/" folder and only copied one file - a webm - into that I wanted converted - I wanted to see how mp3con.sh does its work prior examining its code and possibly using some snippet for a conversion script - to create one that can be run e.g. asand thus only convert the named files - or also executed like or to convert all files mp4/mpv/WebM in these paths (like mp3con.sh does now, but unlike an envisioned mp3convert mp3con.sh doesn't use or understand any parameters it is given)
EDIT
While mp3con.sh definitely did convert something, the target file is not to be found. Look for yourself:That is quite the disappointment, for now I have no clue where the named by ffmpeg target file 'mp3con.sh.CONVERT-mp3/./Vintage 70s Hoover Convertible ASMR _ Retro White Noise for Sleeping, Focus _ 1 HOUR-gWWCInm-SDw.c1.webm.mp3' is… 
Seems lazy butt me cannot simple run mp3con.sh and have the file I wanted converted, well, converted, when the target file is not to be found.
Added in 17 minutes 29 seconds:
Update 2
Looking into its code, I found where it put the file - it put it into ~/Music/mp3con.sh.CONVERT-mp3/ without telling the user about that.Weird undocumented behaviour, but at least the file conversation was finally successful.
Having to read a script's source code to find the resulting converted files is in my book a no-no.
What do you folks think?
Added in 8 minutes :
And another thing I dislike about how mp3con.sh handles things - it converts all files using 320K bitrates - which creates a quite large target file, but in my case the source file only hasand what is lost cannot be regained, so, using 320K on a 122K file is not making the resulting mp3 amazingly better in quality than the source, the only thing it does is creating an unneeded large target file while gaining nothing by using 320K bitrate - unless your source file also had 320K bitrate.
For now, I first use my own "Multimedia File Info" Thunar add-on to give me the bitrate details of the source file and adjust the conversion line manually, e.g. from what mp3con.sh uses
I use this instead
TL;DR version
use
Code: Select all
ffmpeg -v error -i INFILE -b:a 128K -vn OUTFILE.mp3
Use
Code: Select all
ffprobe -hide_banner INFILE
Know that "-v error" suppresses all output that are not errors (like the banner) - when you want to see all that omit "-v error" e.g. by using simply
Code: Select all
ffmpeg -i INFILE -b:a 128K -vn OUTFILE.mp3
Long version with the weirdness that is mp3con.sh:
I found a script that does that and it needs only ffmpeg and lame - both are already installed on your Port 4.* or 5.0 system.
Get the script via
Code: Select all
wget https://raw.githubusercontent.com/jmutai/dotfiles/master/scripts/mp3con.sh
The website describing it is this: https://computingforgeeks.com/how-to-co ... -on-linux/
What I dislike with mp3con.sh: it asks for the folder to convert, and then converts all mp4/mpv/WebM in that folder, but maybe you only want to convert a certain file, or you already have mp3 versions of some mp4/mpv/WebM files in that directory, mp3con.sh would again convert all the mp4/mpv/WebM files from that folder into mp3.
So, realizing that I created a "mp3con.sh.CONVERT/" folder and only copied one file - a webm - into that I wanted converted - I wanted to see how mp3con.sh does its work prior examining its code and possibly using some snippet for a conversion script - to create one that can be run e.g. as
Code: Select all
mp3convert 1.webm 2.mpv
Code: Select all
mp3convert .
Code: Select all
mp3convert /path/
EDIT
While mp3con.sh definitely did convert something, the target file is not to be found. Look for yourself:
Code: Select all
guest@porteus:/mysound/WhiteNoise/mp3con.sh.CONVERT$ ls -l
total 56976
-rw-r--r-- 1 guest users 58278950 Feb 15 2022 Vintage\ 70s\ Hoover\ Convertible\ ASMR\ _\ Retro\ White\ Noise\ for\ Sleeping,\ Focus\ _\ 1\ HOUR-gWWCInm-SDw.c1.webm
guest@porteus:/mysound/WhiteNoise/mp3con.sh.CONVERT$ mp3con.sh
1: Current directory
2: Provide directory
Selection : 1
Okay..
Current dir is /mysound/WhiteNoise/mp3con.sh.CONVERT
ffmpeg version 4.4.1 Copyright (c) 2000-2021 the FFmpeg developers
built with gcc 11.2.0 (GCC)
configuration: --prefix=/usr --libdir=/usr/lib64 --shlibdir=/usr/lib64 --docdir=/usr/doc/-4.4.1/html --mandir=/usr/man --disable-debug --enable-shared --disable-static --enable-gpl --enable-libaom --enable-version3 --enable-avresample --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-gnutls --enable-libbluray --enable-libcdio --enable-libssh --enable-libtheora --enable-libv4l2 --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libmp3lame --enable-opencl --enable-opengl --enable-libopenjpeg --enable-libpulse --enable-libsmbclient --enable-pthreads --enable-postproc --enable-swscale --enable-avfilter --enable-libopus --enable-libspeex --enable-openal --enable-libass --enable-libx264 --enable-libx265 --enable-libgsm --enable-libxvid --enable-libtwolame --enable-libopencore-amrnb --'mp3con.sh.CONVERT-mp3/./Vintage 70s Hoover Convertible ASMR _ Retro White Noise for Sleeping, Focus _ 1 HOUR-gWWCInm-SDw.c1.webm.mp3'enable-libopencore-amrwb --enable-libgsm --enable-nvdec --enable-librtmp
libavutil 56. 70.100 / 56. 70.100
libavcodec 58.134.100 / 58.134.100
libavformat 58. 76.100 / 58. 76.100
libavdevice 58. 13.100 / 58. 13.100
libavfilter 7.110.100 / 7.110.100
libavresample 4. 0. 0 / 4. 0. 0
libswscale 5. 9.100 / 5. 9.100
libswresample 3. 9.100 / 3. 9.100
libpostproc 55. 9.100 / 55. 9.100
Input #0, matroska,webm, from './Vintage 70s Hoover Convertible ASMR _ Retro White Noise for Sleeping, Focus _ 1 HOUR-gWWCInm-SDw.c1.webm':
Metadata:
ENCODER : Lavf58.76.100
Duration: 01:03:39.42, start: -0.006000, bitrate: 122 kb/s
Stream #0:0(eng): Audio: opus, 48000 Hz, stereo, fltp (default)
Metadata:
DURATION : 01:03:39.421000000
Stream mapping:
Stream #0:0 -> #0:0 (opus (native) -> mp3 (libmp3lame))
Press [q] to stop, [?] for help
Output #0, mp3, to 'mp3con.sh.CONVERT-mp3/./Vintage 70s Hoover Convertible ASMR _ Retro White Noise for Sleeping, Focus _ 1 HOUR-gWWCInm-SDw.c1.webm.mp3':
Metadata:
TSSE : Lavf58.76.100
Stream #0:0(eng): Audio: mp3, 48000 Hz, stereo, fltp, 320 kb/s (default)
Metadata:
DURATION : 01:03:39.421000000 'mp3con.sh.CONVERT-mp3/./Vintage 70s Hoover Convertible ASMR _ Retro White Noise for Sleeping, Focus _ 1 HOUR-gWWCInm-SDw.c1.webm.mp3'
encoder : Lavc58.134.100 libmp3lame'mp3con.sh.CONVERT-mp3/./Vintage 70s Hoover Convertible ASMR _ Retro White Noise for Sleeping, Focus _ 1 HOUR-gWWCInm-SDw.c1.webm.mp3'
size= 149198kB time=01:03:39.41 bitrate= 320.0kbits/s speed= 25x
video:0kB audio:149198kB subtitle:0kB other streams:0kB glob'mp3con.sh.CONVERT-mp3/./Vintage 70s Hoover Convertible ASMR _ Retro White Noise for Sleeping, Focus _ 1 HOUR-gWWCInm-SDw.c1.webm.mp3'al headers:0kB muxing overhead: 0.000658%
All files converted successfully
guest@porteus:/mysound/WhiteNoise/mp3con.sh.CONVERT$ ls -oa
total 56984
drwxr-xr-x 2 guest 4096 2022-09-14 00:32 .
drwxr-xr-x 3 guest 4096 2022-09-14 00:29 ..
-rw-r--r-- 1 guest 58278950 2022-02-15 11:34 Vintage\ 70s\ Hoover\ Convertible\ ASMR\ _\ Retro\ White\ Noise\ for\ Sleeping,\ Focus\ _\ 1\ HOUR-gWWCInm-SDw.c1.webm

Seems lazy butt me cannot simple run mp3con.sh and have the file I wanted converted, well, converted, when the target file is not to be found.

Added in 17 minutes 29 seconds:
Update 2
Looking into its code, I found where it put the file - it put it into ~/Music/mp3con.sh.CONVERT-mp3/ without telling the user about that.
Code: Select all
# Move audio directory to ~/Music
if [[ ! -d ~/Music ]]; then
mkdir ~/Music
fi
cd ..
mv "$base_name"-mp3 ~/Music/
Having to read a script's source code to find the resulting converted files is in my book a no-no.
What do you folks think?
Added in 8 minutes :
And another thing I dislike about how mp3con.sh handles things - it converts all files using 320K bitrates - which creates a quite large target file, but in my case the source file only has
Code: Select all
Duration: 01:03:39.42, start: -0.006000, bitrate: 122 kb/s
Stream #0:0(eng): Audio: opus, 48000 Hz, stereo, fltp (default)
For now, I first use my own "Multimedia File Info" Thunar add-on to give me the bitrate details of the source file and adjust the conversion line manually, e.g. from what mp3con.sh uses
Code: Select all
ffmpeg -i INFILE -b:a 320K -vn OUTFILE.mp3
Code: Select all
ffmpeg -i INFILE -b:a 128K -vn OUTFILE.mp3