root/gsdl/trunk/perllib/imageconvert.pm @ 17110

Revision 16841, 3.7 KB (checked in by davidb, 11 years ago)

Supporting classes for conversion

Line 
1###########################################################################
2#
3# imageconvert.pm -- utility to help convert image file
4#                    used by ImagePlug, PagedImgPlug ...
5#
6# Copyright (C) 1999 DigiLib Systems Limited, NZ
7#
8# This program is free software; you can redistribute it and/or modify
9# it under the terms of the GNU General Public License as published by
10# the Free Software Foundation; either version 2 of the License, or
11# (at your option) any later version.
12#
13# This program is distributed in the hope that it will be useful,
14# but WITHOUT ANY WARRANTY; without even the implied warranty of
15# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16# GNU General Public License for more details.
17#
18# You should have received a copy of the GNU General Public License
19# along with this program; if not, write to the Free Software
20# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21#
22###########################################################################
23
24
25package imageconvert;
26
27use strict;
28no strict 'refs'; # allow filehandles to be variables and viceversa
29
30
31use baseconvert;
32
33sub BEGIN {
34    @imageconvert::ISA = ('baseconvert');
35}
36
37
38
39# Discover the characteristics of an image file with the ImageMagick
40# "identify" command.
41
42sub identify {
43    my ($image, $outhandle, $verbosity) = @_;
44
45    # Use the ImageMagick "identify" command to get the file specs
46    my $command = "identify \"$image\" 2>&1";
47    print $outhandle "$command\n" if ($verbosity > 2);
48    my $result = '';
49    $result = `$command`;
50    print $outhandle "$result\n" if ($verbosity > 3);
51
52    # Read the type, width, and height
53    my $type =   'unknown';
54    my $width =  'unknown';
55    my $height = 'unknown';
56
57    my $image_safe = quotemeta $image;
58    if ($result =~ /^$image_safe (\w+) (\d+)x(\d+)/) {
59    $type = $1;
60    $width = $2;
61    $height = $3;
62    }
63   
64    # Read the size
65    my $size = "unknown";
66    if ($result =~ m/^.* ([0-9]+)b/) {
67    $size = $1;
68    } elsif ($result =~ m/^.* ([0-9]+)kb/) {
69    $size = 1024 * $1;
70    }
71
72    print $outhandle "file: $image:\t $type, $width, $height, $size\n"
73    if ($verbosity > 3);
74
75    # Return the specs
76    return ($type, $width, $height, $size);
77}
78
79
80
81
82sub new {
83    my ($class) = shift @_;
84
85    my ($base_dir,$image_filename,$verbosity,$outhandle) = @_;
86
87    my $self = new baseconvert($base_dir,$image_filename,$verbosity,$outhandle);
88   
89    return bless $self, $class;
90}
91
92
93sub stream_cmd_XXXX
94{
95    my $self = shift (@_);
96    my ($ivideo_filename,$video_width,$video_height,
97    $streaming_bitrate,$streaming_size,
98    $opt_streaming_achan, $opt_streaming_arate) = @_;
99
100    my $streaming_achan
101    = (defined $opt_streaming_achan) ? $opt_streaming_achan : 2;
102
103    my $streaming_arate
104    = (defined $opt_streaming_arate) ? $opt_streaming_arate : 22050;
105
106    my $output_dir = $self->{'cached_dir'};
107    my $ivideo_root = $self->{'file_root'};
108
109    my $oflash_file = "${ivideo_root}_stream.flv";
110    my $oflash_filename = &util::filename_cat($output_dir,$oflash_file);
111
112    my $s_opt = $self->optional_frame_scale($streaming_size,$video_width,$video_height);
113
114    my $exp_duration = $self->{'exp_duration'};
115    my $t_opt = (defined $exp_duration) ? "-t $exp_duration" : "";
116
117    my $main_opts = "-y $t_opt";
118
119    my $stream_opts = "-b $streaming_bitrate $s_opt";
120    ### my $stream_opts = "-r 25 $s_opt";
121    $stream_opts .= " -ac $streaming_achan -ar $streaming_arate";
122    $stream_opts .= " -pass 1/2";
123
124    # -flags +ilme+ildct' and maybe '-flags +alt' for interlaced material, and try '-top 0/1'
125
126    my $all_opts = "$main_opts $stream_opts";
127    my $ffmpeg_cmd = "ffmpeg  -i \"$ivideo_filename\" $all_opts -y \"$oflash_filename\"";
128
129    return ($ffmpeg_cmd,$oflash_filename,$oflash_file);
130}
131
132
133
134
135
136
137
138
139
1401;
Note: See TracBrowser for help on using the browser.