5 * These functions retrieve information about audio and video files.
6 * Depends on MediaInfo CLI program (http://mediainfo.sourceforge.net/)
8 * @author Călin-Andrei Burloiu
13 * @param string $params mediainfo parameters, including the input file name
15 * @return string mediainfo standard output
17 function exec_mediainfo($params)
19 // If file does not exist it exists with code 1. If file is not a valid
20 // audio/video file it exists with code 0 and outputs nothing.
21 $h = popen('mediainfo ' . $params . ' 2>&1', 'r');
26 if (pclose($h) > 0 || empty($r))
33 * Returns duration in hours, minutes and seconds for an audio/video file.
35 * @param string $file_name
36 * @return array an associative array with keys 'h', 'min', 's'
38 function get_av_duration($file_name)
40 $output = exec_mediainfo(
41 '--Inform="General;%Duration/String3%" "'. $file_name. '"');
46 $toks = explode(':', $output);
47 $res['h'] = intval($toks[0]);
48 $res['min'] = intval($toks[1]);
49 $res['s'] = floatval($toks[2]);
55 * Returns video width size in pixels.
57 * @param string $file_name
60 function get_video_width($file_name)
62 $output = exec_mediainfo(
63 '--Inform="Video;%Width%" "'. $file_name. '"');
68 return intval($output);
72 * Returns video height size in pixels.
74 * @param string $file_name
77 function get_video_height($file_name)
79 $output = exec_mediainfo(
80 '--Inform="Video;%Height%" "'. $file_name. '"');
85 return intval($output);
89 * Returns Display Aspect Ration (DAR) of a video.
91 * @param string $file_name
92 * @return string a ratio represented a two integers separated by a colon
94 function get_video_dar($file_name)
96 $output = exec_mediainfo(
97 '--Inform="Video;%DisplayAspectRatio/String%" "'. $file_name. '"');
105 /* End of file av_info_helper.php */
106 /* Location: ./application/helpers/av_info_helper.php */