add video model and controller partially implemented
[living-lab-site.git] / application / helpers / av_info_helper.php
1 <?php
2
3 /*
4  * OBSOLETE!
5  * These functions retrieve information about audio and video files.
6  * Depends on MediaInfo CLI program (http://mediainfo.sourceforge.net/)
7  * 
8  * @author Călin-Andrei Burloiu
9  */
10
11 /**
12  *
13  * @param string $params mediainfo parameters, including the input file name
14  * passed as in shell
15  * @return string mediainfo standard output
16  */
17 function exec_mediainfo($params)
18 {
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');
22
23         $r = fgets($h, 512);
24         $r = trim($r);
25         
26         if (pclose($h) > 0 || empty($r))
27                 return FALSE;
28         
29         return $r;
30 }
31
32 /**
33  * Returns duration in hours, minutes and seconds for an audio/video file.
34  *
35  * @param string $file_name 
36  * @return array an associative array with keys 'h', 'min', 's'
37  */
38 function get_av_duration($file_name)
39 {
40         $output = exec_mediainfo(
41                         '--Inform="General;%Duration/String3%" "'. $file_name. '"');
42         
43         if (!$output)
44                 return FALSE;
45         
46         $toks = explode(':', $output);
47         $res['h'] = intval($toks[0]);
48         $res['min'] = intval($toks[1]);
49         $res['s'] = floatval($toks[2]);
50         
51         return $res;
52 }
53
54 /**
55  * Returns video width size in pixels.
56  * 
57  * @param string $file_name
58  * @return int
59  */
60 function get_video_width($file_name)
61 {
62         $output = exec_mediainfo(
63                         '--Inform="Video;%Width%" "'. $file_name. '"');
64         
65         if (!$output)
66                 return FALSE;
67         
68         return intval($output);
69 }
70
71 /**
72  * Returns video height size in pixels.
73  * 
74  * @param string $file_name
75  * @return int
76  */
77 function get_video_height($file_name)
78 {
79         $output = exec_mediainfo(
80                         '--Inform="Video;%Height%" "'. $file_name. '"');
81         
82         if (!$output)
83                 return FALSE;
84         
85         return intval($output);
86 }
87
88 /**
89  * Returns Display Aspect Ration (DAR) of a video.
90  * 
91  * @param string $file_name
92  * @return string a ratio represented a two integers separated by a colon
93  */
94 function get_video_dar($file_name)
95 {
96         $output = exec_mediainfo(
97                         '--Inform="Video;%DisplayAspectRatio/String%" "'. $file_name. '"');
98         
99         if (!$output)
100                 return FALSE;
101         
102         return $output;
103 }
104
105 /* End of file av_info_helper.php */
106 /* Location: ./application/helpers/av_info_helper.php */