Thanks to BrowserUK I was able to get the following code to work for byte aligned data, however I've ran into a situation where some of the data isn't byte aligned meaning the patterns I'm looking for go across byte boundaries. I'll have to do this at a bit level. Any idea how to tweak the code to do this??
#! perl -sw
use strict;
use bytes;
open IN, '< :raw', $ARGV
0 or die "$ARGV
0 : $!";
open OUT, '> :raw', $ARGV
1 or die "$ARGV
1 : $!";
## Grab a double buffer load first time so we can check & correct alig
+nment
local $/ = \768;
my $buf = <IN>; ## Read two frames worth
## Check alignment. Assumes the xf4 .191 xf4 is unique per frame?
$buf =~ m
(\xF4.{191}\xF4);
## Record the offset to the first frame
my $offset = $-[0];
## If there was an offset to the first match
if( $offset != 0 ) {
## Chop off the leading junk
substr( $buf, 0, $offset, '' );
## Top up the buffer to two full frames
read( IN, $buf, $offset, 768 - $offset );
warn "$offset bytes discarded from front of file.";
}
## Process the first two whole frames
print OUT unpack 'x2 a190 x2 a58 x132' x 2, $buf
## Now process as before
local $/ = \384; ## Read file in 384 byte chunks.
while( <IN> ) {
print OUT unpack 'x2 a190 x2 a58', $_;
}
close IN;
close OUT;
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.