Skip to content

Instantly share code, notes, and snippets.

Created March 12, 2018 23:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/10cd235949ae354cb49cb3564bd722c6 to your computer and use it in GitHub Desktop.
Save anonymous/10cd235949ae354cb49cb3564bd722c6 to your computer and use it in GitHub Desktop.
#!/usr/bin/perl
# Splits a ".pic" file created by a Hikvision camera
# into single jpeg files
if (! (${file}=$ARGV[0]) ) {
print "Usage: $0 filename\n"; exit 1;
}
open FILE, ${file};
while (<FILE>){
${jpeg} .= $_;
}
close ${file};
${index}=0;
while ( index(${jpeg}, "\xFF\xD8") != -1 ) {
$start = index(${jpeg}, "\xFF\xD8");
$end = index(${jpeg}, "\xFF\xD9");
${singlejpeg} = substr(${jpeg}, $start, $end);
${jpeg} = substr(${jpeg}, $end+1);
open (OUTFILE, ">${file}_${index}.jpg");
print OUTFILE ${singlejpeg};
close OUTFILE;
${index}++;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment