function addMeta($path, $key, $value = '') { $result = FALSE; if ($key && $path) { $access_key_id = $this->getOption('AWSAccessKeyID'); $secret_access_key = $this->getOption('AWSSecretAccessKey'); $bucket = $this->getOption('S3Bucket'); if ($bucket && $access_key_id && $secret_access_key) { $bucket_path = $bucket . '/' . $path; $txt_mime = mime_from_extension('txt'); $a = array(); if (is_array($key)) { $a = $key; } else { $a[$key] = $value; } foreach ($a as $k => $v) { $info_file_path = meta_file_path($k, $bucket_path); $result = $info_file_path && s3_put_data($access_key_id, $secret_access_key, $info_file_path, $v, $txt_mime); if (!$result) { $this->log($info_file_path . ' ' . $access_key_id . ' ' . $secret_access_key . ' ' . $v . ' ' . $txt_mime); break; } } } } return $result; }
$renders_locally = $moviemasher_client->rendersLocally(); $path_media = $moviemasher_client->getOption('PathMedia'); if (!$path_media) { $err = 'Configuration option PathMedia required'; } } // get job status from Movie Masher Server, and check for error if (!$err) { $path_media .= authenticated_userid() . '/'; $start = empty($_REQUEST['start']) ? 0 : $_REQUEST['start']; try { $get_target = $job; if ($moviemasher_client->progressesLocally()) { $media_host = $uploads_locally ? $renders_locally ? $moviemasher_file->getOption('HostLocal') : $moviemasher_file->getOption('Host') : $moviemasher_file->getOption('HostMedia'); $get_target = 'http://' . $media_host . '/' . $path_media . $id . '/'; $get_target = meta_file_path('progress', $get_target); } $progress = $moviemasher_client->get('encode', $get_target); } catch (Exception $ex) { $err = xml_safe($ex->getMessage()); } } if (!$err) { $attrs = ''; // if job is still processing, redirect back here with same parameters if ($progress['percent'] < 100) { $progress['percent'] = max(1, $start + $progress['percent'] / 100 * (100 - $start)); $attrs = ' delay="5" url="media/php/encoding.php?job=' . $job . '&id=' . $id . '&start=' . $start . '"'; } else { if (!$moviemasher_file->uploadsLocally()) { $media_dir = 'http://' . $moviemasher_file->getOption('HostMedia') . '/';
function set_file_info($path, $key, $data = '') { $result = FALSE; if ($key && $path) { $a = array(); if (is_array($key)) { $a = $key; } else { $a[$key] = $data; } foreach ($a as $k => $v) { if ($v) { $info_file_path = meta_file_path($k, $path); $result = $info_file_path && safe_path($info_file_path) && @file_put_contents($info_file_path, $v); } if (!$result) { break; } @chmod($info_file_path, 0777); } } return $result; }
function __buildAudio($file_path) { if (!empty($this->_options['EncoderAudioExtension'])) { if (get_file_info('audio', $file_path, $this->_options['PathFFmpeg'])) { $this->_progressStep('EncodeAudio', 5, 'Encoding Audio ' . $file_path); $media_path = media_file_path($file_path); $audio_path = $media_path . 'audio.' . $this->_options['EncoderAudioExtension']; $switches = array(); if (!safe_path($audio_path)) { throw new RuntimeException('Could not create path: ' . $audio_path); } $cmd = ''; $cmd .= $this->_options['PathFFmpeg'] . ' -i '; $cmd .= $file_path; $cmd .= ' -ab ' . $this->_options['EncoderAudioBitrate'] . 'k'; $cmd .= ' -ar ' . $this->_options['EncoderAudioFrequency']; //$cmd .= ' -acodec ' . $this->_options['EncoderAudioExtension']; $cmd .= ' -vn ' . $audio_path; $response = $this->_shellExecute($cmd); if (!$response) { throw new RuntimeException('Problem with audio command: ' . $cmd); } if (!file_exists($audio_path)) { throw new RuntimeException('Could not build audio: ' . $response); } $cached_wav = cache_file_wav($file_path, $switches, $this->_options['PathFFmpeg']); if (!$cached_wav) { throw new RuntimeException('Could not determine path to audio wav file: ' . $file_path); } if (!empty($this->_options['Verbose'])) { $this->log($cached_wav['command']); } if (!$cached_wav['path']) { throw new RuntimeException('Could not build audio wav file: ' . $file_path); } $wav_file_path = $cached_wav['path']; // get a more accurate duration reading from WAV file if (!($meta_path = meta_file_path('blah', $wav_file_path))) { throw new RuntimeException('Could not determine meta path for ' . $wav_file_path); } if (!($meta_dir = dir_path($meta_path))) { throw new RuntimeException('Could not determine dir path of ' . $meta_path); } if (!($duration = get_file_info('duration', $wav_file_path, $this->_options['PathFFmpeg']))) { throw new RuntimeException('Could not determine duration of ' . $wav_file_path); } if (!set_file_info($file_path, 'duration', $duration)) { throw new RuntimeException('Could not set duration of ' . $file_path); } // make waveform graphic $this->_ignore[] = $wav_file_path; $audio_path = $media_path . 'audio.' . $this->_options['EncoderWaveformExtension']; $cmd = ''; $cmd .= $this->_options['PathWaveformGenerator'] . ' --input ' . $wav_file_path; $cmd .= ' --height 64 --width 2800'; $cmd .= ' --linecolor ' . $this->_options['EncoderWaveformForecolor']; $cmd .= ' --padding 0'; $cmd .= ' --backgroundcolor ' . $this->_options['EncoderWaveformBackcolor']; $cmd .= ' --output ' . $audio_path; $response = $this->_shellExecute($cmd); if (!file_exists($audio_path)) { throw new RuntimeException('Could not create waveform graphic: ' . $cmd); } $this->_shellExecute('rm -R ' . $meta_dir); $this->_progressStep('EncodeAudio', 100, 'Encoded Audio'); } } }