Changeset 25842
- Timestamp:
- 2012-06-28T10:41:32+12:00 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
gs2-extensions/video-and-audio/trunk/src/perllib/plugins/SimpleVideoPlugin.pm
r25780 r25842 75 75 'list' => [{'name' => "true", 'desc' => "{common.true}"}, 76 76 {'name' => "false", 'desc' => "{common.false}"}], 77 'deft' => " false",78 'reqd' => "no" } 77 'deft' => "true", 78 'reqd' => "no" }, 79 79 { 'name' => "isCluster", 80 80 'desc' => "Will the import be run on a cluster (multiple computers) or not (single computer - possibly multiple processors)", … … 83 83 {'name' => "false", 'desc' => "{common.false}"}], 84 84 'deft' => "false", 85 'reqd' => "no" }, 86 { 'name' => "separateIO", 87 'desc' => "copy and process the file locally (good for segregating IO cost)", 88 'type' => "enum", 89 'list' => [{'name' => "true", 'desc' => "{common.true}"}, 90 {'name' => "false", 'desc' => "{common.false}"}], 91 'deft' => "false", 85 92 'reqd' => "no" } 86 93 ]; … … 120 127 my ($pluginfo, $base_dir, $file, $metadata, $doc_obj, $gli) = @_; 121 128 122 my $ivideo_path = &util::filename_cat($base_dir, $file); 129 print STDERR "[A:" . time() . "] SimpleVideoPlugin processing: " . $file . "\n"; 130 131 # - I have to add some text (yay, back to needing dummy text) otherwise the 132 # DocumentText formatting is ignored (?!?) 123 133 my $topsection = $doc_obj->get_top_section(); 134 $doc_obj->add_utf8_text($topsection, "This is dummy text"); 135 124 136 125 137 $file =~ /[\/]?(.+)\.(?:ts)$/; 126 138 my $filename = $1; 127 $filename =~ /(\d\d\d\d)-(\d\d)-(\d\d)/; 128 my $date = $1 . $2 . $3; 129 $filename =~ s/[^a-z0-9]+/_/ig; 130 $filename =~ s/^_+|_+$//g; 131 132 $doc_obj->add_utf8_metadata($topsection,"Date",$date); 133 134 my $logs_dir = &util::filename_cat($ENV{'GSDLCOLLECTDIR'}, "logs"); 139 140 141 # Optional date metadata (available on raw ReplayMe recordings) 142 if ($filename =~ /(\d\d\d\d)-(\d\d)-(\d\d)/) 143 { 144 my $date = $1 . $2 . $3; 145 $filename =~ s/[^a-z0-9]+/_/ig; 146 $filename =~ s/^_+|_+$//g; 147 $doc_obj->add_utf8_metadata($topsection,"Date",$date); 148 } 149 150 my $process_dir = $ENV{'GSDLCOLLECTDIR'}; 151 # If we are in a cluster, then we don't want to be writing all the logs 152 # etc to the shared file system. Instead, we write to the tmp drive 153 my $separate_io = $self->{'separateIO'}; 154 if ($separate_io) 155 { 156 $process_dir = &util::filename_cat('/tmp', 'gsimport-' . $filename); 157 if (!-d $process_dir) 158 { 159 mkdir($process_dir, 0775); 160 } 161 } 162 my $logs_dir = &util::filename_cat($process_dir, "logs"); 135 163 if (!-d $logs_dir) 136 164 { … … 139 167 my $convert_log_path = &util::filename_cat($logs_dir, 'convert-' . $filename . '.log'); 140 168 my $pass_log_path = &util::filename_cat($logs_dir, 'convert-' . $filename . '-pass'); 141 my $tmp_dir = &util::filename_cat($ ENV{'GSDLCOLLECTDIR'}, "cached");169 my $tmp_dir = &util::filename_cat($process_dir, "cached"); 142 170 if (!-d $tmp_dir) 143 171 { … … 150 178 } 151 179 180 # If we are separating IO, then we also start by copying the file to 181 # the process directory (local tmp) as well 182 my $ivideo_path = &util::filename_cat($base_dir, $file); 183 if ($separate_io) 184 { 185 print STDERR "[B1:" . time() . "] Creating local copy of file\n"; 186 my $local_ivideo_path = &util::filename_cat($process_dir, $file); 187 my $copy_cmd = 'cp "' . $ivideo_path . '" "' . $local_ivideo_path . '"'; 188 `$copy_cmd`; 189 $ivideo_path = $local_ivideo_path; 190 print STDERR "[B2:" . time() . "] Complete\n"; 191 } 192 152 193 # 1. Use MediaInfo to extract important metadata 194 print STDERR "[C1:" . time() . "] Extracting metadata\n"; 153 195 print " - Extracting metadata using MediaInfo\n"; 154 196 my $mi_metadata = $self->getMetadata($ivideo_path); … … 158 200 if (defined $mi_metadata->{'Video'}->{'Format_Info'} && defined $mi_metadata->{'Video'}->{'Format'}) 159 201 { 160 $doc_obj->add_utf8_metadata($topsection,"VideoFormat",$mi_metadata->{'Video'}->{'Format_Info'} . ' (' . $m etadata->{'Video'}->{'Format'} . ')');202 $doc_obj->add_utf8_metadata($topsection,"VideoFormat",$mi_metadata->{'Video'}->{'Format_Info'} . ' (' . $mi_metadata->{'Video'}->{'Format'} . ')'); 161 203 } 162 204 if (defined $mi_metadata->{'Audio'}->{'Format_Info'} && defined $mi_metadata->{'Audio'}->{'Format'}) 163 205 { 164 $doc_obj->add_utf8_metadata($topsection,"AudioFormat",$mi_metadata->{'Audio'}->{'Format_Info'} . ' (' . $m etadata->{'Audio'}->{'Format'} . ')');206 $doc_obj->add_utf8_metadata($topsection,"AudioFormat",$mi_metadata->{'Audio'}->{'Format_Info'} . ' (' . $mi_metadata->{'Audio'}->{'Format'} . ')'); 165 207 } 166 208 $doc_obj->add_utf8_metadata($topsection,"Width",$mi_metadata->{'Video'}->{'Width'}); 167 209 $doc_obj->add_utf8_metadata($topsection,"Height",$mi_metadata->{'Video'}->{'Height'}); 210 print STDERR "[C2:" . time() . "] Complete\n"; 168 211 169 212 # 2. Convert into FLV, reprocess to make seekable, and associate 170 213 # - generate a path for our temporary converted video file 214 print STDERR "[D1:" . time() . "] Converting video to streamble format\n"; 171 215 my $ovideo_path = &util::filename_cat($tmp_dir, 'gsv.mp4'); 172 173 216 if (-f $ovideo_path) 174 217 { … … 209 252 if ($is_parallel && !$is_cluster) 210 253 { 211 $mencoder_options = ':threads=1';254 $mencoder_options .= ':threads=1'; 212 255 } 213 256 my $cmd = 'HandBrakeCLI -i "' . $ivideo_path . '" -t 1 -c 1 -f mp4 -O -o "' . $ovideo_path . '" ' . $video_processing_parameters . ' -e x264 -b ' . $streaming_HQ_VideoBitrate . ' -a 1 -E faac -6 dpl2 -R Auto -B ' . $streaming_HQ_AudioBitrate . ' -D 0.0 -x ' . $mencoder_options . ' > "' . $convert_log_path . '" 2>&1'; … … 219 262 die("Fatal Error! Failed to convert video: " . $ovideo_path . "\nReason:" . $! . "\n"); 220 263 } 221 # - associate222 $doc_obj->associate_file($ovideo_path,'gsv.mp4','video/mp4',$topsection); 223 224 # 3. Extract keyframes using hive, and associate264 print STDERR "[D2:" . time() . "] Complete\n"; 265 266 # 3. Extract keyframes using hive 267 print STDERR "[E1:" . time() . "] Extract keyframes\n"; 225 268 my $oshots_path = &util::filename_cat($tmp_dir, 'shots.xml'); 226 269 if (-f $oshots_path) … … 239 282 die("Fatal Error! Failed to extract keyframe images: " . $oshots_path . "\nReason:" . $! . "\n"); 240 283 } 284 print STDERR "[E2:" . time() . "] Complete\n"; 285 286 287 # 4. Associate files (copies back to shared space if IO separated) 288 print STDERR "[F1:" . time() . "] Associate derived files to doc_obj\n"; 289 # - associate streamable video 290 $doc_obj->associate_file($ovideo_path,'gsv.mp4','video/mp4',$topsection); 241 291 # - associate all of the JPGs found in the temp directory 242 292 opendir(my $dh, $tmp_dir); … … 258 308 } 259 309 } 260 261 # - I have to add some text (yay, back to needing dummy text) otherwise the 262 # DocumentText formatting is ignored (?!?) 263 $doc_obj->add_utf8_text($topsection, "This is dummy text"); 264 265 # 4. Done! Cleanup. 266 310 print STDERR "[F2:" . time() . "] Complete\n"; 311 312 # 5. Done! Cleanup. 313 print STDERR "[G:" . time() . "] SimpleVideoPlugin: Complete!\n"; 267 314 return 1; 268 315 } … … 272 319 my ($self, $ivideo_path) = @_; 273 320 my $cmd = 'mediainfo --Output=XML "' . $ivideo_path . '" 2>&1'; 274 ###print "Cmd: " . $cmd 1. "\n";321 ###print "Cmd: " . $cmd . "\n"; 275 322 my $metadata_xml = `$cmd`; 276 323 my @lines = split(/\r?\n/, $metadata_xml); … … 279 326 foreach my $line (@lines) 280 327 { 281 328 if ($line =~ /<track type="(.+)">/) 282 329 { 283 330 $metadata_type = $1;
Note:
See TracChangeset
for help on using the changeset viewer.