4 * These functions retrieve information about audio and video files.
5 * Depends on MediaInfo CLI program (http://mediainfo.sourceforge.net/)
7 * @author Călin-Andrei Burloiu
12 * @param string $params mediainfo parameters, including the input file name
14 * @return string mediainfo standard output
16 function exec_mediainfo($params)
18 // If file does not exist it exists with code 1. If file is not a valid
19 // audio/video file it exists with code 0 and outputs nothing.
20 $h = popen('mediainfo ' . $params . ' 2>&1', 'r');
25 if (pclose($h) > 0 || empty($r))
32 * Returns duration in hours, minutes and seconds for an audio/video file.
34 * @param string $file_name
35 * @return array an associative array with keys 'h', 'min', 's'
37 function get_av_duration($file_name)
39 $output = exec_mediainfo(
40 '--Inform="General;%Duration/String3%" "'. $file_name. '"');
45 $toks = explode(':', $output);
46 $res['h'] = intval($toks[0]);
47 $res['min'] = intval($toks[1]);
48 $res['s'] = floatval($toks[2]);
54 * Returns video width size in pixels.
56 * @param string $file_name
59 function get_video_width($file_name)
61 $output = exec_mediainfo(
62 '--Inform="Video;%Width%" "'. $file_name. '"');
67 return intval($output);
71 * Returns video height size in pixels.
73 * @param string $file_name
76 function get_video_height($file_name)
78 $output = exec_mediainfo(
79 '--Inform="Video;%Height%" "'. $file_name. '"');
84 return intval($output);
88 * Returns Display Aspect Ration (DAR) of a video.
90 * @param string $file_name
91 * @return string a ratio represented a two integers separated by a colon
93 function get_video_dar($file_name)
95 $output = exec_mediainfo(
96 '--Inform="Video;%DisplayAspectRatio/String%" "'. $file_name. '"');
104 /* End of file av_info_helper.php */
105 /* Location: ./application/helpers/av_info_helper.php */