r82407 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r82406‎ | r82407 | r82408 >
Date:16:40, 18 February 2011
Author:dale
Status:deferred
Tags:
Comment:
fixed aspect ratio data sent to source attributes
Modified paths:
  • /trunk/extensions/TimedMediaHandler/TimedMediaTransformOutput.php (modified) (history)
  • /trunk/extensions/TimedMediaHandler/WebVideoTranscode/WebVideoTranscode.php (modified) (history)
  • /trunk/extensions/TimedMediaHandler/WebVideoTranscode/WebVideoTranscodeJob.php (modified) (history)

Diff [purge]

Index: trunk/extensions/TimedMediaHandler/TimedMediaTransformOutput.php
@@ -186,7 +186,7 @@
187187 $this->textTracks[] = array(
188188 'kind' => 'subtitles',
189189 'data-mwtitle' => $subTitle->getNsText() . ':' . $subTitle->getDBkey(),
190 - 'type' => 'text/mw-srt',
 190+ 'type' => 'text/x-srt',
191191 // TODO Should add a special entry point and output proper WebVTT format:
192192 // http://www.whatwg.org/specs/web-apps/current-work/webvtt.html
193193 'src' => $subTitle->getFullURL( array(
Index: trunk/extensions/TimedMediaHandler/WebVideoTranscode/WebVideoTranscodeJob.php
@@ -187,30 +187,17 @@
188188 // Set the codec:
189189 $cmd.= " -vcodec libvpx";
190190
191 - // Check for aspect ratio
 191+ // Check for aspect ratio ( we don't do anything with this right now)
192192 if ( isset( $options['aspect'] ) ) {
193193 $aspectRatio = $options['aspect'];
194194 } else {
195195 $aspectRatio = $file->getWidth() . ':' . $file->getHeight();
196 - }
197 - $dar = explode(':', $aspectRatio);
198 - $dar = intval( $dar[0] ) / intval( $dar[1] );
199 -
 196+ }
200197 // Check maxSize
201198 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 );
215202 } else if (
216203 (isset( $options['width'] ) && $options['width'] > 0 )
217204 &&
Index: trunk/extensions/TimedMediaHandler/WebVideoTranscode/WebVideoTranscode.php
@@ -151,7 +151,8 @@
152152 $wgLang->formatNum( $file->getHeight() ),
153153 $wgLang->formatBitrate( $file->getHandler()->getBitrate( $file ) )
154154 ),
155 - 'data-shorttitle' => wfMsg('timedmedia-source-file')
 155+ 'data-shorttitle' => wfMsg('timedmedia-source-file'),
 156+ 'data-size' => $file->getWidth() . 'x' . $file->getHeight()
156157 // TODO add some title and data about the file
157158 );
158159
@@ -180,7 +181,7 @@
181182 $codec = self::$derivativeSettings[$transcodeKey]['codec'];
182183 // Check if we should add derivative to job queue
183184 // 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']) ){
185186 continue;
186187 }
187188 // if we are checking for this derivative, update codec flags:
@@ -221,11 +222,18 @@
222223 $thumbUrl = $file->getThumbUrl( $thumbName );
223224 $thumbUrlDir = dirname( $thumbUrl );
224225
 226+ // if the source size is < $transcodeKey assume source size:
225227 if( is_file( $derivativeFile ) ){
226228 $sources[] = array(
227229 'src' => $thumbUrlDir . '/' .$file->getName() . '.' . $transcodeKey,
228230 '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+ )
230238 );
231239 } else {
232240 self::updateJobQueue($file, $transcodeKey);
@@ -258,13 +266,41 @@
259267 }
260268 }
261269 }
 270+
262271 /**
 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+ /**
263299 * Test if a given transcode target is larger than the source file
264300 *
265301 * @param $transcodeKey The static transcode key
266302 * @param $file {Object} File object
267303 */
268 - public static function isTargetLargerThanFile( $targetMaxSize, &$file){
 304+ public static function isTargetLargerThanFile( &$file, $targetMaxSize ){
269305 $largerSize = ( $file->getWidth() > $file->getHeight() )?$file->getWidth(): $file->getHeight();
270306 return ( $targetMaxSize > $largerSize );
271307 }

Status & tagging log