Advertisement
spikeysnack

idetect

Feb 13th, 2017
211
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. DATE="13 FEB 2017"
  9.  
  10. FF=$(which ffmpeg)
  11.  
  12. # you can try more or less frames, accuracy improves with more, but takes longer
  13. frames=256  
  14.  
  15. # throwing away video so just go raw
  16. format="rawvideo"
  17.  
  18. # example output
  19. #[Parsed_idet_0 @ 0x38e3000] Single frame detection: TFF:0 BFF:368 Progressive:101 Undetermined:44
  20. #[Parsed_idet_0 @ 0x38e3000] Multi frame detection: TFF:0 BFF:481 Progressive:10 Undetermined:22
  21.  
  22. # filter the relevant part
  23. OUT=$("${FF}" -filter:v idet -frames:v "${frames}" -an -f "${format}" -y /dev/null  \
  24.     -i "${1}" 2>&1 | grep 'Parsed_idet' )
  25.  
  26. # parse into array
  27. testString="${OUT}"
  28. array=( $testString )
  29.  
  30. # iterate the array
  31. alen=${#array[@]} # num items in array
  32. for n in $(seq 0 $alen) #
  33. do
  34.     # Top Field First (TFF)  or Bottom Field First (BFF)
  35.     if [ "${array[$n]:0:3}" == "TFF" ]  ||  [ "${array[$n]:0:3}" == "BFF" ]; then
  36.         echo "${array[$n]}"
  37.         S="${array[$n]}"
  38.         N="${S#*:}"
  39. #   echo "N" "${N}"
  40.     fi
  41.  
  42.     if [ "${array[$n]:0:11}" == "Progressive" ] ; then
  43.         echo "${array[$n]}"
  44.         S="${array[$n]}"
  45.         P="${S#*:}"
  46.     fi
  47. done
  48.  
  49. # colors
  50. normal="$(tput sgr0)"
  51. black="$(tput setaf 0)"
  52. red="$(tput setaf 1)"
  53. green="$(tput setaf 2)"
  54.  
  55. # decisions
  56. if [ $((N)) -gt 0 ]  &&  [ $((P)) -lt $((N)) ] ; then
  57.     echo -e "${green}YES probably interlaced${normal}"
  58. else
  59.     echo -e "${red}NO probably not interlaced ${normal}"
  60. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement