r90077 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r90076‎ | r90077 | r90078 >
Date:20:08, 14 June 2011
Author:dale
Status:deferred
Tags:
Comment:
bug 29181 add targetSize mode that more closely match their encode targets to tag names ie 640P is 640 high if the correct aspect ratio, also include fail safe for very long or very tall videos
Modified paths:
  • /trunk/extensions/TimedMediaHandler/TimedMediaHandler.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/TimedMediaHandler.php
@@ -62,7 +62,7 @@
6363 // The priority to be used with the nice transcode commands.
6464 $wgTranscodeBackgroundPriority = 19;
6565
66 -// The total amount of time a transcoding shell command can take:
 66+// The total amout of time a transcoding shell command can take:
6767 $wgTranscodeBackgroundTimeLimit = 3600 * 4;
6868
6969 // The location of ffmpeg2theora ( transcoding )
Index: trunk/extensions/TimedMediaHandler/WebVideoTranscode/WebVideoTranscodeJob.php
@@ -323,10 +323,13 @@
324324 } else {
325325 $aspectRatio = $file->getWidth() . ':' . $file->getHeight();
326326 }
327 - // Check maxSize
328 - if (isset( $options['maxSize'] ) && intval( $options['maxSize'] ) > 0) {
 327+ // First check targetSize
 328+ if( isset( $options['targetSize'] ) ){
 329+ list( $width, $height ) = WebVideoTranscode::getTargetSizeTransform( $file, $options['targetSize'] );
 330+ $cmd.= ' -s ' . intval( $width ) . 'x' . intval( $height );
 331+ } else if (isset( $options['maxSize'] ) && intval( $options['maxSize'] ) > 0) {
329332 // Get size transform ( if maxSize is > file, file size is used:
330 - list( $width, $height ) = WebVideoTranscode::getMaxSizeTransform( $file, $options['maxSize'] );
 333+ list( $width, $height ) = WebVideoTranscode::getMaxSizeTransform( $file, $options['maxSize'] );
331334 $cmd.= ' -s ' . intval( $width ) . 'x' . intval( $height );
332335 } else if (
333336 (isset( $options['width'] ) && $options['width'] > 0 )
@@ -390,6 +393,18 @@
391394
392395 // Set up the base command
393396 $cmd = wfEscapeShellArg( $wgFFmpeg2theoraLocation ) . ' ' . wfEscapeShellArg( $this->getSourceFilePath() );
 397+
 398+ $file = wfLocalFile( $this->title );
 399+
 400+ // Check special case options like targetSize
 401+ if( isset( $options['targetSize'] ) ){
 402+ list( $width, $height ) = WebVideoTranscode::getTargetSizeTransform( $file, $options['targetSize'] );
 403+ $options['width'] = $width;
 404+ $options['height'] = $height;
 405+ unset( $options['targetSize'] );
 406+ unset( $options['maxSize'] );
 407+ }
 408+
394409 // Add in the encode settings
395410 foreach( $options as $key => $val ){
396411 if( isset( self::$foggMap[$key] ) ){
Index: trunk/extensions/TimedMediaHandler/WebVideoTranscode/WebVideoTranscode.php
@@ -53,7 +53,8 @@
5454 public static $derivativeSettings = array(
5555 WebVideoTranscode::ENC_OGV_2MBS =>
5656 array(
57 - 'maxSize' => '220', // 160P or around there
 57+ 'maxSize' => '220',
 58+ 'targetSize' => '160P', // 160P
5859 'videoBitrate' => '160',
5960 'audioBitrate' => '32',
6061 'samplerate' => '22050',
@@ -67,7 +68,8 @@
6869 ),
6970 WebVideoTranscode::ENC_OGV_5MBS =>
7071 array(
71 - 'maxSize' => '480', // 360P
 72+ 'maxSize' => '480',
 73+ 'targetSize' => '360P', // 360P
7274 'videoBitrate' => '512',
7375 'audioBitrate' => '48',
7476 'noUpscaling' => 'true',
@@ -78,7 +80,8 @@
7981 ),
8082 WebVideoTranscode::ENC_OGV_9MBS =>
8183 array(
82 - 'maxSize' => '640', // 480P
 84+ 'maxSize' => '640',
 85+ 'targetSize' => '480P', // 480P
8386 'videoBitrate' => '786',
8487 'audioBitrate' => '96',
8588 'noUpscaling' => 'true',
@@ -91,6 +94,7 @@
9295 WebVideoTranscode::ENC_OGV_HQ_VBR =>
9396 array(
9497 'maxSize' => '1280', // 720P
 98+ 'targetSize' => '720P', // 480P
9599 'videoQuality' => 6,
96100 'audioQuality' => 3,
97101 'noUpscaling' => 'true',
@@ -101,7 +105,8 @@
102106 // WebM transcode:
103107 WebVideoTranscode::ENC_WEBM_5MBS =>
104108 array(
105 - 'maxSize' => '480', // 380P
 109+ 'maxSize' => '480',
 110+ 'targetSize' => '380P', // 360P
106111 'videoBitrate' => '512',
107112 'audioBitrate' => '48',
108113 'noUpscaling' => 'true',
@@ -112,7 +117,8 @@
113118 ),
114119 WebVideoTranscode::ENC_WEBM_9MBS =>
115120 array(
116 - 'maxSize' => '640', // 480P
 121+ 'maxSize' => '640',
 122+ 'targetSize' => '480P', // 480P
117123 'videoBitrate' => '786',
118124 'audioBitrate' => '96',
119125 'noUpscaling' => 'true',
@@ -123,7 +129,8 @@
124130 ),
125131 WebVideoTranscode::ENC_WEBM_HQ_VBR =>
126132 array(
127 - 'maxSize' => '1280', // 720P
 133+ 'maxSize' => '1280',
 134+ 'targetSize' => '720P', // 720P
128135 'videoQuality' => 7,
129136 'audioQuality' => 3,
130137 'noUpscaling' => 'true',
@@ -610,6 +617,48 @@
611618 }
612619 wfProfileOut( __METHOD__ );
613620 }
 621+ /**
 622+ * Target size transform slightly diffrent from "maxsize"
 623+ *
 624+ * Here we check aspect ratio to decide if we use the $target size or not.
 625+ *
 626+ * @param $file File Object the source file being transformed
 627+ * @param $targetSize String Target file size string ushualy of type '640P', '720P' etc .
 628+ */
 629+ public static function getTargetSizeTransform( &$file, $targetSize ){
 630+ // Strip the non-numeric parts of the targetSize
 631+ $targetSize = preg_replace('/\D/', '', $targetSize);
 632+ $base16n9Ratio = 16/9;
 633+ $fileRatio = $file->getWidth() / $file->getHeight();
 634+
 635+ // Check if the $file for very nonstandard aspect ratio ie "very wide" or "very tall" video:
 636+ // in this case use the max size system to avoid a huge video at low bitrates:
 637+ if( $fileRatio > 3 || $fileRatio < .25 ){
 638+ return self::getMaxSizeTransform( $file, $targetSize);
 639+ }
 640+ // make sure we don't upscale
 641+ $targetSize = ( $targetSize > $file->getHeight() )? $file->getHeight() : $targetSize;
 642+
 643+ // Check if file is narrower than 16:9 and use raw targetSize for height, true to HD name
 644+ // ie 640P is 640 pixles high.
 645+ if( $fileRatio <= $base16n9Ratio ){
 646+ $height = $targetSize;
 647+ $width = $fileRatio * $height;
 648+ } else {
 649+ // wider than 16:9 full HD width
 650+ $width = $targetSize * $base16n9Ratio;
 651+ $height = $width / $fileRatio;
 652+ }
 653+
 654+ // round width and height
 655+ $width = round( $width );
 656+ $height = round( $height );
 657+
 658+ // round to even numbers:
 659+ $width = ($width % 2)? $width+1: $width;
 660+ $height = ($height % 2)? $height+1: $height;
 661+ return array( $width, $height );
 662+ }
614663
615664 /**
616665 * Transforms the size per a given "maxSize"

Status & tagging log