I have looked at Converting mp4 to mp3 which uses a tool called ffmpeg. The process is great when you have a single file to convert, but I'm trying automate the mp4 to mp3 conversion for any given directory.
As an example, the directory below with all its sub directories is given, i.e. MusicVideos`:
.
├── Andra
│ └── Andra::Why.mp4
├── Ariana Grande
│ └── Dangerous Woman
│ ├── ArianaGrande::IntoYou.mp4
│ └── ArianaGrande::SideToSide.mp4
├── Justin Bieber
│ └── JustinBieber::LetMeLoveYou.mp4
├── Major Lazer
│ └── De Maxx 37
│ └── MajorLazer::ColdWater.mp4
├── Martin Garrix & Bebe Rexha
│ └── MartinGarrix&BebeRevha::InTheNameOfLove.mp4
├── Shawn Mendes
│ └── ShawnMendes::TreatYouBetter.mp4
├── Sia
│ └── The Greatest
│ └── Sia::TheGreatest.mp4
├── The Chainsmokers
│ ├── TheChainsmokers::AllWeKnow.mp4
│ └── TheChainsmokers::Closer.mp4
├── The Weekend
│ └── Starboy
│ └── TheWeekend::DaftPunk.mp4
└── TWENTY ØNE PILØTS
└── Suicide Squad
└── TwentyOnePilots::Heathens.mp4
After the script is ran the output directory should look like, i.e., MusicAudio:
.
├── Andra
│ └── Andra::Why.mp3
├── Ariana Grande
│ └── Dangerous Woman
│ ├── ArianaGrande::IntoYou.mp3
│ └── ArianaGrande::SideToSide.mp3
├── Justin Bieber
│ └── JustinBieber::LetMeLoveYou.mp3
├── Major Lazer
│ └── De Maxx 37
│ └── MajorLazer::ColdWater.mp3
├── Martin Garrix & Bebe Rexha
│ └── MartinGarrix&BebeRevha::InTheNameOfLove.mp3
├── Shawn Mendes
│ └── ShawnMendes::TreatYouBetter.mp3
├── Sia
│ └── The Greatest
│ └── Sia::TheGreatest.mp3
├── The Chainsmokers
│ ├── TheChainsmokers::AllWeKnow.mp3
│ └── TheChainsmokers::Closer.mp3
├── The Weekend
│ └── Starboy
│ └── TheWeekend::DaftPunk.mp3
└── TWENTY ØNE PILØTS
└── Suicide Squad
└── TwentyOnePilots::Heathens.mp3
I was looking at how to do this conversion using bash scripts and i came across Script: Recursively convert wma files to MP3, then remove WMA files.
This seems a bit harder than what I was anticipating for, any help and guidance will be greatly appreciated.
Update
With some help I've written a script: Please confirm that this works!
cp -a /$1/. /$2/ #copy the whole dir from src to dest
#cd $2 #change dir to dest
cd $2
#convert .mp4 to .mp3
#find . -name ".mp4" -exec bash -c 'var=${1%.mp4}; var=${var#/};ffmpeg -i "${1#*/}" -vn -acodec libmp3lame -ac 2 -qscale:a 4 -ar 48000 "$dest/$var".mp3' - '{}' ;
find . -name "*.mp4" -exec bash -c 'ffmpeg -i "$1" -vn -acodec libmp3lame -ac 2 -qscale:a 4 -ar 48000 "${1%.mp4}".mp3' - '{}' ;
echo "Cleaning up"
find . -name ".mp4" -exec bash -c 'var=${1%.mp4}; var=${var#/}; rm "${1#*/}"' - '{}' ;
You can find the source code on my GitHub. Any further contribution will be appreciated greatly.