编码的音频文件,然后用bash脚本

问题描述:

我正在写一个bash脚本,将在Linux上运行转换对其进行重命名/编码的音频文件编码的音频文件,然后用bash脚本

转换工作正常,到目前为止,但是当涉及到重新命名产生文件根据我必须坚持它的特定模式产生错误。

名为音频001.flac的文件已被重命名为 2552011-Unit05-Fil001.flac以下的模式:拍摄日期记录单元ID-文件ID]

我的代码中号使用用于重命名:

echo "Enter Recording Date, Recording Unit-ID, and File-ID Separated by SPACE"

read RD RU FID

echo "Your input is: $RD, $RU, $FD " >> /home/user-name/Music/User-Input.txt #This is for logging

mv $FLACS/*.flac $FLACS/${RD}-${RU}-${FID}.$flac

我得到一个错误:mv: target 22112011-Unit05-File0. is not a directory

我可以使用find和sed?

find bar -iname "*.wav" -printf 'mv %p %p\n' \

| sed 's/*\.wav$/${RD}-${RU}-${FID}\.flac/' \ 
    | while read l; do eval $l; done` 
+1

哪儿是你卡住了? – Sriram 2011-06-07 09:35:04

+0

嗯,我知道我可以使用类似[f中的* .wav 做 flac“$ f”-o“$ {f%.wav} .flac” 完成]我只是困惑如何去解析和重命名机制。 – Lithiumion 2011-06-07 10:19:59

工作需要尼斯击穿,所以:

find WHERE -print | grep -i PATTERN #or 
find WHERE -name ... print0 | xargs -0 -I% .... #or the simple 
echo ./**/*.wav 

2 - use an open source tool such as flac and ffmpeg to convert all the .WAV files in that folder tree to .FLAC

是,你就是:

1 - Parse a folder tree (full of .WAV files)

这可以用几种方式,形式进行对。一般语法是

flac [<general-options>] [<format-options>] [<encoding options>] [inputfile [...]] 

3- Place the .FLAC files in a newly created folder tree that is identical to the original

不是一个艰巨的任务。在Linux中,您可以使用mkdir命令创建一个目录。您可以从find命令(1)中获得相同的树。可能还需要使用dirname命令。 (这里是其他方面也是如此,但目录名称是好的)

4- when naming the new .FLAC and their respective folders it will add a unique identifier to the file names i.e folder named 2582001 contains the files 2582001-1.wav and 2582001-2.wav will be recreated and will contain two .FLAC files with the names 2582001-REC05-FIL1.FLAC and 2582001-REC05-FIL2.FLAC. This structure of the new file names is [Recording Date - Recording Unit ID - File ID].

同样不是一个艰巨的任务,你可以使用以下命令:

command > "${RecordingDate} - ${RecordingUnitID} - ${FileID}" 

但不recommening这一点。当然会更好命名文件没有空间,例如:

command > "${RecordingDate}-${RecordingUnitID}-${FileID}" 
如果你想重命名文件使用 mv命令,像

mv oldfilename.ext "${RecordingDate}-${RecordingUnitID}-${FileID}.$newext" 

PS:如果你想要一些更精确回答,请尝试更精确。 :)

+0

谢谢!这是一个很好的起点 – Lithiumion 2011-06-07 13:41:42

+0

+1:很好的答案。尤其是创建新的目录部分。 – Sriram 2011-06-08 06:53:53

+0

编辑您的问题并显示导致问题的原因。如果不可能只根据文本问题给出一个好的建议。 – jm666 2011-06-10 22:07:26

您正在尝试mv更多文件到“一个文件”中。

mv $FLACS/*.flac $FLACS/${RD}-${RU}-${FID}.$flac 

*.flac被扩展为更多文件。你不能将更多的文件移动到一个。当移动更多的文件时,mv想要将他的最后一个参数作为目录。

你可能想:

mv $FLACS/some_one_file.flac $FLACS/${RD}-${RU}-${FID}.flac 
+0

那么,如何让它根据用户输入顺序重命名文件。这里的重要一点是文件ID。 Audio-001.flac必须重命名为2552011-Unit05-001.flac。我只是将日期和单位ID添加到原始文件名中。 – Lithiumion 2011-06-10 23:20:33