scripts

random scripts
git clone https://git.parazyd.org/scripts
Log | Files | Refs

fbits (922B)


      1 #!/bin/bash
      2 
      3 me="${0##*/}"
      4 
      5 if [ -w "$TMPDIR" ]; then
      6 	tdir="$TMPDIR"
      7 elif [ -w '/tmp' ]; then
      8 	tdir='/tmp'
      9 elif [ -w "$HOME" ]; then
     10 	tdir="$HOME"
     11 elif [ -w "$PWD" ]; then
     12 	tdir="$PWD"
     13 else
     14 	echo "$me: error: can't find a writable directory for creating the temporary file" 1>&2 ; exit 1
     15 fi
     16 
     17 tf="$( TMPDIR="$tdir" mktemp "${tdir}/${me}.XXXX" 2>/dev/null )"
     18 if [ -z "$tf" ]; then
     19 	echo "$me: error: can't create temporary file" 1>&2 ; exit 1
     20 fi
     21 
     22 checkbits ()
     23 {
     24 	local bps abps tbps=0 n=0
     25 	bps="$( metaflac --show-bps "$1" )"
     26 	flac -ac "$1" 2>/dev/null | fgrep 'wasted_bits' | cut -d '=' -f 3 | cut -f 1 > "$tf"
     27 	while read wb; do
     28 		tbps=$(( tbps + ( bps - wb ) ))
     29 		((n++))
     30 	done < "$tf"
     31 	abps=$(( ( ( tbps * 10 / n) + 5 ) / 10 )) # (* 10 + 5) / 10 for proper rounding
     32 	printf "%2u/%2u bits\t%s\n" "$abps" "$bps" "$1"
     33 }
     34 
     35 for f in "$@"; do
     36 	case "$f" in
     37 		*.flac) checkbits "$f" ;;
     38 		*) continue ;;
     39 	esac
     40 done
     41 
     42 rm -f "$tf"