shell - How to get the duration of a file in milliseconds -
i trying duration of audio file (.wav) in milliseconds.
i have seen command lines using ffmpeg
, library deprecated (remplaced avconv
) on ubuntu version, , didn't find on it.
i can duration running avconv -i <file>
looking result in milliseconds
.
wrote small stand-alone .sh
file:
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" ]; milliseconds=$(echo $full_length | cut -f2 -d. | cut -c -3) result=$(($seconds * 1000)) result=$(($result + $milliseconds)) echo "$result" exit fi echo "0" exit
call like
new-file.sh test.wav
to result (duration in ms)
1337
(you can find full code sources used on github)
Comments
Post a Comment