0

I am trying to get the duration of an audio file (.wav) in milliseconds.

I have seen some command lines using ffmpeg, but this library is deprecated (remplaced by avconv) on my Ubuntu version, and i didn't find anything on it.

I can get the duration by running avconv -i <file> but i am looking for the result in milliseconds.

4

1 回答 1

0

把它写成一个小的独立.sh文件:

file="$1"
info=$(sox $file -n stat 2>&1)
full_length=$(echo "$info" | sed -n 's#^Length (seconds):[^0-9]*\([0-9.]*\).*$#\1#p')
seconds=$(echo $full_length | cut -f1 -d.)

if [ -n "$seconds" ]; then
    milliseconds=$(echo $full_length | cut -f2 -d. | cut -c -3)

    result=$(($seconds * 1000))
    result=$(($result + $milliseconds))

    echo "$result"
    exit
fi

echo "0"
exit

像这样称呼它

new-file.sh test.wav

得到类似的结果(以毫秒为单位的持续时间)

1337

(你可以在GitHub上找到我使用的所有源代码的完整代码)

于 2016-08-03T20:53:48.260 回答