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 .shfile:

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

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -