Advertisement
peacey8

Calculate Bitrate Stats

Jan 13th, 2020
5,375
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.54 KB | None | 0 0
  1. #! /bin/bash
  2. #
  3. # Calculate bitrate statistics for movies
  4. #
  5. # Requires:
  6. # ffmpeg_bitrate_stats (https://github.com/slhck/ffmpeg-bitrate-stats)
  7. # printTable from util.bash (https://github.com/gdbtek/linux-cookbooks/blob/master/libraries/util.bash)
  8. # jq (https://stedolan.github.io/jq/)
  9. #
  10. # Sample results: https://pastebin.com/qNJhj61x
  11. #
  12.  
  13. set -e
  14.  
  15. # Find all 4K movies on hard drives
  16. 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
  17.  
  18. # Calculate bitrate stats for all 4K files
  19. # Bitrate calculation takes ~ 5 minutes per 60 GB 4K file
  20. IFS=$'\n'
  21. 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
  22.  
  23. # Write table of bitrate stats to file
  24. cd rate_output
  25. 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
  26.  
  27. # Print table to output
  28. printTable ',' "$(< rate_table)"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement