r82001 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r82000‎ | r82001 | r82002 >
Date:23:11, 11 February 2011
Author:dale
Status:deferred
Tags:
Comment:
updated ffmpeg mapping for firefogg api
added dependency to patch on bug 27336 ( so that normal requests don't result in transcode jobs )
Modified paths:
  • /trunk/extensions/TimedMediaHandler/README (modified) (history)
  • /trunk/extensions/TimedMediaHandler/TimedMediaHandler.hooks.php (modified) (history)
  • /trunk/extensions/TimedMediaHandler/TimedMediaHandler.php (modified) (history)
  • /trunk/extensions/TimedMediaHandler/TimedMediaHandler_body.php (modified) (history)
  • /trunk/extensions/TimedMediaHandler/TimedMediaTransformOutput.php (modified) (history)
  • /trunk/extensions/TimedMediaHandler/WebVideoTranscode/WebVideoTranscode.php (modified) (history)
  • /trunk/extensions/TimedMediaHandler/WebVideoTranscode/WebVideoTranscodeCron.old.php (modified) (history)
  • /trunk/extensions/TimedMediaHandler/WebVideoTranscode/WebVideoTranscodeJob.php (modified) (history)

Diff [purge]

Index: trunk/extensions/TimedMediaHandler/TimedMediaHandler_body.php
@@ -199,16 +199,14 @@
200200
201201 $srcWidth = $file->getWidth();
202202 $srcHeight = $file->getHeight();
203 -
204203 $baseConfig = array(
205204 'file' => $file,
206205 'length' => $this->getLength( $file ),
207206 'offset' => $this->getOffset( $file ),
208207 'width' => $params['width'],
209208 'height' => $srcWidth == 0 ? $srcHeight : $params['width']* $srcHeight / $srcWidth,
210 - 'isVideo' => ( $srcHeight == 0 || $srcWidth == 0 ),
 209+ 'isVideo' => ( $srcHeight != 0 && $srcWidth != 0 )
211210 );
212 -
213211 // No thumbs for audio
214212 if( $baseConfig['isVideo'] === false ){
215213 return new TimedMediaTransformOutput( $baseConfig );
Index: trunk/extensions/TimedMediaHandler/TimedMediaTransformOutput.php
@@ -37,7 +37,7 @@
3838 }
3939 }
4040
41 - function getTagName(){
 41+ function getTagName(){
4242 return ( $this->isVideo )? 'video' : 'audio';
4343 }
4444
@@ -71,18 +71,24 @@
7272 * supplied arrays
7373 */
7474 function getXmlTagOutput( $mediaAttr, $mediaSources, $textSources ){
75 - // Build the video tag output:
 75+ // Try to get the first source src attribute ( usually this should be the source file )
 76+ $firstSource = current( reset( $mediaSources ) );
 77+ if( !$firstSource['url']){
 78+ // XXX media handlers don't seem to work with exceptions..
 79+ return 'Error missing media source';
 80+ }
 81+ // Build the video tag output:
7682 $s = Xml::tags( $this->getTagName(), $mediaAttr,
7783
7884 // The set of media sources:
7985 self::xmlTagSet( 'source', $mediaSources ) .
8086
8187 // Timed text:
82 - self::xmlTagSet( 'track', $textAttr ) .
 88+ self::xmlTagSet( 'track', $textSources ) .
8389
8490 // Fallback text displayed for browsers without js and without video tag support:
8591 /// XXX note we may want to replace this with an image and download link play button
86 - wfMsg('timedmedia-no-player-js', $url)
 92+ wfMsg('timedmedia-no-player-js', $firstSource['src'])
8793 );
8894 return $s;
8995 }
@@ -103,11 +109,6 @@
104110 // Note we set controls to true ( for no-js players ) when mwEmbed rewrites the interface
105111 // it updates the controls attribute of the embed video
106112 'controls'=> 'true',
107 -
108 - // Custom data-attributes
109 - 'data-durationhint' => $length,
110 - 'data-startoffset' => $offset,
111 - 'data-mwtitle' => $this->file->getTitle()->getDBKey()
112113 );
113114
114115 // Set player skin:
@@ -115,7 +116,14 @@
116117 $mediaAttr['class'] = htmlspecialchars ( $wgVideoPlayerSkin );
117118 }
118119
119 - // xxx Note when on the same cluster we should be able to look up sources
 120+ // Custom data-attributes
 121+ $mediaAttr += array(
 122+ 'data-durationhint' => $length,
 123+ 'data-startoffset' => $offset,
 124+ 'data-mwtitle' => $this->file->getTitle()->getDBKey()
 125+ );
 126+
 127+ // Add api provider:
120128 if( $this->file->getRepoName() != 'local' ){
121129 // Set the api provider name to "commons" for shared ( instant commons convention )
122130 // ( provider names should have identified the provider
@@ -126,6 +134,7 @@
127135 }
128136 // XXX Note: will probably migrate mwprovider to an escaped api url.
129137 $mediaAttr[ 'data-mwprovider' ] = $apiProviderName;
 138+
130139 return $mediaAttr;
131140 }
132141
@@ -138,7 +147,7 @@
139148 return $this->sources;
140149 }
141150
142 - function getTimedTextSources(){
 151+ function getTextSources(){
143152 // Check local cache:
144153 if( $this->textTracks ){
145154 return $this->textTracks;
@@ -155,7 +164,7 @@
156165 ));
157166 $api = new ApiMain( $params );
158167 $api->execute();
159 - $data = & $api->getResultData();
 168+ $data = $api->getResultData();
160169 // Get the list of language Names
161170 $langNames = Language::getLanguageNames();
162171
Index: trunk/extensions/TimedMediaHandler/TimedMediaHandler.php
@@ -36,6 +36,7 @@
3737 $wgAutoloadClasses['TimedMediaTransformOutput'] = "$timedMediaDir/TimedMediaTransformOutput.php";
3838 $wgAutoloadClasses['TimedMediaIframeOutput' ] = "$timedMediaDir/TimedMediaIframeOutput.php";
3939 $wgAutoloadClasses['WebVideoTranscode'] = "$timedMediaDir/WebVideoTranscode/WebVideoTranscode.php";
 40+$wgAutoloadClasses['WebVideoTranscodeJob'] = "$timedMediaDir/WebVideoTranscode/WebVideoTranscodeJob.php";
4041
4142 // Register the Timed Media Handler javascript resources ( mwEmbed modules )
4243 MwEmbedResourceManager::register( 'extensions/TimedMediaHandler/resources/EmbedPlayer' );
@@ -74,7 +75,7 @@
7576 $wgOggThumbLocation = '/usr/bin/oggThumb';
7677
7778 // The location of ffmpeg2theora ( for metadata and transcoding )
78 -$wgffmpeg2theoraPath = '/usr/bin/ffmpeg2theora';
 79+$wgffmpeg2theoraLocation = '/usr/bin/ffmpeg2theora';
7980
8081 // Location of the FFmpeg binary ( used to encode WebM and for thumbnails )
8182 $wgFFmpegLocation = '/usr/bin/ffmpeg';
Index: trunk/extensions/TimedMediaHandler/WebVideoTranscode/WebVideoTranscodeJob.php
@@ -20,9 +20,247 @@
2121 public function __construct( $title, $params, $id = 0 ) {
2222 parent::__construct( 'webVideoTranscode', $title, $params, $id );
2323 }
24 -
 24+ // Run the transcode request
2525 public function run() {
 26+ // Get the file object
 27+ $file = wfLocalFile( $this->title );
 28+ $transcodeKey = $this->params['transcodeKey'];
2629
 30+ // Build the destination target
 31+ $destinationFile = WebVideoTranscode::getTargetEncodePath( $file, $transcodeKey );
 32+
 33+ $options = WebVideoTranscode::$derivativeSettings[ $transcodeKey ];
 34+
 35+ // Check the codec see which encode method to call;
 36+ if( $options['codec'] == 'theora' ){
 37+ $status = $this->ffmpeg2TheoraEncode( $file, $destinationFile, $options );
 38+ } else if( $options['codec'] == 'vp8' ){
 39+ // Check for twopass:
 40+ if( isset( $options['twopass'] ) ){
 41+ $status = $this->ffmpegEncode( $file, $destinationFile, $options, 1 );
 42+ if( $status ){
 43+ $status = $this->ffmpegEncode( $file, $destinationFile, $options, 2 );
 44+ }
 45+ } else {
 46+ $this->ffmpegEncode( $file, $destinationFile, $options );
 47+ }
 48+
 49+ } else {
 50+ wfDebug( 'Error unknown codec:' . $options['codec'] );
 51+ $status = false;
 52+ }
 53+
 54+ return $status;
2755 }
2856
 57+ /** Utility helper for ffmpeg and ffmpeg2theora mapping **/
 58+
 59+ function ffmpegEncode( $file, $target, $options, $pass=0 ){
 60+ global $wgFFmpegLocation;
 61+ // Get the source
 62+ $source = $file->getFullPath();
 63+
 64+ // Set up the base command
 65+ $cmd = wfEscapeShellArg( $wgFFmpegLocation ) . ' ' . wfEscapeShellArg( $source );
 66+
 67+ if( isset($options['preset']) ){
 68+ if ($options['preset'] == "360p") {
 69+ $cmd.= " -vpre libvpx-360p";
 70+ } else if ( $options['preset'] == "720p" ) {
 71+ $cmd.= " -vpre libvpx-720p";
 72+ } else if ( $options['preset'] == "1080p" ) {
 73+ $cmd.= " -vpre libvpx-1080p";
 74+ }
 75+ }
 76+
 77+ if ( isset( $options['novideo'] ) ) {
 78+ $cmd.= " -vn ";
 79+ } else {
 80+ $cmd.= $this->ffmpegAddVideoOptions( $file, $target, $options, $pass );
 81+
 82+ }
 83+
 84+ // Check for start time
 85+ if( isset( $options['starttime'] ) ){
 86+ $cmd.= ' -ss ' . wfEscapeShellArg( $options['starttime'] );
 87+ } else {
 88+ $options['starttime'] = 0;
 89+ }
 90+ // Check for end time:
 91+ if( isset( $options['endtime'] ) ){
 92+ $cmd.= ' -t ' . intval( $options['endtime'] ) - intval($options['starttime'] ) ;
 93+ }
 94+
 95+
 96+ if ( $pass == 1 || $options['noaudio'] ) {
 97+ $cmd.= ' -an';
 98+ } else {
 99+ $cmd.= $this->ffmpegAddAudioOptions( $file, $target, $options, $pass );
 100+ }
 101+
 102+ // Output WebM
 103+ $cmd.=" -f webm";
 104+
 105+ if ( $pass != 0 ) {
 106+ $cmd.=" -pass " .wfEscapeShellArg( $pass ) ;
 107+ $cmd.=" -passlogfile " . wfEscapeShellArg( $target .'.log' );
 108+ }
 109+ // And the output target:
 110+ if ($pass==1) {
 111+ $cmd.= ' /dev/null';
 112+ } else{
 113+ $cmd.= $target;
 114+ }
 115+
 116+ print "Running cmd: \n\n" .$cmd . "\n\n" ;
 117+
 118+ wfProfileIn( 'ffmpeg_encode' );
 119+ wfShellExec( $cmd, $retval );
 120+ wfProfileOut( 'ffmpeg_encode' );
 121+
 122+ if( $retval ){
 123+ return false;
 124+ }
 125+ return true;
 126+ }
 127+ function ffmpegAddVideoOptions( $file, $target, $options, $pass){
 128+ $cmd ='';
 129+ // Add the boiler plate vp8 ffmpeg command:
 130+ $cmd.="-y -skip_threshold 0 -rc_buf_aggressivity 0 -bufsize 6000k -rc_init_occupancy 4000 -threads 4";
 131+
 132+ // Check for video quality:
 133+ if ( isset( $options['videoQuality'] ) && $options['videoQuality'] >= 0 ) {
 134+ // Map 0-10 to 63-0, higher values worse quality
 135+ $quality = 63 - intval( intval( $options['videoQuality'] )/10 * 63 );
 136+ $cmd .= " -qmin " . wfEscapeShellArg( $quality );
 137+ $cmd .= " -qmax " . wfEscapeShellArg( $quality );
 138+ }
 139+
 140+ // Check for video bitrate:
 141+ if ( isset( $options['videoBitrate'] ) ) {
 142+ $cmd.= " -qmin 1 -qmax 51";
 143+ $cmd.= " -vp " . wfEscapeShellArg( $options['videoBitrate'] );
 144+ }
 145+ // Set the codec:
 146+ $cmd.= " -vcodec libvpx";
 147+
 148+ die( $file->getWidth() + ':' + $file->getHeight() );
 149+
 150+ // Check for aspect ratio
 151+ if ($options['aspect']) {
 152+ $aspectRatio = $options['aspect'];
 153+ } else {
 154+ $aspectRatio = $file->getWidth() + ':' + $file->getHeight();
 155+ }
 156+
 157+ $dar = $aspectRatio.split(':');
 158+ $dar = intval( $aspectRatio[0] ) / intval( $aspectRatio[1] );
 159+
 160+ // Check maxSize
 161+ if (isset( $options['maxSize'] ) && intval( $options['maxSize'] ) > 0) {
 162+ $sourceWidth = $file->getWidth();
 163+ $sourceHeight =$file->getHeight();
 164+ if ($sourceWidth > $options['maxSize'] ) {
 165+ $width = intval( $options['maxSize'] );
 166+ $height = intval( $width / $dar);
 167+ } else {
 168+ $height = intval( $options['maxSize'] );
 169+ $width = intval( $height * $dar);
 170+ }
 171+ $cmd.= ' -s ' . intval( $width ) . 'x' . intval( $height );
 172+ } else if (
 173+ (isset( $options['width'] ) && $options['width'] > 0 )
 174+ &&
 175+ (isset( $options['height'] ) && $options['height'] > 0 )
 176+ ){
 177+ $cmd.= ' -s ' . intval( $options['width'] ) . 'x' . intval( $options['height'] );
 178+ }
 179+
 180+ // Handle crop:
 181+ $optionMap = array(
 182+ 'cropTop' => '-croptop',
 183+ 'cropBottom' => '-cropbottom',
 184+ 'cropLeft' => '-cropleft',
 185+ 'cropRight' => '-cropright'
 186+ );
 187+ foreach( $optionMap as $name => $cmdArg ){
 188+ if( isset($options[$name]) ){
 189+ $cmd.= " $cmdArg " . wfEscapeShellArg( $options[$name] );
 190+ }
 191+ }
 192+
 193+ // Check for keyframeInterval
 194+ if( isset( $options['keyframeInterval'] ) ){
 195+ $cmd.= ' -g ' . wfEscapeShellArg( $options['keyframeInterval'] );
 196+ $cmd.= ' -keyint_min ' . wfEscapeShellArg( $options['keyframeInterval'] );
 197+ }
 198+ if( isset( $options['deinterlace'] ) ){
 199+ $cmd.= ' -deinterlace';
 200+ }
 201+
 202+ return $cmd;
 203+ }
 204+
 205+ function ffmpegAddAudioOptions( $file, $target, $options, $pass){
 206+ $cmd ='';
 207+ if( isset( $options['audioQuality'] ) ){
 208+ $cmd.= " -aq " . wfEscapeShellArg( $options['audioQuality'] );
 209+ }
 210+ if( isset( $options['audioBitrate'] )){
 211+ $cmd.= ' -ab ' . intval( $options['audioBitrate'] ) * 1000;
 212+ }
 213+ if( isset( $options['samplerate'] ) ){
 214+ $cmd.= " -ar " . wfEscapeShellArg( $options['samplerate'] );
 215+ }
 216+ if( isset( $options['channels'] )){
 217+ $cmd.= " -ac " . wfEscapeShellArg( $options['channels'] );
 218+ }
 219+ // Always use vorbis for audio:
 220+ $cmd.= " -acodec libvorbis ";
 221+ return $cmd;
 222+ }
 223+
 224+
 225+
 226+ /**
 227+ * ffmpeg2Theora mapping is much simpler since it is the basis of the the firefogg API
 228+ */
 229+ function ffmpeg2TheoraEncode( $file, $target, $options){
 230+ global $wgffmpeg2theoraLocation;
 231+
 232+ // Get the source:
 233+ $source = $file->getFullPath();
 234+
 235+ // Set up the base command
 236+ $cmd = wfEscapeShellArg( $wgffmpeg2theoraLocation ) . ' ' . wfEscapeShellArg( $source );
 237+
 238+ // Add in the encode settings
 239+ foreach( $options as $key => $val){
 240+ if( isset( WebVideoTranscode::$foggMap[$key] ) ){
 241+ if( is_array( WebVideoTranscode::$foggMap[$key] ) ){
 242+ $cmd.= ' '. implode(' ', WebVideoTranscode::$foggMap[$key] );
 243+ }else if($val == 'true' || $val === true){
 244+ $cmd.= ' '. WebVideoTranscode::$foggMap[$key];
 245+ }else if( $val === false){
 246+ //ignore "false" flags
 247+ }else{
 248+ //normal get/set value
 249+ $cmd.= ' '. WebVideoTranscode::$foggMap[$key] . ' ' . wfEscapeShellArg( $val );
 250+ }
 251+ }
 252+ }
 253+ die( "run\n\n" . $cmd. "\n");
 254+ // Add the output target:
 255+ $cmd.= ' -o ' . wfEscapeShellArg ( $target );
 256+ print "Running cmd: \n\n" .$cmd . "\n\n" ;
 257+
 258+ wfProfileIn( 'ffmpeg2theora_encode' );
 259+ wfShellExec( $cmd, $retval );
 260+ wfProfileOut( 'ffmpeg2theora_encode' );
 261+
 262+ if( $retval ){
 263+ return false;
 264+ }
 265+ return true;
 266+ }
29267 }
\ No newline at end of file
Index: trunk/extensions/TimedMediaHandler/WebVideoTranscode/WebVideoTranscodeCron.old.php
@@ -152,13 +152,13 @@
153153
154154 $file = wfFindFile( $fileTitle );
155155 if( !$file ){
156 - $this->output( "File not found: {$name} (not adding to jobQueue\n" );
 156+ $maintenance->output( "File not found: {$name} (not adding to jobQueue\n" );
157157 continue;
158158 }
159159 $targetSize = OggTranscode::$derivativeSettings[ $derivativeKey ]['maxSize'];
160160 $sourceSize = $file->getWidth();
161161 if( $targetSize > $sourceSize ){
162 - $this->output( "File:{$name} is too small for {$derivativeKey} ::\n" .
 162+ $maintenance->output( "File:{$name} is too small for {$derivativeKey} ::\n" .
163163 "target: {$targetSize} > source: {$sourceSize} \n\n" );
164164 continue;
165165 }
@@ -285,7 +285,7 @@
286286 * @param {Array} $encodeSettings Settings to encode the file with
287287 */
288288 function doEncode( $source, $target, $encodeSettings ){
289 - global $wgffmpeg2theoraPath;
 289+ global $wgffmpeg2theoraPath, $maintenance;
290290
291291 // Set up the base command
292292 $cmd = wfEscapeShellArg( $wgffmpeg2theoraPath ) . ' ' . wfEscapeShellArg( $source );
@@ -307,7 +307,7 @@
308308 }
309309 // Add the output target:
310310 $cmd.= ' -o ' . wfEscapeShellArg ( $target );
311 - $this->output( "Running cmd: \n\n" .$cmd . "\n\n" );
 311+ $maintenance->output( "Running cmd: \n\n" .$cmd . "\n\n" );
312312 wfProfileIn( 'ffmpeg2theora_encode' );
313313 wfShellExec( $cmd, $retval );
314314 wfProfileOut( 'ffmpeg2theora_encode' );
Index: trunk/extensions/TimedMediaHandler/WebVideoTranscode/WebVideoTranscode.php
@@ -48,7 +48,7 @@
4949 * http://firefogg.org/dev/index.html
5050 */
5151 public static $derivativeSettings = array(
52 - WebVideoTranscode::ENC_WEB_2MBS =>
 52+ WebVideoTranscode::ENC_OGV_2MBS =>
5353 array(
5454 'maxSize' => '200',
5555 'videoBitrate' => '128',
@@ -59,7 +59,8 @@
6060 'noUpscaling' => 'true',
6161 'twopass' => 'true',
6262 'keyframeInterval' => '64',
63 - 'bufDelay' => '128'
 63+ 'bufDelay' => '128',
 64+ 'codec' => 'theora',
6465 ),
6566 WebVideoTranscode::ENC_OGV_4MBS =>
6667 array(
@@ -69,7 +70,8 @@
7071 'noUpscaling' => 'true',
7172 'twopass' => 'true',
7273 'keyframeInterval' => '128',
73 - 'bufDelay' => '256'
 74+ 'bufDelay' => '256',
 75+ 'codec' => 'theora',
7476 ),
7577 WebVideoTranscode::ENC_OGV_6MBS =>
7678 array(
@@ -79,9 +81,11 @@
8082 'noUpscaling' => 'true',
8183 'twopass' => 'true',
8284 'keyframeInterval' => '128',
83 - 'bufDelay' => '256'
 85+ 'bufDelay' => '256',
 86+ 'codec' => 'theora',
8487 ),
8588
 89+ // WebM transcode:
8690 WebVideoTranscode::ENC_WEBM_6MBS =>
8791 array(
8892 'maxSize' => '512',
@@ -93,12 +97,13 @@
9498 'bufDelay' => '256',
9599 'codec' => 'vp8',
96100 ),
97 - WebVideoTranscode::ENC_OGV_HQ_VBR =>
 101+ WebVideoTranscode::ENC_WEBM_HQ_VBR =>
98102 array(
99103 'maxSize' => '720',
100104 'videoQuality' => 7,
101105 'audioQuality' => 3,
102 - 'noUpscaling' => 'true'
 106+ 'noUpscaling' => 'true',
 107+ 'codec' => 'vp8',
103108 )
104109 );
105110 /**
@@ -126,6 +131,7 @@
127132 'cropRight' => "--cropright",
128133 'keyframeInterval'=> "--key",
129134 'denoise' => array("--pp", "de"),
 135+ 'deinterlace' => "--deinterlace",
130136 'novideo' => array("--novideo", "--no-skeleton"),
131137 'bufDelay' => "--buf-delay",
132138 // audio
@@ -145,16 +151,30 @@
146152 'contact' => "--contact"
147153 );
148154
 155+ static public function getDerivativeFilePath($file, $transcodeKey){
 156+ return dirname(
 157+ $file->getThumbPath(
 158+ $file->thumbName( array() )
 159+ )
 160+ ) . '/' .
 161+ $file->getName() . '.' .
 162+ $transcodeKey ;
 163+ }
 164+ static public function getTargetEncodePath( $file, $transcodeKey ){
 165+ return self::getDerivativeFilePath( $file, $transcodeKey ) . '.tmp';
 166+ }
 167+
149168 /**
150169 * Static function to get the set of video assets
151170 *
152171 * Based on the $wgEnabledTranscodeSet set of enabled derivatives
153172 *
154173 * In progress assets have .tmp extension and we don't add jobQueue for them.
155 - * This lets us do relatively cheap stat calls and avoid costly jobQueue sql queries
 174+ * This assumes "cheap" stat calls and "costly" jobQueue sql queries
156175 *
157176 * If no transcode is in progress or ready add the job to the jobQueue
158177 *
 178+ * @param {Object} File object
159179 * @returns an associative array of sources suitable for <source> tag output
160180 */
161181 static public function getSources( $file ){
@@ -163,35 +183,79 @@
164184
165185 // Setup local variables
166186 $fileName = $file->getName();
 187+
167188 // Add the source file:
168189 $sources[] = array(
169190 'src' => $file->getUrl()
170191 );
171192
172 - $thumbName = $file->thumbName( array() );
173 - $thumbPath = $file->getThumbPath( $thumbName );
174 - $thumbDir = dirname( $thumbPath );
 193+ $thumbName = $file->thumbName( array() );
175194 $thumbUrl = $file->getThumbUrl( $thumbName );
176 - $thumbUrlDir = dirname( $thumbUrl );
177 -
 195+ $thumbUrlDir = dirname( $thumbUrl );
 196+
 197+ $hasOggFlag = false;
 198+ $hasWebMFlag = false;
 199+ // Check the source file for .webm extension
 200+ if( preg_match( "/$.webm/i", $fileName ) ) {
 201+ $hasWebMFlag = true;
 202+ } else {
 203+ // we only support ogg and webm so assume oky if we have .webm
 204+ $hasOggFlag = true;
 205+ }
 206+
178207 foreach($wgEnabledTranscodeSet as $transcodeKey){
179 - $derivativeFile = $thumbPath . '/' . $fileName . '.' . $transcodeKey ;
 208+ $derivativeFile = self::getDerivativeFilePath( $file, $transcodeKey);
180209 if( is_file( $derivativeFile ) ){
181 - $sources[] = array(
 210+ $sources[] = array(
182211 'src' => $thumbUrlDir . '/' .$fileName . '.' . $transcodeKey
183212 );
184213 } else {
 214+ // Skip if transcode is smaller than source
 215+ // And we have at least one ogg and one WebM encode for this source
 216+ $codec = self::$derivativeSettings[$transcodeKey]['codec'];
 217+ if( ! self::isTranscodeSmallerThanSource( $file, $transcodeKey )
 218+ &&
 219+ // Check if we need to process the $transcodeKey because we don't
 220+ // have an ogg or webm source yet:
 221+ ! (
 222+ ( !$hasOggFlag && $codec == 'theora' )
 223+ ||
 224+ ( !$hasWebMFlag && $codec == 'vp8' )
 225+ )
 226+ ){
 227+ continue;
 228+ }
185229 // TranscodeKey not found ( check if the file is in progress ) ( tmp transcode location )
186 - if( is_file( $derivativeFile . '.tmp' ) ){
 230+ //if( is_file( self::getEncodeTargetFilePath( $file, $transcodeKey ) ){
187231 // file in progress / in queue
188232 // XXX Note we could check date and flag as failure somewhere
189 - } else {
 233+ //} else {
190234 // no in-progress file add to job queue and touch the target
191 - //touch( $derivativeFile . '.tmp' );
192 - }
 235+ $job = new WebVideoTranscodeJob( $file->getTitle(), array(
 236+ 'transcodeMode' => 'derivative',
 237+ 'transcodeKey' => $transcodeKey,
 238+ ) );
 239+ $jobId = $job->insert();
 240+ if( $jobId ){
 241+ // If the job was inserted:
 242+ touch( self::getTargetEncodePath( $file, $transcodeKey ) );
 243+ }
 244+ //}
193245 }
194246 }
195247 return $sources;
196248 }
 249+ /**
 250+ * Test if a given transcode target is smaller than the source file
 251+ *
 252+ * @param $transcodeKey The static transcode key
 253+ * @param $file {Object} File object
 254+ */
 255+ public static function isTranscodeSmallerThanSource( $file, $transcodeKey){
 256+ return ( self::$derivativeSettings[$transcodeKey]['maxSize'] < $file->getWidth()
 257+ &&
 258+ self::$derivativeSettings[$transcodeKey]['maxSize'] < $file->getHeight()
 259+ );
 260+ }
197261 }
198262
Index: trunk/extensions/TimedMediaHandler/TimedMediaHandler.hooks.php
@@ -10,7 +10,7 @@
1111 class TimedMediaHandlerHooks {
1212 // Register TimedMediaHandler Hooks
1313 static function register(){
14 - global $wgParserOutputHooks, $wgHooks;
 14+ global $wgParserOutputHooks, $wgHooks, $wgJobClasses, $wgJobExplitRequestTypes;
1515
1616 // Parser hook for TimedMediaHandler output
1717 $wgParserOutputHooks['TimedMediaHandler'] = array( 'TimedMediaHandler', 'outputHook' );
@@ -18,7 +18,15 @@
1919 // Setup a hook for iframe embed handling:
2020 $wgHooks['ArticleFromTitle'][] = 'TimedMediaIframeOutput::iframeHook';
2121
22 -
 22+ // Add transcode job class:
 23+ $wgJobClasses+= array(
 24+ 'webVideoTranscode' => 'WebVideoTranscodeJob'
 25+ );
 26+ // Transcode jobs must be explicitly requested from the job queue:
 27+ $wgJobExplitRequestTypes+= array(
 28+ 'webVideoTranscode'
 29+ );
 30+
2331 /**
2432 * Add support for the "timedText" NameSpace
2533 */
Index: trunk/extensions/TimedMediaHandler/README
@@ -67,7 +67,7 @@
6868
6969 Set the ffmpeg2theora binary location with:
7070
71 - $wgffmpeg2theoraPath = '/path/to/ffmpeg2theora';
 71+ $wgffmpeg2theoraLocation = '/path/to/ffmpeg2theora';
7272
7373 Download ffmpeg2theora from: http://v2v.cc/~j/ffmpeg2theora/
7474

Follow-up revisions

RevisionCommit summaryAuthorDate
r84397(bug 27336) Add $wgJobTypesExcludedFromDefaultQueue for job types that aren't...catrope16:52, 20 March 2011

Status & tagging log