Convert MP4 To MP3 Linux Bash Script

View previous topic View next topic Go down

Convert MP4 To MP3 Linux Bash Script

Post by jamied_uk on 10th April 2017, 14:40

Convert MP$ To MP3 Linux Bash Script








mp4tomp3

Code:
Automatically convert *.mp4 to *.mp3



Usage

run mp4tomp3 and pass the source and destination folder paths as command arguments

If script is in another directory:

Code:
./mp4tomp3.sh /PATH/TO/SOURCE /PATH/TO/DESTINATION



If script is in the same directory

Code:
./mp4tomp3.sh /PATH/TO/SOURCE /PATH/TO/DESTINATION


Dependencies

Code:
sudo apt install -y ffmpeg




ffmpeg


Code:
git clone https://github.com/Prince-of-Persia/mp4tomp3.git





~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

To Execute:

Code:
sudo chmod +x *.sh





Test:
Code:

./mp4tomp3.sh /home/jay/Documents/Convert/test /home/jay/Documents/Convert/output




~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Code:
Code:

#needs ffmpeg installed
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#*/}"' - '{}' \;



Box Backup


Box Backup:
app.box.com/s/8is8va0ndygja9zod0saupnim0g08exw

Original Link


https://github.com/Prince-of-Persia/mp4tomp3
avatar
jamied_uk
Admin

Posts : 2280
Join date : 2010-05-09
Age : 34
Location : UK

http://address-shortner.co.uk

Back to top Go down

Re: Convert MP4 To MP3 Linux Bash Script

Post by jamied_uk on 18th July 2017, 15:28

Example 2





Code:

Code:
#!/bin/bash
#
# jnet.forumn.biz/t1461-convert-mp4-to-mp3-linux-bash-script#2292
# Usage Example
# ./Convert.sh
#
#
search_dir="files_in"
# Starting
echo "Files In:"
ls files_in/
read -p "Are you sure (Files will be Converted From MP4 To MP3)? " -n 1 -r
if [[ $REPLY =~ ^[Yy]$ ]]
then
#
for file in "$search_dir"/*
do
#  echo "$file"
ffmpeg -i "$file" -b:a 192K -vn "$file".mp3
# Now Report
cd $search_dir
# Move all mp3 to out Folder!
mv *.mp3* ../out/
# Done
cd ..
clear
echo "All Done. Files In Out Folder!"
done
fi
#
ls out/
avatar
jamied_uk
Admin

Posts : 2280
Join date : 2010-05-09
Age : 34
Location : UK

http://address-shortner.co.uk

Back to top Go down

Re: Convert MP4 To MP3 Linux Bash Script

Post by jamied_uk on 18th July 2017, 15:57

Notes:

You will need the 2 folders!

Code:
sudo chmod +x *.sh



Code:
./Convert.sh
avatar
jamied_uk
Admin

Posts : 2280
Join date : 2010-05-09
Age : 34
Location : UK

http://address-shortner.co.uk

Back to top Go down

Re: Convert MP4 To MP3 Linux Bash Script

Post by Sponsored content


Sponsored content


Back to top Go down

View previous topic View next topic Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum