in reply to Re^6: Search hex string in vary large binary file
in thread Search hex string in vary large binary file
Here's my test script, the patch to MP4::Info is as described earlier. The "scan" code hopefully does your solution justice. Note this particular script currently only tests for the presence of the HDVD flag, it doesn't look at whether it has a value of 1 (720p) or 2 (1080p) - but that shouldn't make any difference for this benchmark.
#!/usr/bin/env perl use warnings FATAL => 'all'; use strict; use 5.010; use MP4::Info 'get_mp4tag'; my %func = ( external => sub { my $file=shift; return `AtomicParsley "$file" -T 1 2>/dev/null`=~/hdvd/i; }, scan => sub { my $file=shift; my $BUFN = 1024; $BUFN *= 4096; my $SIG = '68 64 76 64 00 00 00 11 64 61 74 61 00 00 00 15' .'00 00 00 00 02 00 00 00'; $SIG =~ tr[ ][]d; $SIG = pack 'H*', $SIG; open my $in, '<:raw', $file or die $!; my( $offset, $buffer ) = ( 0, '' ); while( sysread( $in, $buffer, $BUFN, length $buffer ) ) { my $pos = 1+index( $buffer, $SIG ); if( $pos ) { return 1; } $offset += length( $buffer ) - length( $SIG ); $buffer = substr $buffer, - length $SIG; } close $in; return; }, mp4info => sub { my $file=shift; my $tag = get_mp4tag($file) or return; return !!$tag->{HDVD}; }, ); die "Usage: $0 ".join('|',sort keys %func)." PATH\n" unless @ARGV==2 && exists $func{$ARGV[0]} && -d $ARGV[1]; my $FUNC = $ARGV[0]; my $PATH = $ARGV[1]; use File::Find 'find'; my ($yes,$no,$size) = (0,0,0); find({ wanted=>sub { return unless -f && /\.(mp4|m4[apvb])$/i; $size+=-s; if ($func{$FUNC}->($_)) { $yes++; say "YES $_"; } else { $no++; say " no $_"; } }}, $PATH); say "yes=$yes, no=$no, size=$size";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^8: Search hex string in vary large binary file
by BrowserUk (Patriarch) on Feb 08, 2015 at 05:08 UTC | |
by Anonymous Monk on Feb 08, 2015 at 11:35 UTC |