1 package Utils::PresentingPerl;
7 #use Data::Dump::Streamer;
9 use English '-no_match_vars';
12 # Given a filename, and an arrayref of information keys that we are interested in, returns a hashref with those keys filled in.
13 # If it cannot determine the information asked for (including if the keys are unknown), it will eventually return a hashref without them filled in.
14 # Known tags: 'width', 'height'. Size of video frame. Does not allow for changing size during the video.
16 my ($filename, $wanted_info) = @_;
18 my $file = FLV::File->new;
20 # We need to use a modified version of FLV::File::parse, or we'll end up parsing the whole file.
21 flv_parse($file, $filename);
27 # Now, we need to parse out the file, oen bit at at time, until we have what we wanted.
28 # This is from FLV::Body::parse
30 my $lastsize = $file->get_bytes(4);
32 my $tag = FLV::Tag->new;
33 $tag->parse($file, {});
34 my $payload = $tag->get_payload;
36 if ($payload->isa('FLV::VideoTag')) {
37 $info->{width} = $payload->{width};
38 $info->{height} = $payload->{height};
40 # For the time being, assume that other tags are unimportant.
41 # Could, plasuably, tell somthing about the audio... but what do we care about?
42 # Much more plausably, if our file had metadata tags, then we could read them.
43 #die "No handler for payload $payload";
47 next if !exists $info->{$_};
62 $self->{header} = undef;
63 $self->{body} = undef;
64 $self->{filename} = undef;
65 $self->{filehandle} = undef;
68 my $eval_result = eval {
70 $self->{filehandle} = $input;
72 $self->{filename} = $input;
73 ## no critic (RequireBriefOpen)
74 open my $fh, '<', $self->{filename} or croak q{} . $OS_ERROR;
75 binmode $fh or croak 'Failed to set binary mode on file';
76 $self->{filehandle} = $fh;
79 $self->{header} = FLV::Header->new();
80 $self->{header}->parse($self); # might throw exception
82 $self->{body} = FLV::Body->new();
83 # $self->{body}->parse($self, $opts); # might throw exception
87 die 'Failed to read FLV file: ' . $EVAL_ERROR;
90 #$self->{filehandle} = undef; # implicitly close the filehandle