Index: trunk/extensions/TimedMediaHandler/TimedMediaHandler.php |
— | — | @@ -62,7 +62,7 @@ |
63 | 63 | // The priority to be used with the nice transcode commands. |
64 | 64 | $wgTranscodeBackgroundPriority = 19; |
65 | 65 | |
66 | | -// The total amount of time a transcoding shell command can take: |
| 66 | +// The total amout of time a transcoding shell command can take: |
67 | 67 | $wgTranscodeBackgroundTimeLimit = 3600 * 4; |
68 | 68 | |
69 | 69 | // The location of ffmpeg2theora ( transcoding ) |
Index: trunk/extensions/TimedMediaHandler/WebVideoTranscode/WebVideoTranscodeJob.php |
— | — | @@ -323,10 +323,13 @@ |
324 | 324 | } else { |
325 | 325 | $aspectRatio = $file->getWidth() . ':' . $file->getHeight(); |
326 | 326 | } |
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) { |
329 | 332 | // 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'] ); |
331 | 334 | $cmd.= ' -s ' . intval( $width ) . 'x' . intval( $height ); |
332 | 335 | } else if ( |
333 | 336 | (isset( $options['width'] ) && $options['width'] > 0 ) |
— | — | @@ -390,6 +393,18 @@ |
391 | 394 | |
392 | 395 | // Set up the base command |
393 | 396 | $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 | + |
394 | 409 | // Add in the encode settings |
395 | 410 | foreach( $options as $key => $val ){ |
396 | 411 | if( isset( self::$foggMap[$key] ) ){ |
Index: trunk/extensions/TimedMediaHandler/WebVideoTranscode/WebVideoTranscode.php |
— | — | @@ -53,7 +53,8 @@ |
54 | 54 | public static $derivativeSettings = array( |
55 | 55 | WebVideoTranscode::ENC_OGV_2MBS => |
56 | 56 | array( |
57 | | - 'maxSize' => '220', // 160P or around there |
| 57 | + 'maxSize' => '220', |
| 58 | + 'targetSize' => '160P', // 160P |
58 | 59 | 'videoBitrate' => '160', |
59 | 60 | 'audioBitrate' => '32', |
60 | 61 | 'samplerate' => '22050', |
— | — | @@ -67,7 +68,8 @@ |
68 | 69 | ), |
69 | 70 | WebVideoTranscode::ENC_OGV_5MBS => |
70 | 71 | array( |
71 | | - 'maxSize' => '480', // 360P |
| 72 | + 'maxSize' => '480', |
| 73 | + 'targetSize' => '360P', // 360P |
72 | 74 | 'videoBitrate' => '512', |
73 | 75 | 'audioBitrate' => '48', |
74 | 76 | 'noUpscaling' => 'true', |
— | — | @@ -78,7 +80,8 @@ |
79 | 81 | ), |
80 | 82 | WebVideoTranscode::ENC_OGV_9MBS => |
81 | 83 | array( |
82 | | - 'maxSize' => '640', // 480P |
| 84 | + 'maxSize' => '640', |
| 85 | + 'targetSize' => '480P', // 480P |
83 | 86 | 'videoBitrate' => '786', |
84 | 87 | 'audioBitrate' => '96', |
85 | 88 | 'noUpscaling' => 'true', |
— | — | @@ -91,6 +94,7 @@ |
92 | 95 | WebVideoTranscode::ENC_OGV_HQ_VBR => |
93 | 96 | array( |
94 | 97 | 'maxSize' => '1280', // 720P |
| 98 | + 'targetSize' => '720P', // 480P |
95 | 99 | 'videoQuality' => 6, |
96 | 100 | 'audioQuality' => 3, |
97 | 101 | 'noUpscaling' => 'true', |
— | — | @@ -101,7 +105,8 @@ |
102 | 106 | // WebM transcode: |
103 | 107 | WebVideoTranscode::ENC_WEBM_5MBS => |
104 | 108 | array( |
105 | | - 'maxSize' => '480', // 380P |
| 109 | + 'maxSize' => '480', |
| 110 | + 'targetSize' => '380P', // 360P |
106 | 111 | 'videoBitrate' => '512', |
107 | 112 | 'audioBitrate' => '48', |
108 | 113 | 'noUpscaling' => 'true', |
— | — | @@ -112,7 +117,8 @@ |
113 | 118 | ), |
114 | 119 | WebVideoTranscode::ENC_WEBM_9MBS => |
115 | 120 | array( |
116 | | - 'maxSize' => '640', // 480P |
| 121 | + 'maxSize' => '640', |
| 122 | + 'targetSize' => '480P', // 480P |
117 | 123 | 'videoBitrate' => '786', |
118 | 124 | 'audioBitrate' => '96', |
119 | 125 | 'noUpscaling' => 'true', |
— | — | @@ -123,7 +129,8 @@ |
124 | 130 | ), |
125 | 131 | WebVideoTranscode::ENC_WEBM_HQ_VBR => |
126 | 132 | array( |
127 | | - 'maxSize' => '1280', // 720P |
| 133 | + 'maxSize' => '1280', |
| 134 | + 'targetSize' => '720P', // 720P |
128 | 135 | 'videoQuality' => 7, |
129 | 136 | 'audioQuality' => 3, |
130 | 137 | 'noUpscaling' => 'true', |
— | — | @@ -610,6 +617,48 @@ |
611 | 618 | } |
612 | 619 | wfProfileOut( __METHOD__ ); |
613 | 620 | } |
| 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 | + } |
614 | 663 | |
615 | 664 | /** |
616 | 665 | * Transforms the size per a given "maxSize" |