Advertisement
spikeysnack

idetect

Feb 13th, 2017
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.55 KB | None | 0 0
  1. #!/usr/bin/env bash
  2.  
  3. # idetect.sh
  4. # attempts to detect if video is interlaced
  5. # "should be" non-destructive
  6.  
  7. AUTHOR="Chris Reid"
  8. EMAIL="spikeysnack@gmail.com"
  9. DATE="13 FEB 2017"
  10.  
  11. FF=$(which ffmpeg)
  12.  
  13. # you can try more or less frames, accuracy improves with more, but takes longer
  14. frames=256  
  15.  
  16. # throwing away video so just go raw
  17. format="rawvideo"
  18.  
  19. # example output
  20. #[Parsed_idet_0 @ 0x38e3000] Single frame detection: TFF:0 BFF:368 Progressive:101 Undetermined:44
  21. #[Parsed_idet_0 @ 0x38e3000] Multi frame detection: TFF:0 BFF:481 Progressive:10 Undetermined:22
  22.  
  23. # filter the relevant part
  24. OUT=$("${FF}" -filter:v idet -frames:v "${frames}" -an -f "${format}" -y /dev/null  \
  25.     -i "${1}" 2>&1 | grep 'Parsed_idet' )
  26.  
  27. # parse into array
  28. testString="${OUT}"
  29. array=( $testString )
  30.  
  31. # iterate the array
  32. alen=${#array[@]} # num items in array
  33. for n in $(seq 0 $alen) #
  34. do
  35.     # Top Field First (TFF)  or Bottom Field First (BFF)
  36.     if [ "${array[$n]:0:3}" == "TFF" ]  ||  [ "${array[$n]:0:3}" == "BFF" ]; then
  37.         echo "${array[$n]}"
  38.         S="${array[$n]}"
  39.         N="${S#*:}"
  40. #   echo "N" "${N}"
  41.     fi
  42.  
  43.     if [ "${array[$n]:0:11}" == "Progressive" ] ; then
  44.         echo "${array[$n]}"
  45.         S="${array[$n]}"
  46.         P="${S#*:}"
  47.     fi
  48. done
  49.  
  50. # colors
  51. normal="$(tput sgr0)"
  52. black="$(tput setaf 0)"
  53. red="$(tput setaf 1)"
  54. green="$(tput setaf 2)"
  55.  
  56. # decisions
  57. if [ $((N)) -gt 0 ]  &&  [ $((P)) -lt $((N)) ] ; then
  58.     echo -e "${green}YES probably interlaced${normal}"
  59. else
  60.     echo -e "${red}NO probably not interlaced ${normal}"
  61. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement