/[drupal]/contributions/modules/transformer/transformer_video.module
ViewVC logotype

Contents of /contributions/modules/transformer/transformer_video.module

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.3 - (show annotations) (download) (as text)
Sun Jan 11 09:52:31 2009 UTC (10 months, 2 weeks ago) by dopry
Branch: MAIN
CVS Tags: HEAD
Changes since 1.2: +48 -25 lines
File MIME type: text/x-php
most recent update to transformer to support video transcoding. it's been a while since
I looked at this... but I know its functioning for some people...
1 <?php
2 /**
3 * default transformer transforms
4 */
5
6 /**
7 * return an array of transforms implemented by this module.
8 *
9 * 'basename' => array( 'title'=>'', 'mimes'=>'', 'extensions'=>array(), 'queue'=>BOOL );
10 * basename is the basename from which functions _form and _perform will be generated.
11 * title is a human readable title
12 * mimes is an array of valid mime types this transform can operate on.
13 */
14 function transformer_video_transformer() {
15 return array(
16 /*
17 'transformer_video_crop' => array(
18 'title' => t('Video Crop'),
19 ),
20 */
21 'transformer_video_scale' => array(
22 'title' => t('Video Scale'),
23 ),
24 'transformer_video_convert' => array(
25 'title' => t('Video Convert'),
26 ),
27 'transformer_video_extract' => array(
28 'title' => t('Extract Image from Video'),
29 ),
30 'transformer_video_ffmpeg_raw' => array(
31 'title' => t('Pass raw arguments into ffmpeg'),
32 ),
33 );
34 }
35
36 function transformer_video_crop_form($data) {
37 //debug_msg($transform);
38 $form = array();
39 $form['width'] = array(
40 '#type' => 'textfield',
41 '#size' => 15,'#maxlength' => 30,
42 '#title' => t('Width'),
43 '#default_value' => $data['width'],
44 );
45 $form['height'] = array(
46 '#type' => 'textfield',
47 '#title' => t('Height'),
48 '#size' => 15,'#maxlength' => 30,
49 '#default_value' => $data['height'],
50 );
51 $form['xoffset'] = array(
52 '#type' => 'textfield',
53 '#title' => t('X Offset'),
54 '#size' => 15,'#maxlength' => 30,
55 '#default_value' => $data['xoffset'],
56 );
57 $form['yoffset'] = array(
58 '#type' => 'textfield',
59 '#title' => t('Y Offset'),
60 '#size' => 15,'#maxlength' => 30,
61 '#default_value' => $data['yoffset'],
62 );
63 $form['#validate'] = array('transformer_crop_form_validate' => array());
64 return $form;
65 }
66
67 function transformer_video_crop_form_validate() {
68 }
69
70 function transformer_video_crop_perform($video, $data) {
71 return $video->crop($data['xoffset'] , $data['yoffset'], $data['width'], $data['height']);
72 }
73
74 function transformer_video_scale_form($data) {
75 $form = array();
76 $form['width'] = array(
77 '#type' => 'textfield',
78 '#size' => 15,'#maxlength' => 30,
79 '#title' => t('Width'),
80 '#default_value' => $data['width'],
81 );
82 $form['height'] = array(
83 '#type' => 'textfield',
84 '#size' => 15,'#maxlength' => 30,
85 '#title' => t('Height'),
86 '#default_value' => $data['height'],
87 );
88 $form['#validate'] = array('transformer_video_scale_form_validate' => array());
89 return $form;
90 }
91
92 function transformer_video_scale_form_validate() {
93 }
94
95 function transformer_video_scale_perform($video, $data) {
96 $video->scale($data['width'], $data['height']);
97 return TRUE;
98 }
99
100 function transformer_video_extract_form($data) {
101 $form = array();
102
103 $form['width'] = array(
104 '#type' => 'textfield',
105 '#size' => 15,'#maxlength' => 30,
106 '#title' => t('Width'),
107 '#default_value' => $data['width'],
108 );
109 $form['height'] = array(
110 '#type' => 'textfield',
111 '#size' => 15,'#maxlength' => 30,
112 '#title' => t('Height'),
113 '#default_value' => $data['height'],
114 );
115
116 $form['time'] = array(
117 '#type' => 'textfield',
118 '#title' => t('Frame Timecode'),
119 '#description' => t('Time code of the frame you wish to extract for the thumbnail. ex) 00:00:02'),
120 '#default_value' => '00:00:02',
121 );
122
123 $form['format'] = array(
124 '#type' => 'select',
125 '#title' => t('Thumbnail format'),
126 '#options' => $options,
127 '#default_value' => $configuration['thumb_format'] ? $configuration['thumb_format'] : 'jpg',
128 '#description' => t('Format for the thumbnail output'),
129 );
130
131 $form['#validate'] = array('transformer_video_extract_form_validate' => array());
132 return $form;
133 }
134
135
136
137 function transformer_video_extract_form_validate() {
138 }
139
140 function transformer_video_extract_perform($source, $destination, $data) {
141 return image_resize($source, $destination, $data['width'], $data['height']);
142 }
143
144 function transformer_video_convert_form($data) {
145 return array(
146
147 'format' => array(
148 '#type' => 'select',
149 '#title' => t('Convert to'),
150 '#options' => array(
151 'flv' => 'Flash 7 Video',
152 'mov' => 'Quicktime Mov',
153 'avi' => 'Windows AVI',
154 'mp3' => 'MP3 Audio'
155 ),
156 '#default_value' => isset($data['format']) ? $data['format'] : 'flv',
157 ),
158
159 'video' => array(
160 '#type' => 'fieldset',
161 '#title' => t('Video Options'),
162
163 // http://www.adobe.com/devnet/flash/articles/encoding_video_print.html
164 'video_frame_rate' => array(
165 '#type' => 'select',
166 '#title' => t('Video Frame Rate'),
167 '#options' => array('8' => '8fps', '12' => '12fps', '15' => '15fps', '25' => '25fps', '30' => '30fps'),
168 '#default_value' => isset($data['video']['video_frame_rate']) ? $data['video']['video_frame_rate'] : '25',
169 ),
170
171 'video_bit_rate' => array(
172 '#type' => 'select',
173 '#title' => t('Video Bit Rate'),
174 '#options' => array('68' => '68Kbps', '132' => '132Kbps', '200' => '200Kbps', '286' => '286Kbps', '336' => '336Kbps', '504' => '504Kbps', '754' => '754Kbps', '1304' => '1304Kps'),
175 '#default_value' => isset($data['video']['video_bit_rate']) ? $data['video']['video_bit_rate'] : '132k',
176 ),
177
178 ),
179
180 'audio' => array(
181 '#type' => 'fieldset',
182 '#title' => t('Audio Options'),
183
184 'audio_sample_rate' => array(
185 '#type' => 'select',
186 '#title' => t('Audio Sample Rate'),
187 '#options' => array('22050' => '22Khz', '44100' => '44.1Khz', '48000' => '48Khz'),
188 '#default_value' => isset($data['audio']['audio_sample_rate']) ? $data['audio']['audio_sample_rate'] : '22050',
189 ),
190
191 'audio_bit_rate' => array(
192 '#type' => 'select',
193 '#title' => t('Audio Bit Rate'),
194 '#options' => array('16' => '16Kbps', '32' => '32Kbps', '48' => '48Kbps', '64' => '64Kbps', '96' => '96Kbps', '128' => '128Kbps', '192' => '192Kbps'),
195 '#default_value' => isset($data['audio']['audio_bit_rate']) ? $data['audio']['audio_bit_rate'] : '64',
196 ),
197
198 'audio_channels' => array(
199 '#type' => 'select',
200 '#title' => t('Audio Channels'),
201 '#options' => array('1' => 'Mono', '2' => 'Stereo'),
202 '#default_value' => isset($data['audio']['audio_channels']) ? $data['audio']['audio_channels'] : 1,
203 ),
204
205 ),
206
207 '#validate' => array(
208 'transformer_video_convert_form_validate' => array()
209 ),
210 );
211 }
212
213 function transformer_video_convert_form_validate() {
214 }
215
216 function transformer_video_convert_perform($video, $data) {
217 // @todo: default values with ternary...
218 $video->set_video_frame_rate($data['video']['video_frame_rate']);
219 $video->set_video_bit_rate($data['video']['video_bit_rate']);
220 $video->set_audio_sample_rate($data['audio']['audio_sample_rate']);
221 $video->set_audio_bit_rate($data['audio']['audio_bit_rate']);
222 $video->set_audio_channels($data['audio']['audio_channels']);
223 $video->set_output_format($data['format']);
224 return TRUE;
225 }
226
227 function transformer_video_ffmpeg_raw_form($data) {
228 return array(
229 'arguments' => array(
230 '#type' => 'textfield',
231 '#title' => t('FFmpeg Arguments'),
232 '#description' => t('These arguments will be passed directly to ffmpeg.'),
233 '#default_value' => $data['arguments'],
234 )
235 );
236 }
237
238 function transformer_video_ffmpeg_raw_form_validate($element) {
239 }
240
241 function transformer_video_ffmpeg_raw_perform($video, $data) {
242 $video->convert($data['arguments']);
243 }

  ViewVC Help
Powered by ViewVC 1.1.2