Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #! /bin/bash
- #
- # Calculate bitrate statistics for movies
- #
- # Requires:
- # ffmpeg_bitrate_stats (https://github.com/slhck/ffmpeg-bitrate-stats)
- # printTable from util.bash (https://github.com/gdbtek/linux-cookbooks/blob/master/libraries/util.bash)
- # jq (https://stedolan.github.io/jq/)
- #
- # Sample results: https://pastebin.com/qNJhj61x
- #
- set -e
- # Find all 4K movies on hard drives
- find /mnt/B /mnt/G /mnt/S /mnt/Z -type f -regextype egrep -iregex ".*/Downloads/Movies-4k/.*\.(mkv|mp4|ts)" -exec du -hs "{}" \; | sort -hr > 4k_files
- # Calculate bitrate stats for all 4K files
- # Bitrate calculation takes ~ 5 minutes per 60 GB 4K file
- IFS=$'\n'
- for i in $(< 4k_files); do echo "$i"; fname="$(echo "$i" | cut -f2)"; out_fname="rate_output/$(basename $fname).rate"; [[ -f "$out_fname" ]] && echo "Rate file already exists. Skipping." || ffmpeg_bitrate_stats -of json "$fname" > "$out_fname"; done
- # Write table of bitrate stats to file
- cd rate_output
- echo "Name,Size,Average,Minimum,Maximum,Seconds > 100" > rate_table; for i in $(< ../4k_files); do fsize=$(echo "$i" | cut -f1); fname=$(basename $(echo "$i" | cut -f2)); avg=$(cat "$fname.rate" | jq -r '.avg_bitrate/1000'); max=$(cat "$fname.rate" | jq -r '.max_bitrate/1000'); min=$(cat "$fname.rate" | jq -r '.min_bitrate/1000'); count=$(cat "$fname.rate" | jq -r '.bitrate_per_chunk | .[] | "\(.) \(. > 100000)"' | grep true | wc -l); printf "%s,%s,%.2f,%.3f,%.2f,%d\n" "$fname" "$fsize" "$avg" "$min" "$max" "$count"; done >> rate_table
- # Print table to output
- printTable ',' "$(< rate_table)"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement