Changeset 26948

Show
Ignore:
Timestamp:
26.02.2013 10:41:13 (7 years ago)
Author:
jmt12
Message:

Adding 'fixedCore' argument to allow restricting HandbrakeCLI to a single CPU (threads=1 only affects encoding). Replace all built-in perl file tests with calls to util library to allow plugin to process files in HDFS. Coincidentally HDFS *only* supported by 'separateIO' functionality.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • gs2-extensions/video-and-audio/trunk/src/perllib/plugins/SimpleVideoPlugin.pm

    r25842 r26948  
    9090                               {'name' => "false", 'desc' => "{common.false}"}], 
    9191                    'deft' => "false", 
    92                     'reqd' => "no" } 
     92                    'reqd' => "no" }, 
     93                  { 'name' => "fixedCore", 
     94                    'desc' => "Restrict the execution of Handbrake to a single core (0 = no restriction, > 0 use value-1'th core)", 
     95                    'type' => "int", 
     96                    'deft' => "0", 
     97                    'reqd' => "no" }, 
    9398                ]; 
    9499 
     
    135140 
    136141 
    137   $file =~ /[\/]?(.+)\.(?:ts)$/; 
     142  $file =~ /[\/]?([^\/]+)\.(?:ts)$/; 
    138143  my $filename = $1; 
    139  
    140144 
    141145  # Optional date metadata (available on raw ReplayMe recordings) 
     
    148152  } 
    149153 
     154  # Special Case: HDFS *only* supported by separateIO flag (you need to move 
     155  # the file out of HDFS to local filespace to allow MediaInfo and Handbrake 
     156  # to be run on it. 
     157  my $separate_io = $self->{'separateIO'}; 
     158  if (&util::isHDFS($file)) 
     159  { 
     160    $separate_io = 'true'; 
     161  } 
     162 
    150163  my $process_dir = $ENV{'GSDLCOLLECTDIR'}; 
    151164  # If we are in a cluster, then we don't want to be writing all the logs 
    152165  # etc to the shared file system. Instead, we write to the tmp drive 
    153   my $separate_io = $self->{'separateIO'}; 
    154   if ($separate_io) 
     166  if ($separate_io eq 'true') 
    155167  { 
    156168    $process_dir = &util::filename_cat('/tmp', 'gsimport-' . $filename); 
    157     if (!-d $process_dir) 
     169    if (!&util::dir_exists($process_dir)) 
    158170    { 
    159171      mkdir($process_dir, 0775); 
     
    161173  } 
    162174  my $logs_dir = &util::filename_cat($process_dir, "logs"); 
    163   if (!-d $logs_dir) 
     175  if (!&util::dir_exists($logs_dir)) 
    164176  { 
    165177    mkdir($logs_dir, 0775); 
     
    168180  my $pass_log_path = &util::filename_cat($logs_dir, 'convert-' . $filename . '-pass'); 
    169181  my $tmp_dir = &util::filename_cat($process_dir, "cached"); 
    170   if (!-d $tmp_dir) 
     182  if (!&util::dir_exists($tmp_dir)) 
    171183  { 
    172184    mkdir($tmp_dir, 0775); 
    173185  } 
    174186  $tmp_dir = &util::filename_cat($tmp_dir, $filename); 
    175   if (!-d $tmp_dir) 
     187  if (!&util::dir_exists($tmp_dir)) 
    176188  { 
    177189    mkdir($tmp_dir, 0775); 
     
    181193  # the process directory (local tmp) as well 
    182194  my $ivideo_path = &util::filename_cat($base_dir, $file); 
    183   if ($separate_io) 
     195  if ($separate_io eq 'true') 
    184196  { 
    185197    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`; 
     198    my $local_ivideo_path = &util::filename_cat($process_dir, $filename . ".ts"); 
     199    &util::cp($ivideo_path, $local_ivideo_path); 
    189200    $ivideo_path = $local_ivideo_path; 
    190201    print STDERR "[B2:" . time() . "] Complete\n"; 
     
    214225  print STDERR "[D1:" . time() . "] Converting video to streamble format\n"; 
    215226  my $ovideo_path = &util::filename_cat($tmp_dir, 'gsv.mp4'); 
    216   if (-f $ovideo_path) 
     227  if (&util::file_exists($ovideo_path)) 
    217228  { 
    218229    print " - Found existing converted video in cache\n"; 
     
    249260    # causing all other threads to wait anyway). It will interesting to test 
    250261    # whether parallel processing or serial processing (with HandBrake parallel 
    251     # processing) is faster. 
    252     if ($is_parallel && !$is_cluster) 
     262    # processing) is faster. *update* threads=1 *only* controls the encoding and 
     263    # several other parts of Handbrake can run parallel (demuxing etc). I've 
     264    # had to include a 'taskset' command to truely make Handbrake serial 
     265    if ($is_parallel eq 'true'  && $is_cluster eq 'false') 
    253266    { 
    254267      $mencoder_options .= ':threads=1'; 
    255268    } 
    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'; 
     269    # Banish HandbrakeCLI to the (fixedCore-1)'th CPU if necessary 
     270    my $cmd = ''; 
     271    if (defined $self->{'fixedCore'} && $self->{'fixedCore'} > 0) 
     272    { 
     273      $cmd .= 'taskset -c ' . ($self->{'fixedCore'} - 1) . ' '; 
     274    } 
     275    $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'; 
    257276    print "[DEBUG: " . $cmd . "]\n"; 
    258277    `$cmd`; 
    259278  } 
    260   if (!-f $ovideo_path) 
     279  if (!&util::file_exists($ovideo_path)) 
    261280  { 
    262281    die("Fatal Error! Failed to convert video: " . $ovideo_path . "\nReason:" . $! . "\n"); 
     
    267286  print STDERR "[E1:" . time() . "] Extract keyframes\n"; 
    268287  my $oshots_path = &util::filename_cat($tmp_dir, 'shots.xml'); 
    269   if (-f $oshots_path) 
     288  if (&util::file_exists($oshots_path)) 
    270289  { 
    271290    print " - Found existing keyframe images in cache\n"; 
     
    278297    `$cmd`; 
    279298  } 
    280   if (!-f $oshots_path) 
     299  if (!&util::file_exists($oshots_path)) 
    281300  { 
    282301    die("Fatal Error! Failed to extract keyframe images: " . $oshots_path . "\nReason:" . $! . "\n");