You are here

function audiofield_ffprobe_analyze in AudioField 7

FFProbe analyze.

1 call to audiofield_ffprobe_analyze()
audiofield_details_formatter in ./audiofield.module
Get details formater.

File

./audiofield.module, line 83
Audio Field module for displaying audio files as usable players.

Code

function audiofield_ffprobe_analyze($audio_path) {
  $audiofield_detail = variable_get('audiofield_detail');
  if (empty($audiofield_detail['ffprobe_path'])) {
    return FALSE;
  }
  $file_path = drupal_realpath($audio_path);
  $command = $audiofield_detail['ffprobe_path'] . 'ffprobe -v quiet -print_format json -show_format -show_streams "' . $file_path . '"';
  exec($command, $output, $result);
  if ($result == 0) {
    $array = json_decode(implode("\n", $output), TRUE);
    if (isset($array['streams'])) {

      // Find first audio stream.
      foreach ($array['streams'] as $s) {
        if (isset($s['codec_type']) && $s['codec_type'] == 'audio') {
          $array['_audio'] = $s;
          break;
        }
      }
    }
    return $array;
  }
  return FALSE;
}