You are not logged in.
#! /bin/bash
track=`echo "$@"`
music='/home/lnk/Music/'
video='/home/lnk/Videos/'
ffmpeg -i "$video$track".mp4 -acodec libmp3lame -ab 160k -ar 44100 -ac 2 "$music$track".mp3
Save the above code using your favorite text editor to 'convert.sh' or whatever you want.
Simply change the video variable from '/home/lnk/Music' to whatever folder you want the final conversion to end up.
Change the video variable from '/home/lnk/Videos/' to whatever folder you have your videos located.
Run
chmod +x convert.sh
Make sure you have 'lame' and 'ffmpeg' installed. Both of these can be found with pacman and installed.
pacman -S lame
pacman -S ffmpeg
When you're ready to do the conversions simple traverse in the terminal to the folder you have your script located and once there type
./convert.sh "filename without extension"
And you're all done. ;)
Hope this helps a few beginners create something useful.
Offline
We already have it in the wiki https://wiki.archlinux.org/index.php/FF … ting_audio but thanks anyway :-)
Offline
Also, to lose the subshell for `echo "$@"` and to enable use of filenames including extension (or script *.mp4 to get all):
#!/bin/bash
target='/home/lnk/Videos/' # remember to end this with /
for i in "$@"; do
ffmpeg -i "$i" -acodec libmp3lame -ab 160k -ar 44100 -ac 2 "$target${i%*.mp4}".mp3
done
You could also include check for availability of lame and ffmpeg, and give an error if not. There are a lot of converting scripts out there by the way, but if you see this as a learning experience, I hope this helps.
Offline
@VCoolio I'm not sure I understand your method. The reason I used $@ was because my video names often had spaces and dashes which it mistook for multiple variables. The only way I found to resolve that issue was to assign the full input as a variable. I don't see what a for loop would do here..it's still going to break the words apart and try to find 4 different files that don't exist instead of the full video name right? Can you explain? Also what does the i% section of your code do? I'm just now beginning to learn so i hope you'll understand.
Offline
The "@" means "all arguments given to the script read separately". So all filenames are read, and if you have given the filename as one argument, so spaces escaped like autocomplete would do or *.mkv, then that stays. So "$@" is what you want
Now we make a loop where we handle each file after another, everytime we call it "i". So the line starting with ffmpeg is done for each file, where file = i.
ffmpeg -i "$i" : this is where we give ffmpeg the input file
"$target${i%*.mp4}".mp3 is where we point to the target folder and target filename. We don't want the output file to be filename.mp4.mp3, so we tell it to use the filename without the ".mp4" part at the end. That's what %*.mp4 does. Check here: http://www.tldp.org/LDP/abs/html/string … ation.html
Last edited by VCoolio (2012-03-27 16:18:19)
Offline
Funny, I also adapted one not too long ago: http://blog.rolinh.ch/dev/convertir-sim … un-script/
It preserves the tags and offer a possibility to delete original m4a files after the conversion.
Offline
@VCoolio thanks for all the information. Very helpful I appreciate you taking the time to explain it.
Offline