Index: trunk/extensions/TimedMediaHandler/TimedMediaTransformOutput.php |
— | — | @@ -186,7 +186,7 @@ |
187 | 187 | $this->textTracks[] = array( |
188 | 188 | 'kind' => 'subtitles', |
189 | 189 | 'data-mwtitle' => $subTitle->getNsText() . ':' . $subTitle->getDBkey(), |
190 | | - 'type' => 'text/mw-srt', |
| 190 | + 'type' => 'text/x-srt', |
191 | 191 | // TODO Should add a special entry point and output proper WebVTT format: |
192 | 192 | // http://www.whatwg.org/specs/web-apps/current-work/webvtt.html |
193 | 193 | 'src' => $subTitle->getFullURL( array( |
Index: trunk/extensions/TimedMediaHandler/WebVideoTranscode/WebVideoTranscodeJob.php |
— | — | @@ -187,30 +187,17 @@ |
188 | 188 | // Set the codec: |
189 | 189 | $cmd.= " -vcodec libvpx"; |
190 | 190 | |
191 | | - // Check for aspect ratio |
| 191 | + // Check for aspect ratio ( we don't do anything with this right now) |
192 | 192 | if ( isset( $options['aspect'] ) ) { |
193 | 193 | $aspectRatio = $options['aspect']; |
194 | 194 | } else { |
195 | 195 | $aspectRatio = $file->getWidth() . ':' . $file->getHeight(); |
196 | | - } |
197 | | - $dar = explode(':', $aspectRatio); |
198 | | - $dar = intval( $dar[0] ) / intval( $dar[1] ); |
199 | | - |
| 196 | + } |
200 | 197 | // Check maxSize |
201 | 198 | if (isset( $options['maxSize'] ) && intval( $options['maxSize'] ) > 0) { |
202 | | - // Check if source is smaller than maxSize |
203 | | - if( !WebVideoTranscode::isTargetLargerThanFile( $options['maxSize'], $file ) ){ |
204 | | - $sourceWidth = $file->getWidth(); |
205 | | - $sourceHeight = $file->getHeight(); |
206 | | - if ($sourceWidth > $options['maxSize'] ) { |
207 | | - $width = intval( $options['maxSize'] ); |
208 | | - $height = intval( $width / $dar); |
209 | | - } else { |
210 | | - $height = intval( $options['maxSize'] ); |
211 | | - $width = intval( $height * $dar); |
212 | | - } |
213 | | - $cmd.= ' -s ' . intval( $width ) . 'x' . intval( $height ); |
214 | | - } |
| 199 | + // Get size transform ( if maxSize is > file, file size is used: |
| 200 | + list( $width, $height ) = WebVideoTranscode::getMaxSizeTransform( $file, $options['maxSize'] ) |
| 201 | + $cmd.= ' -s ' . intval( $width ) . 'x' . intval( $height ); |
215 | 202 | } else if ( |
216 | 203 | (isset( $options['width'] ) && $options['width'] > 0 ) |
217 | 204 | && |
Index: trunk/extensions/TimedMediaHandler/WebVideoTranscode/WebVideoTranscode.php |
— | — | @@ -151,7 +151,8 @@ |
152 | 152 | $wgLang->formatNum( $file->getHeight() ), |
153 | 153 | $wgLang->formatBitrate( $file->getHandler()->getBitrate( $file ) ) |
154 | 154 | ), |
155 | | - 'data-shorttitle' => wfMsg('timedmedia-source-file') |
| 155 | + 'data-shorttitle' => wfMsg('timedmedia-source-file'), |
| 156 | + 'data-size' => $file->getWidth() . 'x' . $file->getHeight() |
156 | 157 | // TODO add some title and data about the file |
157 | 158 | ); |
158 | 159 | |
— | — | @@ -180,7 +181,7 @@ |
181 | 182 | $codec = self::$derivativeSettings[$transcodeKey]['codec']; |
182 | 183 | // Check if we should add derivative to job queue |
183 | 184 | // Skip if we have both an Ogg & WebM and if target encode larger than source |
184 | | - if( self::isTargetLargerThanFile( self::$derivativeSettings[$transcodeKey]['maxSize'], $file) ){ |
| 185 | + if( self::isTargetLargerThanFile( $file, self::$derivativeSettings[$transcodeKey]['maxSize']) ){ |
185 | 186 | continue; |
186 | 187 | } |
187 | 188 | // if we are checking for this derivative, update codec flags: |
— | — | @@ -221,11 +222,18 @@ |
222 | 223 | $thumbUrl = $file->getThumbUrl( $thumbName ); |
223 | 224 | $thumbUrlDir = dirname( $thumbUrl ); |
224 | 225 | |
| 226 | + // if the source size is < $transcodeKey assume source size: |
225 | 227 | if( is_file( $derivativeFile ) ){ |
226 | 228 | $sources[] = array( |
227 | 229 | 'src' => $thumbUrlDir . '/' .$file->getName() . '.' . $transcodeKey, |
228 | 230 | 'title' => wfMsg('timedmedia-derivative-desc-' . $transcodeKey ), |
229 | | - 'data-shorttitle' => wfMsg('timedmedia-derivative-' . $transcodeKey) |
| 231 | + 'data-shorttitle' => wfMsg('timedmedia-derivative-' . $transcodeKey), |
| 232 | + 'data-size' => implode( 'x', |
| 233 | + WebVideoTranscode::getMaxSizeTransform( |
| 234 | + $file, |
| 235 | + self::$derivativeSettings[$transcodeKey]['maxSize'] |
| 236 | + ) |
| 237 | + ) |
230 | 238 | ); |
231 | 239 | } else { |
232 | 240 | self::updateJobQueue($file, $transcodeKey); |
— | — | @@ -258,13 +266,41 @@ |
259 | 267 | } |
260 | 268 | } |
261 | 269 | } |
| 270 | + |
262 | 271 | /** |
| 272 | + * Transforms the size per a given "maxSize" |
| 273 | + * if maxSize is > file, file size is used |
| 274 | + */ |
| 275 | + public static function getMaxSizeTransform( &$file, $targetMaxSize ){ |
| 276 | + $sourceWidth = $file->getWidth(); |
| 277 | + $sourceHeight = $file->getHeight(); |
| 278 | + if( WebVideoTranscode::isTargetLargerThanFile( $file, $targetMaxSize) ){ |
| 279 | + return array( |
| 280 | + $sourceWidth, |
| 281 | + $sourceHeight |
| 282 | + ); |
| 283 | + } |
| 284 | + // Get the aspect ratio percentage |
| 285 | + $ar = intval( $sourceWidth ) / intval( $sourceHeight ); |
| 286 | + if ( $sourceWidth > $targetMaxSize ) { |
| 287 | + return array( |
| 288 | + intval( $targetMaxSize ), |
| 289 | + intval( $targetMaxSize / $ar) |
| 290 | + ); |
| 291 | + } else { |
| 292 | + return array( |
| 293 | + intval( $targetMaxSize ), |
| 294 | + intval( $targetMaxSize * $ar) |
| 295 | + ); |
| 296 | + } |
| 297 | + } |
| 298 | + /** |
263 | 299 | * Test if a given transcode target is larger than the source file |
264 | 300 | * |
265 | 301 | * @param $transcodeKey The static transcode key |
266 | 302 | * @param $file {Object} File object |
267 | 303 | */ |
268 | | - public static function isTargetLargerThanFile( $targetMaxSize, &$file){ |
| 304 | + public static function isTargetLargerThanFile( &$file, $targetMaxSize ){ |
269 | 305 | $largerSize = ( $file->getWidth() > $file->getHeight() )?$file->getWidth(): $file->getHeight(); |
270 | 306 | return ( $targetMaxSize > $largerSize ); |
271 | 307 | } |