SHARE
TWEET

tff_or_bff.pl

chrispitude Jan 4th, 2015 (edited) 145 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/perl -w
  2. # chrispitude@gmail.com 01/04/2015
  3. #
  4. # credit goes to Nicolas Hillegeer for:
  5. #  http://www.aktau.be/2013/09/22/detecting-interlaced-video-with-ffmpeg/
  6.  
  7.  
  8. # usage:
  9. #  ./tff_or_bff.pl <file>
  10. #    returns dominant frame type keyword (tff, bff, progressive, undetermined)
  11. #
  12. #  ./tff_or_bff.pl -i <file>
  13. #    returns dominant *interlaced* frame type keyword (tff, bff) and ignores noninterlaced data (progressive, undetermined);
  14. #    useful when you are sure the content is interlaced
  15. #
  16. #  ./tff_or_bff.pl -v <file>
  17. #    shows detailed frame count information for each frame type
  18.  
  19.  
  20. use strict;
  21. use Getopt::Std;
  22. my %args;
  23. getopts('iv', \%args);
  24.  
  25.  
  26. # acquire information from 'idet' ffmpeg filter
  27. my $output = `ffmpeg -filter:v idet -an -f rawvideo -y /dev/null -i $ARGV[0] 2>&1`;
  28. my ($single_tff, $single_bff, $single_progressive, $single_undetermined) = $output =~ m!^\[Parsed_idet.*Single frame detection:\s+TFF:\s+(\d+)\s+BFF:\s+(\d+)\s+Progressive:\s+(\d+)\s+Undetermined:\s+(\d+)!m;
  29. my ($multi_tff, $multi_bff, $multi_progressive, $multi_undetermined) = $output =~ m!^\[Parsed_idet.*Multi frame detection:\s+TFF:\s+(\d+)\s+BFF:\s+(\d+)\s+Progressive:\s+(\d+)\s+Undetermined:\s+(\d+)!m;
  30.  
  31. # sum single-frame and multi-frame results
  32. my %count = ();
  33. $count{tff} = $single_tff + $multi_tff;
  34. $count{bff} = $single_bff + $multi_bff;
  35. $count{progressive} = $single_progressive + $multi_progressive;
  36. $count{undetermined} = $single_undetermined + $multi_undetermined;
  37.  
  38. # get total frame count
  39. my $total_count = 0;
  40. $total_count += $count{$_} for keys(%count);
  41.  
  42. # consider only interlacing results (tff, bff) if i
  43. if ($args{i}) {
  44.  delete $count{progressive};
  45.  delete $count{undetermined};
  46. }
  47.  
  48. # sort frame counts by type, largest first
  49. my @sorted_count_types = sort {$count{$b} <=> $count{$a}} keys(%count);
  50.  
  51. # print dominant result if nonv
  52. if (!$args{v}) {
  53.  print "$sorted_count_types[0]";
  54. }
  55.  
  56. # print sorted results if v
  57. if ($args{v}) {
  58.  printf "%s: %d (%.2f%%)\n", $_, $count{$_}, (100.0*$count{$_}/$total_count) for (@sorted_count_types)
  59. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top