Skip to content
Permalink
Browse files

Merge pull request #598 from tarasfrompir/patch-2

Добавлена функция получения данных о медиа файле
  • Loading branch information...
sergejey committed Aug 16, 2019
2 parents 135c1bc + bfbbc1a commit 62a09ebbf9391eee1c6d136e895d7fd2999873d5
Showing with 49 additions and 0 deletions.
  1. +49 −0 lib/common.class.php
@@ -1328,3 +1328,52 @@ function logAction($action_type,$details='') {
SQLInsert('actions_log',$rec);
}
function get_media_info($file)
{
if (!defined('PATH_TO_FFMPEG')) {
if (IsWindowsOS()) {
define("PATH_TO_FFMPEG", SERVER_ROOT . '/apps/ffmpeg/ffmpeg.exe');
} else {
define("PATH_TO_FFMPEG", 'ffmpeg');
}
}
$data = shell_exec(PATH_TO_FFMPEG . " -i " . $file . " 2>&1");
//DebMes ($data);
if (preg_match("/: Invalid /", $data)) {
return false;
}
//get duration
preg_match("/Duration: (.{2}):(.{2}):(.{2})/", $data, $duration);
if (!isset($duration[1])) {
return false;
}
$hours = $duration[1];
$minutes = $duration[2];
$seconds = $duration[3]+1;
$out['duration'] = $seconds + ($minutes * 60) + ($hours * 60 * 60);
// get all info about codec
preg_match("/Audio: (.+), (.\d+) Hz, (.\w+), (.+), (.\d+) kb/", $data, $format);
if ($format) {
$out['Audio_format'] = $format[1];
$out['Audio_sample_rate'] = $format[2];
$out['Audio_type'] = $format[3];
$out['Audio_codec'] = $format[4];
$out['Audio_bitrate'] = $format[5];
if ($out['Audio_type'] == 'mono' ) {
$out['Audio_chanel'] = 1;
} else {
$out['Audio_chanel'] = 2;
}
}
preg_match("/Video: (.+),\s(.\d+x.\d+) (.+), (.+), (.+), (.+), (.+), (.+) /", $data, $formatv);
if ($formatv) {
$out['Video_format'] = $formatv[1];
$out['Video_size'] = $formatv[2];
$out['Video_bitrate'] = str_ireplace("kb/s", "", $formatv[4]);
$out['Video_fps'] = $formatv[5];
}
return $out;
}

0 comments on commit 62a09eb

Please sign in to comment.
You can’t perform that action at this time.