You are here

protected function PHPVideoToolkit::_joinInput in Video 7

* This is a protected function that joins multiple input sources into one source before * the final processing takes place. All videos are temporarily converted into mpg for * joining. * * PLEASE NOTE. This process is experimental an might not work on all systems. * * @access protected *

Parameters

boolean $log:

1 call to PHPVideoToolkit::_joinInput()
PHPVideoToolkit::execute in libraries/phpvideotoolkit/phpvideotoolkit.php5.php
* Commits all the commands and executes the ffmpeg procedure. This will also attempt to validate any outputted files in order to provide * some level of stop and check system. * * @access public *

File

libraries/phpvideotoolkit/phpvideotoolkit.php5.php, line 2701

Class

PHPVideoToolkit

Code

protected function _joinInput($log) {
  die('INPUT CANNOT YET BE JOINED.');

  // ---- ffmpeg works

  /*
  mkfifo /Users/ollie/Sites/@Projects/ffmpeg/checkout/root/examples/tmp/intermediate1.mpg
  mkfifo /Users/ollie/Sites/@Projects/ffmpeg/checkout/root/examples/tmp/intermediate2.mpg
  ffmpeg -i /Users/ollie/Sites/@Projects/ffmpeg/checkout/root/examples/tmp/MOV02820.MPG -sameq -y /Users/ollie/Sites/@Projects/ffmpeg/checkout/root/examples/tmp/intermediate1.mpg < /dev/null &
  ffmpeg -i /Users/ollie/Sites/@Projects/ffmpeg/checkout/root/examples/tmp/MOV02832.MPG -sameq -y /Users/ollie/Sites/@Projects/ffmpeg/checkout/root/examples/tmp/intermediate2.mpg < /dev/null &
  cat /Users/ollie/Sites/@Projects/ffmpeg/checkout/root/examples/tmp/intermediate1.mpg /Users/ollie/Sites/@Projects/ffmpeg/checkout/root/examples/tmp/intermediate2.mpg |\
  ffmpeg -f mpeg -i - -sameq -vcodec flv -acodec mp3 -ar 22050 /Users/ollie/Sites/@Projects/ffmpeg/checkout/root/examples/tmp/output.flv
  */

  // ---- mencoder works

  /*
  PHPVIDEOTOOLKIT_MENCODER_BINARY.' -oac copy -ovc copy -idx -o '.$temp_file.' '.implode(' ', $this->_input_file);
  */

  // 			run a libmp3lame check as it require different mp3 codec
  $audio_codec = 'mp3';
  $info = $this
    ->getFFmpegInfo(true);
  if (isset($info['binary']['configuration']) === true && in_array('--enable-libmp3lame', $info['binary']['configuration']) === true) {

    // 				$audio_codec = 'liblamemp3';
    $audio_codec = 'libmp3lame';
  }

  // 			build commands
  $temp_files = array();
  $mkinfo_commands = array();
  $ffmpeg_commands = array();
  $cat_files = array();
  $unique = $this
    ->unique();
  foreach ($this->_input_file as $key => $file) {
    $unique_name = $this->_tmp_directory . $unique . '-' . $key . '-temp.mpg';
    $unique_name_escaped = escapeshellarg($unique_name);
    $logfile1 = $this->_tmp_directory . $unique . '-' . $key . '-log1.log';
    $logfile2 = $this->_tmp_directory . $unique . '-' . $key . '-log2.log';
    array_push($mkinfo_commands, array(
      'cmd' => 'mkfifo ' . $unique_name_escaped . ($log ? ' &> ' . $logfile1 : ''),
      'logfile' => $logfile1,
    ));
    array_push($ffmpeg_commands, array(
      'cmd' => $this->_ffmpeg_binary . ' -i ' . escapeshellarg($file) . ' -acodec ' . $audio_codec . ' -sameq ' . $unique_name_escaped . ' < /dev/null ' . ($log ? '&> ' . $logfile2 : '&'),
      'logfile' => $logfile2,
    ));
    array_push($cat_files, $unique_name_escaped);

    // 				array_push($this->_unlink_files, $unique_name);
    if ($log) {

      // 					array_push($this->_unlink_files, $logfile1);
      // 					array_push($this->_unlink_files, $logfile2);
    }
  }

  // 			start log
  if ($log) {
    $log_lines = array();
    array_unshift($log_lines, $this
      ->_getMessage('ffmpeg_log_separator'), $this
      ->_getMessage('ffmpeg_log_ffmpeg_join_gunk'), $this
      ->_getMessage('ffmpeg_log_separator'));
  }

  // 			mkinfo for temp files
  foreach ($mkinfo_commands as $cmd) {

    // 				exec($cmd['cmd']);
    echo $cmd['cmd'] . "\r\n";
    if ($log) {
      array_push($log_lines, '---------', trim(file_get_contents($cmd['logfile'])));
    }
  }

  // 			extract data
  foreach ($ffmpeg_commands as $cmd) {

    // 				exec($cmd['cmd']);
    echo $cmd['cmd'] . "\r\n";
    if ($log) {
      array_push($log_lines, trim(file_get_contents($cmd['logfile'])), '---------');
    }
  }

  // 			join command
  $unique = $this
    ->unique();
  $temp_join_file = $this->_tmp_directory . $unique . '-combined-joined.mpg';
  $temp_join_file_escaped = escapeshellarg($temp_join_file);
  $temp_process_file = $this->_tmp_directory . $unique . '-combined-temp.mpg';
  $temp_process_file_escaped = escapeshellarg($temp_process_file);
  $logfile = $this->_tmp_directory . $unique . '.log';

  // 			command for use with cat mkinfo files
  // 			exec('cat '.implode(' ', $cat_files).' |\
  // '.PHPVIDEOTOOLKIT_FFMPEG_BINARY.' -f mpeg -i - -sameq -vcodec mpeg4 -acodec '.$audio_codec.'  '.escapeshellarg($temp_process_file).($log ? ' &> '.$logfile : ''));
  echo 'cat ' . implode(' ', $cat_files) . ' |\\
' . $this->_ffmpeg_binary . ' -f mpeg -i - -sameq -vcodec mpeg4 -acodec ' . $audio_codec . ' ' . escapeshellarg($temp_process_file) . ($log ? ' &> ' . $logfile : '') . "\r\n";

  // 			echo('cat '.implode(' ', $cat_files).' > '.$temp_join_file_escaped.'
  // '.PHPVIDEOTOOLKIT_FFMPEG_BINARY.' -i '.$temp_join_file_escaped.' -sameq -vcodec mpeg4 -acodec '.$audio_codec.' '.$temp_process_file_escaped.($log ? ' &> '.$logfile : ''));
  // 			exec('cat '.implode(' ', $cat_files).' > '.$temp_join_file_escaped.'
  // '.PHPVIDEOTOOLKIT_FFMPEG_BINARY.' -i '.$temp_join_file_escaped.' -sameq -vcodec mpeg4 -acodec '.$audio_codec.' '.$temp_process_file_escaped.($log ? ' &> '.$logfile : ''));
  if ($log) {
    array_push($log_lines, trim(file_get_contents($logfile)));
    array_push($this->_unlink_files, $logfile);
    $this
      ->_addToLog($log_lines, 'a+');

    // 				print_r($log_lines);
  }

  //			create a temp dir in the temp dir
  // 			$temp_file = $this->_tmp_directory.$this->unique().'.'.array_pop(explode('.', $this->_process_address));
  // 			print_r($temp_file);
  $this
    ->addCommand('-i', $temp_process_file);

  // 	array_push($this->_unlink_files, $temp_process_file);
  exit;
}