[英]Using bash to cycle through files in directory then create sub-directory based on file name
我正在尝试使用bash来
1) cycle through files in a directory
2) then create a sub-directory based on the file names
3) then split mp3 files using ffmpeg in 3 second increments.
我可以创建子目录,然后ffmpeg代码使用正确的名称拆分文件。 我似乎遇到的问题是循环。 它创建了split-chirp目录及其所有文件,但不处理pink.mp3文件。 参见起始目录下图
它不会创建粉红色的目录和所有文件(我知道这是一个循环问题,只是无法弄清楚原因)
我使用命令bash mp3spl.sh *.mp3
运行代码
下面的代码
#!/bin/bash
currentdir=$(pwd) #get current directory
for f in $currentdir/*.mp3
do
fn=`echo "$1" | cut -d'.' -f1` #get just the filename no extension
splitdirname="$currentdir/split-$fn" #sub directory with correct names
mkdir -p "$splitdirname" #make split directory
echo "Processing $f"
ffmpeg -i "$1" 2> tmp.txt
ffmpeg -i "$1" -f segment -segment_time 3 -ar 22050 -ac 1 "$splitdirname/$fn-%03d.mp3"
#rm tmp.txt
done
$1
是不必要的,因为您要循环播放所有mp3文件。
fn=$(basename "$f" | cut -d'.' -f1) #get just the filename no extension
我保持其余的不变。
这将与目录和文件名中的空格一起使用
#!/bin/bash
#run using bash mp3spl.sh
currentdir="$(pwd)" #get current directory
for f in *.mp3 #only look for mp3 files
do
fn=$(basename "$f" | cut -d'.' -f1) #get just the filename no extension
splitdirname="$currentdir/split-$fn" #sub directory with correct names
mkdir -p "$splitdirname" #make split directory
#echo "Processing $f"
ffmpeg -i "$1" 2> tmp.txt
ffmpeg -i "$f" -f segment -segment_time 1200 -ar 22050 -ac 1 "$splitdirname/%03d-$fn.mp3" #split every 20mins
#rm tmp.txt
done
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.