Created
May 16, 2014 01:20
-
-
Save fand/12019405ac6fead0e348 to your computer and use it in GitHub Desktop.
Perl AVI datamosh 修正版
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
open $f_in, '<', $ARGV[0]; | |
read $f_in, my $buf, -s $ARGV[0]; | |
my ( $movi, $idx1 ) = ( index( $buf, "movi" ), index( $buf, "idx1" ) ); | |
my @frames = | |
map { [ unpack( 'a4VVV', substr( $buf, $idx1 + 8 + $_ * 16, 16 ) ) ] } | |
0 .. ( ( unpack( 'V', substr( $buf, $idx1 + 4, 4 ) ) / 16 ) - 1 ); | |
my ( $movi_new, $idx1_new, $count ) = ( "movi", substr( $buf, $idx1, 8 ), 0 ); | |
for (@frames) { | |
my $offset = length $movi_new; | |
if (@$_[0] =~ /00d./ && @$_[1] & 0x10 && $count != 0) { | |
$movi_new .= @$_[0] . "\x00\x00\x00\x00"; | |
@$_[3] = "\x00\x00\x00\x00"; | |
} | |
else { | |
$count++ if @$_[0] =~ /00d./ && @$_[1] & 0x10; | |
$movi_new .= substr( $buf, $movi + @$_[2], @$_[3] + 8 ); | |
$movi_new .= "\x00" if length($movi_new) % 2 == 1; | |
} | |
@$_[1] = "\x00\x00\x00\x00" if @$_[0] =~ /00d./ && @$_[1] & 0x10; | |
@$_[2] = $offset; | |
$idx1_new .= pack( 'a4VVV', @$_ ); | |
} | |
my $size = $movi + (length $movi_new) + (length $idx1_new) - 8; | |
substr($buf, 4, 4, pack('V', $size)); | |
substr($buf, $movi - 4, 4, pack('V', length $movi_new)); | |
open $f_out, '>', $ARGV[1]; | |
print $f_out substr( $buf, 0, $movi ) . $movi_new . $idx1_new; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment