Ejemplo n.º 1
0
function cache_url_wav($vid_url, $dir_path, $switches = array(), $ffmpeg = '')
{
    $result = FALSE;
    $vid_file_path = cache_url($vid_url, $dir_path);
    if ($vid_file_path) {
        $result = cache_file_wav($vid_file_path, $switches, $ffmpeg);
    }
    return $result;
}
Ejemplo n.º 2
0
 function __buildAudio()
 {
     $result = FALSE;
     $c = 0;
     $y = sizeof(array_keys($this->__mashData['cache_urls']));
     foreach ($this->__mashData['cache_urls'] as $url => $true) {
         $this->_progressStep('CacheFiles', 1 + round(20 * ($c / $y)), 'Caching Media');
         $result = cache_url($url, $this->_options['DirCache']);
         if (!$result) {
             throw new RuntimeException('Could not cache media file: ' . $url);
         }
         $file_path = $result;
         $ext = file_extension($file_path);
         switch ($ext) {
             //case 'mp3': // recent version of ecasound doesn't support seeking mp3s
             case 'wav':
             case 'aiff':
             case 'aif':
                 break;
             default:
                 // needs to be converted for ecasound
                 $cached_wav = cache_file_wav($file_path, array(), $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);
                 }
                 $file_path = $cached_wav['path'];
         }
         $this->__mashData['cache_urls'][$url] = $file_path;
         $this->_progressStep('CacheFiles', 100, 'Cached Media');
     }
     $this->_progressStep('BuildAudio', 25, 'Building Audio');
     $audio_path = $this->_buildDir . 'build/audio.wav';
     if ($this->__mashData['has_audio']) {
         $path = $this->_options['CoderBaseURL'];
         $cmd = $this->_options['PathEcasound'];
         $counter = 1;
         $last_sound = floatval(0);
         $one = floatval(1);
         foreach ($this->__mashData['clips'] as $clip) {
             if (!$clip['audio']) {
                 continue;
             }
             // make sure we've got a locally cached file for this url
             $file_path = $this->__mashData['cache_urls'][$clip['audio']];
             if (!$file_path) {
                 throw new RuntimeException('No path for audio URL: ' . $clip['audio']);
             }
             $cmd .= ' -a:' . $counter++ . ' -i ';
             if (floatgtr($clip['loops'], $one)) {
                 $cmd .= ' audioloop,';
             }
             $cmd .= "playat,{$clip['start']},select,{$clip['trimstart']},{$clip['length']},{$file_path}";
             if (floatgtr($clip['loops'], $one)) {
                 $cmd .= ' -t:' . $clip['duration'] * $clip['loops'];
             }
             $volume = $clip['volume'];
             $volume = explode(',', $volume);
             $z = sizeof($volume) / 2;
             $cmd .= ' -ea:0 -klg:1,0,100,' . $z;
             for ($i = 0; $i < $z; $i++) {
                 $p = ($i + 1) * 2;
                 $pos = floatval($volume[$p - 2]);
                 $val = floatval($volume[$p - 1]) / floatval(100);
                 if ($pos) {
                     $pos = $clip['length'] * $clip['loops'] * $pos / floatval(100);
                 }
                 $cmd .= ',' . ($clip['start'] + $pos) . ',' . $val;
             }
             $last_sound = floatmax($last_sound, $clip['start'] + $clip['length']);
         }
         // if there is space at the end, fill it with silence
         if (floatgtr($this->__mashData['duration'], $last_sound)) {
             //$this->log('duration = ' . $this->__mashData['duration'] . ' last_sound = ' . $last_sound);
             $cmd .= ' -a:' . $counter . ' -i ';
             $cmd .= 'playat,0,tone,sine,0,' . $this->__mashData['duration'];
         }
         $cmd .= ' -a:all -z:mixmode,sum';
         $cmd .= ' -o ' . $audio_path;
     }
     if ($cmd) {
         $result = $this->_shellExecute($cmd);
         if (!file_exists($audio_path)) {
             throw new RuntimeException('Could not build audio: ' . $cmd);
         }
         $result = $audio_path;
     }
     return $result;
 }
Ejemplo n.º 3
0
 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');
         }
     }
 }