FLAC decoding script
Hi,
I have a library of FLAC files which I need to convert to WAVs. The FLAC files are in a folder called FLAC, with each album in a uniquely named folder. The WAV files will be in a folder called WAV, again with each album in its own folder, named the same as the FLAC album folder. So I guess I need to know how to recursively descend into folders and decode the FLAC files into similar directory structures elsewhere. /home/FLAC/Album1/track1.flac becomes /home/WAV/Album1/track1.wav /home/FLAC/Album1/track2.flac becomes /home/WAV/Album1/track2.wav /home/FLAC/Album2/track1.flac becomes /home/WAV/Album2/track1.wav ...etc This code is currently working for a single album folder: Code:
#!/bin/bash Code:
[root@server52870 bms002]# flacdecode |
you might try this (test it first, then remove the comments
and the echo lines) assuming your flac cmd works as: flac inputfile outputfile ### cut and paste into a shell script ### #!/bin/sh TOP=replace_here_by_the_folder_above_both_FLAC_n_WAV FLAC=$TOP/FLAC WAV=$TOP/WAV find $FLAC/* | while read f do cmd="echo $f | sed 's?^$FLAC?$WAV?'" g="$(eval $cmd)" d=${g%/*} echo "mkdir -p $WAV/$d" # mkdir -p $WAV/$d if [ -d $f ]; then continue fi ext=${f##*.} if [ "$ext" == "flac" ]; then echo "flac $f $g || exit 1" # flac $f $g || exit 1 fi done #### end of script |
Hi vonbiber,
Thanks for the reply - can you explain what the code does? I think it's very close to what I need but currently doesn't quite do it... Here's my script: Code:
#!/bin/sh Code:
mkdir -p /media_library/12//media_library/12 |
Sussed it! Probably a weird hack, but works... thanks loads for your help vonbiber. Here's what worked in the end:
Code:
#!/bin/sh |
FWIW and not that it has any bearing on your script or would apply if your .flac don't have any information, or if .wav is not just an intermediate conversion stage, but FLAC can store quite a lot of information and a flac->wav conversion won't transfer it. As in 'metaflac --export-tags.*'.
|
Quote:
actually doing the conversion I'll try to explain The idea is to store the output files in a tree similar to the input files (except for the top directory which for the input files is $FLAC and it exists for the output files is $WAV and it doesn't necessarily exists 1. first we look for all files/folders/subfolders in the input directory $FLAC find $FLAC/* | while read f do ... done 2. cmd="echo $f | sed 's?^$FLAC?$WAV?'" g="$(eval $cmd)" the 2 lines above help us form the target path we can't directly do g=$(echo $f | sed 's?^$FLAC?$WAV?'") that wouldn't work (eval replaces the variables FLAC and WAV by their actual values before executing sed) d=${g%/*} this one forms the directory part of the complete path $g so for instance, if the input file is /media_library/flacfiles/folder0/folderA/file.avi g is gonna be /media_library/wavefiles/folder0/folderA/file.avi and d: /media_library/wavefiles/folder0/folderA mkdir -p $d we create the directory $d if it doesn't already exist if [ -d $f ]; then continue fi if $f is a directory proceed, do nothing ext=${f##*.} this store the extension of the file in the variable ext if the test below is true if [ "$ext" == "flac" ]; then do the conversion ... These shell constructions are quite useful (and more efficient than the commands 'basename', 'sed', etc.) so whenever you can use them do so g=${f##*/} : filename (without the directory part) n=${g%.*} : name (without the extension) hope this is clear enough |
All times are GMT -5. The time now is 05:28 PM. |