Thanks to Rene and Flemur, who fixed my mistakes and resulted in this EDIT !!
Rene - all processes on one line
Flemur - Possible unintended loss of some files.
Perhaps, run it in COPIED folders a few times to see if anything breaks?
Over time we collect Music in various formats, either ripping our CDs or DVDs to play the music we have bought on our phones, tablets or computers and players.
.mp3 is one format that while it might not be the 'best' format (it is lossy) is convenient and easily played on almost anything.
Mint, and other Linux systems can rip and convert most things. There are several GUI programs to do this task. Most might find a GUI easier than using a script, but doing stuff in the terminal and using shell scripts is part of the fun of getting your hands dirty in Linux. (sometimes)
There is a handy program called ffmpeg in most repos, and it is usually installed by default in Mint.
It can change formats easily and bash scripts have been around for years to achieve this, but often they only convert from .mp4 to .mp3, leaving all the .wav files (the format you usually get when you simply 'copy' the tracks on a CD rather than 'ripping' them) unconverted in the folder/directory. We also sometimes accumulate other files that can often be converted.
I rewrote the mp42mp3.sh script to 0vid4mp3.sh
the 0 in front simply puts it early in the file list.
A discussion here corrected a few glaring errors in my messy script and it now works better. Thanks Rene and Flemur.
This is nothing special, just a simple script for beginners who may have music in various other formats who want it changed to .mp3 format.
Here's Rene's simplified (corrected) code. If it throws an ERROR message on a particular file type, just remove that extension form the line.
If you save it as 0vid4mp3 it will appear early in a list of files, and it converts more filetypes than the old mp42mp3
Run this script in Terminal in the folder you want to convert folder
Run it with ./0vid4mp3.sh or bash 0vid4mp3
Code: Select all
#!/bin/bash
# This script needs ffmpeg
# sudo apt install ffmpeg
# If ffmpeg is not in your suppository, you may need to dig around a bit for it
# Copy this script to the directory you want to convert
# If you have other file types like .ogg or .MPG in capitals
# that are not in the list, add them to the line with filetypes
# don't forget to save this file if you edit it or changes won't work
# rename the resulting output directory (music-mp3) and move it wherever you want it.
# Have Fun - Rene, Flemur, RossDv8 (Mint Forums)
shopt -s nullglob
mkdir -p music-mp3
for i in *.mp4 *.MP4 *.mkv *.mpg *.webm *.wav *.avi *.flv *.m4a *.wma *.wmv
do
ffmpeg -i "$i" -ab 128k -y "music-mp3/${i%.*}.mp3"
done
mv *.mp3 -t music-mp3