I am unable to resurrect old posts (for very good reasons).
This post from 2010 is essentially my exact question with some slight changes to the input and output folder/file locations.
Here is the text of the linked forum post (reformatted), for reference. I have modified the details of the post so they apply to my specific parameters. The quoted items are generic placeholders if that isn't immediately evident: (I recognize alac is lossless. "compressed" is the folder itunes watches for any compatible files and has mp3's in it, as well.)
I have several large sets of .flac files that are all organized like so:
/home/storage/music/lossless/"Artist"/"Album"/"Song.flac"
I would like to convert these to alac's (.m4a) in order to play them on my iPhone. I have a script that will convert all the flac's in a folder to alac .m4a's and it looks like this:
The problem is that with my current file structure I have to run that command in the folder of every album, which would take a long time.Code:for i in *.flac; do ffmpeg -i "$i" -acodec alac "`basename "$i" .flac`.m4a"; done;
What I would like to do is a write a script that would just run ffmpeg, recursively, in every folder found in /home/storage/music/lossless.
Then, I'd like to append a script to move all the newly created alac's to another folder in a way that retains the current structure so I could end up with something like:
input = /home/storage/music/lossless/"Artist"/"Album"/"Song.flac" and output = /home/storage/music/compressed/"Artist"/"Album"/"Song.m4a"
Any suggestions/advice/feedback would be appreciated.
Thanks for your time,
Sohex
The final reply, with a solution, is as follows:
I was able to figure out that for the beginning, I can substituteSorry, my fault. The "basename" removes the directory part of the names.Originally Posted by Originally Posted by Sohex
Either replace "`basename "${i/Music/Music_too}" .flac`.m4a" with "`dirname ${i/Music/Music_too}"`/`basename "$i" .flac`.m4a" or edit $i in two steps using neither dirname nor basename, like o=${i/Music/Music_too}; o=${o%.flac%.m4a} and then use "$o" in the ffmpeg command.
Put an echo before the ffmpeg the first time you run the command to see what it will do:Code:for i in Music/*/*/*.flac; do o=${i/Music/Music_too}; o=${o%.flac%.mp4}; ffmpeg -i "$i" -acodec alac "$o"; done
Code:for i in Music/*/*/*.flac; do o=${i/Music/Music_too}; o=${o%.flac%.mp4}; echo ffmpeg -i "$i" -acodec alac "$o"; doneMy confusion lies with the parameters for the do function. Specifically, the subsequent string variable. I am unable to figure out how to properly substitute my parameters into this case and use the script suggested.Code:for i in /home/storage/music/lossless/*/*/*.flac;
If possible, an additional step that checks the respective "compressed" folder for .m4a's already existing would aid in being able to reuse this single script each time I've added files to the "lossless" folder. Perhaps, as a CRON job that is run nightly. This is not a priority or needed at all, just a hopeful wish, if easily executed.
Any help would be greatly appreciated.
Bookmarks