1 | ######################################################################
|
---|
2 | #
|
---|
3 | # MultimediaPlugin.pm -- internal plugin to support processing audio and video
|
---|
4 | # A component of the Greenstone digital library software
|
---|
5 | # from the New Zealand Digital Library Project at the
|
---|
6 | # University of Waikato, New Zealand.
|
---|
7 | #
|
---|
8 | # Copyright (C) 1999 New Zealand Digital Library Project
|
---|
9 | #
|
---|
10 | # This program is free software; you can redistribute it and/or modify
|
---|
11 | # it under the terms of the GNU General Public License as published by
|
---|
12 | # the Free Software Foundation; either version 2 of the License, or
|
---|
13 | # (at your option) any later version.
|
---|
14 | #
|
---|
15 | # This program is distributed in the hope that it will be useful,
|
---|
16 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
17 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
18 | # GNU General Public License for more details.
|
---|
19 | #
|
---|
20 | # You should have received a copy of the GNU General Public License
|
---|
21 | # along with this program; if not, write to the Free Software
|
---|
22 | # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
---|
23 | #
|
---|
24 | ###########################################################################
|
---|
25 |
|
---|
26 | # -- Largely modeled on how ImagePlugin works
|
---|
27 |
|
---|
28 | package MultimediaPlugin;
|
---|
29 |
|
---|
30 | use strict;
|
---|
31 | no strict 'refs'; # allow filehandles to be variables and viceversa
|
---|
32 | no strict 'subs';
|
---|
33 |
|
---|
34 | use gsprintf;
|
---|
35 |
|
---|
36 | use BasePlugin;
|
---|
37 |
|
---|
38 | sub BEGIN {
|
---|
39 | @MultimediaPlugin::ISA = ('BasePlugin');
|
---|
40 |
|
---|
41 | if (!defined $ENV{'GEXTVIDEO'}) {
|
---|
42 | print STDERR "Warning: Greenstone Video extension not detected.\n";
|
---|
43 | }
|
---|
44 |
|
---|
45 | }
|
---|
46 |
|
---|
47 |
|
---|
48 |
|
---|
49 | # do later the description
|
---|
50 | my $arguments =
|
---|
51 | [ { 'name' => "use_ascii_only_filenames",
|
---|
52 | 'desc' => "{VideoPlug.use_ascii_only_filenames}",
|
---|
53 | 'type' => "flag",
|
---|
54 | 'reqd' => "no" },
|
---|
55 | { 'name' => "excerpt_duration",
|
---|
56 | 'desc' => "{MultimediaPlug.excerpt_duration}",
|
---|
57 | 'type' => "string",
|
---|
58 | 'deft' => "",
|
---|
59 | 'reqd' => "no" },
|
---|
60 | { 'name' => "converttotype",
|
---|
61 | 'desc' => "{MultimediaPlug.converttotype}",
|
---|
62 | 'type' => "string",
|
---|
63 | 'deft' => "",
|
---|
64 | 'reqd' => "no" },
|
---|
65 | { 'name' => "enable_flv_streaming",
|
---|
66 | 'desc' => "{MultimediaPlug.enable_streaming}",
|
---|
67 | 'type' => "flag",
|
---|
68 | 'deft' => "1",
|
---|
69 | 'reqd' => "no" },
|
---|
70 | { 'name' => "enable_mp4_streaming",
|
---|
71 | 'desc' => "{MultimediaPlug.enable_streaming}",
|
---|
72 | 'type' => "flag",
|
---|
73 | 'deft' => "0",
|
---|
74 | 'reqd' => "no" } ];
|
---|
75 |
|
---|
76 | my $options = { 'name' => "MultimediaPlugin",
|
---|
77 | 'desc' => "{MultimediaPlug.desc}",
|
---|
78 | 'abstract' => "yes",
|
---|
79 | 'inherits' => "yes",
|
---|
80 | 'args' => $arguments };
|
---|
81 |
|
---|
82 |
|
---|
83 | sub new {
|
---|
84 | my ($class) = shift (@_);
|
---|
85 | my ($pluginlist,$inputargs,$hashArgOptLists) = @_;
|
---|
86 | push(@$pluginlist, $class);
|
---|
87 |
|
---|
88 | push(@{$hashArgOptLists->{"ArgList"}},@{$arguments});
|
---|
89 | push(@{$hashArgOptLists->{"OptList"}},$options);
|
---|
90 |
|
---|
91 | my $self = new BasePlugin($pluginlist, $inputargs, $hashArgOptLists);
|
---|
92 |
|
---|
93 | # Check that ffmpeg is installed and available on the path (except for Windows 95/98)
|
---|
94 | # This test is "inherited" from ImagePlugin where ImageMagick support
|
---|
95 | # for building cannot be used on these two versions of Windows as they
|
---|
96 | # do not have enough flexablity in the use of stdout and stderr to
|
---|
97 | # support how our code works. It seems reasonable to assume the
|
---|
98 | # same is true for MultimediaPlugin work using ffmpeg.
|
---|
99 |
|
---|
100 | if (($ENV{'GSDLOS'} ne "windows" || Win32::IsWinNT())) {
|
---|
101 |
|
---|
102 | my $result = `ffmpeg -h 2>&1`;
|
---|
103 |
|
---|
104 | if (!defined $result || $result !~ m/^FFmpeg version/m) {
|
---|
105 | $self->{'ffmpeg_installed'} = 0;
|
---|
106 | if (defined $result) {
|
---|
107 | print STDERR $result;
|
---|
108 | }
|
---|
109 | else {
|
---|
110 | print STDERR "Unable to find ffmpeg\n";
|
---|
111 | }
|
---|
112 | }
|
---|
113 | else {
|
---|
114 | $self->{'ffmpeg_installed'} = 1;
|
---|
115 | }
|
---|
116 |
|
---|
117 | }
|
---|
118 |
|
---|
119 | return bless $self, $class;
|
---|
120 | }
|
---|
121 |
|
---|
122 |
|
---|
123 |
|
---|
124 | sub begin {
|
---|
125 | my $self = shift (@_);
|
---|
126 | my ($pluginfo, $base_dir, $processor, $maxdocs) = @_;
|
---|
127 |
|
---|
128 | $self->SUPER::begin(@_);
|
---|
129 |
|
---|
130 | $self->{'base_dir'} = $base_dir;
|
---|
131 | }
|
---|
132 |
|
---|
133 |
|
---|
134 | sub init {
|
---|
135 | my $self = shift (@_);
|
---|
136 | my ($verbosity, $outhandle, $failhandle) = @_;
|
---|
137 |
|
---|
138 | $self->SUPER::init(@_);
|
---|
139 | }
|
---|
140 |
|
---|
141 | # Want to hash on doc.xml rather than original file which in the case of
|
---|
142 | # audio and video can be HUGE
|
---|
143 |
|
---|
144 | sub get_oid_hash_type {
|
---|
145 |
|
---|
146 | my $self = shift (@_);
|
---|
147 |
|
---|
148 | return "hash_on_ga_xml";
|
---|
149 | }
|
---|
150 |
|
---|
151 |
|
---|
152 |
|
---|
153 | # Create the keyframes, thumbnail and screenview images, and discover
|
---|
154 | # the Video's size, width, and height using the ffmpeg utility.
|
---|
155 |
|
---|
156 | sub run_convert {
|
---|
157 | my $self = shift (@_);
|
---|
158 |
|
---|
159 | die "$self The inheriting class must implement run_convert method";
|
---|
160 | }
|
---|
161 |
|
---|
162 |
|
---|
163 | sub read_into_doc_obj {
|
---|
164 | my $self = shift (@_);
|
---|
165 | my ($pluginfo, $base_dir, $file, $block_hash, $metadata, $processor, $maxdocs, $total_count, $gli) = @_;
|
---|
166 |
|
---|
167 | my $outhandle = $self->{'outhandle'};
|
---|
168 |
|
---|
169 | # should we move this to read? What about secondary plugins?
|
---|
170 | print STDERR "<Processing n='$file' p='$self->{'plugin_type'}'>\n" if ($gli);
|
---|
171 | print $outhandle "$self->{'plugin_type'} processing $file\n"
|
---|
172 | if $self->{'verbosity'} > 1;
|
---|
173 |
|
---|
174 | my ($filename_full_path, $filename_no_path) = &util::get_full_filenames($base_dir, $file);
|
---|
175 |
|
---|
176 | # create a new document
|
---|
177 | my $doc_obj = new doc ($filename_full_path, "indexed_doc", $self->{'file_rename_method'});
|
---|
178 |
|
---|
179 |
|
---|
180 | my $top_section = $doc_obj->get_top_section();
|
---|
181 |
|
---|
182 |
|
---|
183 | $doc_obj->add_utf8_metadata($top_section, "Plugin", "$self->{'plugin_type'}");
|
---|
184 | $doc_obj->add_utf8_metadata($top_section, "FileSize", (-s $filename_full_path));
|
---|
185 |
|
---|
186 | # sets the UTF8 filename (Source) for display and sets the url ref to URL encoded version
|
---|
187 | # of the UTF8 filename (SourceFile) for generated files
|
---|
188 | $self->set_Source_metadata($doc_obj, $filename_no_path);
|
---|
189 |
|
---|
190 |
|
---|
191 | # plugin specific stuff - what args do we need here??
|
---|
192 | unless (defined ($self->process($pluginfo, $base_dir, $file, $metadata, $doc_obj, $gli))) {
|
---|
193 | print STDERR "<ProcessingError n='$file'>\n" if ($gli);
|
---|
194 | return (-1,undef);
|
---|
195 | }
|
---|
196 |
|
---|
197 | # include any metadata passed in from previous plugins
|
---|
198 | # note that this metadata is associated with the top level section
|
---|
199 | my $section = $doc_obj->get_top_section();
|
---|
200 | # can we merge these two methods??
|
---|
201 | $self->add_associated_files($doc_obj, $filename_full_path);
|
---|
202 | $self->extra_metadata ($doc_obj, $section, $metadata);
|
---|
203 | $self->auto_extract_metadata($doc_obj);
|
---|
204 |
|
---|
205 | # if we haven't found any Title so far, assign one
|
---|
206 | # this was shifted to here from inside read()
|
---|
207 | $self->title_fallback($doc_obj,$section,$filename_no_path);
|
---|
208 |
|
---|
209 | $self->add_OID($doc_obj);
|
---|
210 |
|
---|
211 | $self->post_process_doc_obj($pluginfo, $base_dir, $file, $metadata, $doc_obj, $gli);
|
---|
212 |
|
---|
213 | return (1,$doc_obj);
|
---|
214 | }
|
---|
215 |
|
---|
216 | sub add_dummy_text {
|
---|
217 | my $self = shift(@_);
|
---|
218 | my ($doc_obj, $section) = @_;
|
---|
219 |
|
---|
220 | # add NoText metadata so we can hide this dummy text in format statements
|
---|
221 | $doc_obj->add_metadata($section, "NoText", "1");
|
---|
222 | $doc_obj->add_text($section, &gsprintf::lookup_string("{BasePlugin.dummy_text}",1));
|
---|
223 |
|
---|
224 | }
|
---|
225 |
|
---|
226 |
|
---|
227 |
|
---|
228 |
|
---|
229 | # do plugin specific processing of doc_obj
|
---|
230 | sub process {
|
---|
231 | my $self = shift (@_);
|
---|
232 | # options??
|
---|
233 | my ($pluginfo, $base_dir, $file, $metadata, $doc_obj, $gli) = @_;
|
---|
234 |
|
---|
235 | my $outhandle = $self->{'outhandle'};
|
---|
236 |
|
---|
237 | my ($filename_full_path, $filename_no_path) = &util::get_full_filenames($base_dir, $file);
|
---|
238 |
|
---|
239 |
|
---|
240 | if ($self->{'ffmpeg_installed'}) {
|
---|
241 | my $utf8_filename_no_path = $self->filepath_to_utf8($filename_no_path);
|
---|
242 | my $url_encoded_filename = &util::rename_file($utf8_filename_no_path, $self->{'file_rename_method'});
|
---|
243 |
|
---|
244 |
|
---|
245 | #run convert to get the thumbnail and extract size and type info
|
---|
246 | my $result = $self->run_convert($base_dir, $filename_full_path,
|
---|
247 | $url_encoded_filename, $doc_obj);
|
---|
248 |
|
---|
249 | if (!defined $result) {
|
---|
250 | if ($gli) {
|
---|
251 | print STDERR "<ProcessingError n='$file'>\n";
|
---|
252 | }
|
---|
253 | print $outhandle "MultimediaPlugin: couldn't process \"$filename_full_path\"\n";
|
---|
254 | return (-1,undef); # error during processing
|
---|
255 | }
|
---|
256 | }
|
---|
257 | else {
|
---|
258 | if ($gli) {
|
---|
259 | &gsprintf(STDERR, "<Warning p='MultimediaPlugin' r='{MultimediaConverter.noconversionavailable}: {MultimediaConverter.".$self->{'no_multimedia_conversion_reason'}."}'>");
|
---|
260 | }
|
---|
261 | # all we do is add the original video file as an associated file, and set up srclink etc
|
---|
262 | my $assoc_file = $doc_obj->get_assocfile_from_sourcefile();
|
---|
263 | my $section = $doc_obj->get_top_section();
|
---|
264 |
|
---|
265 | $doc_obj->associate_file($filename_full_path, $assoc_file, "", $section);
|
---|
266 |
|
---|
267 | $doc_obj->add_metadata ($section, "srclink", "<a href=\"_httpprefix_/collect/[collection]/index/assoc/[assocfilepath]/[SourceFile]\">");
|
---|
268 | $doc_obj->add_metadata ($section, "/srclink", "</a>");
|
---|
269 | $doc_obj->add_metadata ($section, "srcicon", "<img src=\"_httpprefix_/collect/[collection]/index/assoc/[assocfilepath]/[SourceFile]\" width=\"100\">");
|
---|
270 |
|
---|
271 | }
|
---|
272 | #we have no text - adds dummy text and NoText metadata
|
---|
273 | $self->add_dummy_text($doc_obj, $doc_obj->get_top_section());
|
---|
274 |
|
---|
275 | return 1;
|
---|
276 |
|
---|
277 | }
|
---|
278 |
|
---|
279 |
|
---|
280 |
|
---|
281 | 1;
|
---|
282 |
|
---|
283 |
|
---|
284 |
|
---|
285 |
|
---|
286 |
|
---|
287 |
|
---|
288 |
|
---|
289 |
|
---|
290 |
|
---|
291 |
|
---|
292 |
|
---|