خرید بک لینک

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:

Code:

for i in *.flac; do ffmpeg -i "$i" -acodec alac "`basename "$i" .flac`.m4a"; done;
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.

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:
Quote Originally Posted by Originally Posted by Sohex

The converted m4a's show up in the directory containing Music and Music_too (or FLAC and ALAC if you will) instead of in the appropriate location, how can I fix that?

Sorry, my fault. The "basename" removes the directory part of the names.

Either replace "`basename "${i/Music/Music_too}" .flac`.m4a" with "`diame ${i/Music/Music_too}"`/`basename "$i" .flac`.m4a" or edit $i in two steps using neither diame nor basename, like o=${i/Music/Music_too}; o=${o%.flac%.m4a} and then use "$o" in the ffmpeg command.

Code:

for i in Music/*/*/*.flac; do o=${i/Music/Music_too}; o=${o%.flac%.mp4}; ffmpeg -i "$i" -acodec alac "$o"; done
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}; echo ffmpeg -i "$i" -acodec alac "$o"; done
I was able to figure out that for the begiing, I can substitute

Code:

for i in /home/storage/music/lossless/*/*/*.flac;
My 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.

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.

برچسب: نویسنده: استخدام کار تاريخ: جمعه 1 مرداد 1395 ساعت: 4:58

صفحه بندی