-
Notifications
You must be signed in to change notification settings - Fork 0
/
split.pl
88 lines (73 loc) · 2.81 KB
/
split.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#!/usr/bin/perl
#use strict;
#use warnings;
use Getopt::Std;
our($opt_i, $opt_o, $opt_b, $opt_p, $opt_x);
my $n=0;
my $folder = "temp";
my $infilename = "filename.csq";
my $outfilebase = "frame";
my $outfilename = "";
my $pattype = "fff";
my $patfff = "\x46\x46\x46\x00"; # split a generic fff header (some seq files recorded on camera have simple headers like this)
my $patfcf = "\x46\x46\x46\x00\x43\x41\x50"; # split the fcf file type header (older video type)
my $patseq = "\x46\x46\x46\x00\x43\x41\x4D"; # split the seq file type header (based on camera controlled by computer)
my $patcsq = "\x46\x46\x46\x00\x52\x54\x50"; # split the csq file type header (compressed video format)
my $patjpegls = "\xff\xd8\xff\xf7"; # split out jpegls headers from .raw file generated from exiftool
my $pattiff = "II\\*\0";
my $outext = "fff";
my $file = "";
my (%opt)=();
getopts("h:i:o:b:p:x:",\%opt);
if ($opt{h}){
print qq(
Usage: perl split -i filename -o outputfoldername -b basename -p splitpattern -x outputfileextension
options:
-i input filename
-o output folder
-b base output name
-p split pattern (fff, fcf, seq, csq, jpegls, tiff)
-x output extension (fff, jpegls, tiff)\n.);
exit
}
if (!defined $opt{i} & !defined $opt{o} & !defined $opt{b} & !defined $opt{p} & !defined $opt{x}){die "Error: Please specify input file, output folder, the output filename base, pattern to split, and output file extension.\n"}
if (!defined $opt{i}){die "Error: Please specify the input file. \n"}
if (!defined $opt{o}){die "Error: Please specify the output folder.\n"}
if (!defined $opt{b}){die "Error: Please specify the output filename base.\n"}
if (!defined $opt{p}){die "Error: Please specify the split pattern.\n"}
if (!defined $opt{x}){die "Error: Please specify the output file extension.\n"}
my $pattype = "$opt_p";
$folder = $opt{o};
$infilename = $opt{i};
$outfilebase = $opt{b};
$outext = ".$opt{x}";
if ($opt{p} eq "fff"){
$pat = $patfff;
} elsif ($opt{p} eq "fcf"){
$pat= $patfcf;
} elsif ($opt{p} eq "seq"){
$pat = $patseq;
} elsif ($opt{p} eq "jpegls"){
$pat = $patjpegls;
} elsif ($opt{p} eq "tiff"){
$pat = $pattiff;
}
else {die "Error: Please specify the split pattern.\n"}
# Create output folder to store split files
unless(-e $folder or mkdir $folder) {
die "Unable to create $directory\n";
}
print "Processing $infilename\n";
# Use binary mode for portability between operating systems
binmode F;
open F, '<:raw', $infilename;
$file = do { local $/; <F> };
close F;
# Split infilename based on $pat
for my $content (split(/(?=$pat)/, $file)) {
$outfilename = ">$folder/$outfilebase" . sprintf("%05d",++$n) . $outext;
open(OUT, $outfilename);
binmode(OUT, ":raw");
print OUT $content;
close(OUT);
}