r88114 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r88113‎ | r88114 | r88115 >
Date:17:16, 14 May 2011
Author:dale
Status:deferred
Tags:
Comment:
removed oggThumb support ( ffmpeg handles thumbnails fine )
fixed remove file support
remove log-0.log files for two pass encoding
Modified paths:
  • /trunk/extensions/TimedMediaHandler/README (modified) (history)
  • /trunk/extensions/TimedMediaHandler/TimedMediaHandler.hooks.php (modified) (history)
  • /trunk/extensions/TimedMediaHandler/TimedMediaHandler.i18n.php (modified) (history)
  • /trunk/extensions/TimedMediaHandler/TimedMediaHandler.php (modified) (history)
  • /trunk/extensions/TimedMediaHandler/TimedMediaThumbnail.php (modified) (history)
  • /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/TimedMediaHandler.php
@@ -41,9 +41,6 @@
4242 // Support iframe for remote embedding
4343 $wgEnableIframeEmbed = true;
4444
45 -// Location of oggThumb binary ( used instead of ffmpeg )
46 -$wgOggThumbLocation = '/usr/bin/oggThumb';
47 -
4845 // The location of ffmpeg2theora ( transcoding )
4946 $wgFFmpeg2theoraLocation = '/usr/bin/ffmpeg2theora';
5047
Index: trunk/extensions/TimedMediaHandler/TimedMediaThumbnail.php
@@ -11,60 +11,12 @@
1212 }
1313
1414 wfDebug( "Creating video thumbnail at" . $options['dstPath'] . "\n" );
15 - // If try OggThumb:
16 - if( self::tryOggThumb( $options) ){
17 - return true;
18 - }
1915 // Else try ffmpeg and return result:
2016 return self::tryFfmpegThumb( $options );
2117 }
22 - /**
23 - * Try to render a thumbnail using oggThumb:
24 - *
25 - * @param $file {Object} File object
26 - * @param $dstPath {string} Destination path for the rendered thumbnail
27 - * @param $dstPath {array} Thumb rendering parameters ( like size and time )
28 - */
29 - static function tryOggThumb( $options ){
30 - global $wgOggThumbLocation;
31 - // Check that the file is 'ogg' format
32 - if( $options['file']->getHandler()->getMetadataType() != 'ogg' ){
33 - return false;
34 - }
35 -
36 - // Check for $wgOggThumbLocation
37 - if( !$wgOggThumbLocation
38 - || !is_file( $wgOggThumbLocation )
39 - ){
40 - return false;
41 - }
42 -
43 - $cmd = wfEscapeShellArg( $wgOggThumbLocation ) .
44 - ' -t '. intval( self::getThumbTime( $options ) ) . ' ';
45 -
46 - // Setting height to 0 will keep aspect:
47 - // http://dev.streamnik.de/75.html
48 - if( isset( $options['width'] ) ){
49 - $cmd.= ' -s ' . intval( $options['width'] ) . 'x0 ';
50 - }
51 -
52 - $cmd.= ' -n ' . wfEscapeShellArg( $options['dstPath'] ) . ' ' .
53 - ' ' . wfEscapeShellArg( $options['file']->getPath() ) . ' 2>&1';
54 -
55 - $returnText = wfShellExec( $cmd, $retval );
56 -
57 - // Check if it was successful
58 - if ( !$options['file']->getHandler()->removeBadFile( $options['dstPath'], $retval ) ) {
59 - return true;
60 - }
61 - return false;
62 - }
6318
6419 static function tryFfmpegThumb( $options ){
6520 global $wgFFmpegLocation;
66 - if( !$wgFFmpegLocation || !is_file( $wgFFmpegLocation ) ){
67 - return false;
68 - }
6921
7022 $cmd = wfEscapeShellArg( $wgFFmpegLocation ) .
7123 ' -i ' . wfEscapeShellArg( $options['file']->getPath() );
Index: trunk/extensions/TimedMediaHandler/README
@@ -20,22 +20,33 @@
2121
2222 // For boxes doing transcoding you should increase the allocated shell memory:
2323 $wgMaxShellMemory = 102400*64;
 24+
 25+
 26+== Running Transcodes ==
 27+To transcode the video you need to run webVideoTranscode jobs. In the trunk maintenance folder
 28+you can run as the web user:
 29+ php runJobs.php --type webVideoTranscode --maxjobs 1
2430
 31+If you want to have a job runner that checks for new jobs every 5 min in the maintenance folder
 32+of Timed Media Handler run:
 33+ WebVideoJobRunner.php
2534
26 -Kaltura html5 player library
 35+
 36+== Kaltura html5 player library ==
2737 TimedMediaHandler uses the Kaltura html5 player library for video playback.
2838
2939 For more information about the player library visit:
3040 http://html5video.org or http://www.kaltura.org/project/HTML5_Video_Media_JavaScript_Library
3141
3242
33 -FFmpeg
 43+== FFmpeg ==
3444
3545 We use FFmpeg for creating still images of videos, and for transcoding webm
3646 videos. You will need a copy on your server.
3747
 48+You can download static ffmpeg builds for multiple platforms at:
 49+http://firefogg.org/nightly/
 50+
3851 Download source: http://ffmpeg.mplayerhq.hu/download.html
3952 About the bug: https://roundup.mplayerhq.hu/roundup/ffmpeg/issue159
4053
@@ -80,12 +91,14 @@
8192 after the require line in LocalSettings.php.
8293
8394
84 -ffmpeg2theora
 95+== ffmpeg2theora ==
8596
8697 We use ffmpeg2theora for extract metadata from videos, you will need a copy on your
8798 server.
8899
 100+You can download static ffmpeg2theora builds for multiple platforms at:
 101+http://firefogg.org/nightly/
 102+
89103 Set the ffmpeg2theora binary location with:
90104
91105 $wgFFmpeg2theoraLocation = '/path/to/ffmpeg2theora';
@@ -93,22 +106,7 @@
94107 Download ffmpeg2theora from: http://firefogg.org/nightly/
95108
96109
97 -oggThumb
98 -
99 -We use oggvideotools for creating still images of videos, you will need a copy on your
100 -server.
101 -
102 -Set the oggThumb binary location with:
103 -
104 - $wgOggThumbLocation = '/path/to/oggThumb';
105 -
106 -Download oggThumb from: http://dev.streamnik.de/oggvideotools.html
107 -
108 -
109 -Cortado
110 -
 110+== Cortado ==
111111 Wikimedia uses Cortado Java applet from Xiph.org.
112112
113113 A .jar file compiled from this tree is provided in the OggHandler directory for
@@ -120,9 +118,9 @@
121119
122120 See LICENSE.cortado, LICENSE.jheora and LICENSE.smoke for license information.
123121
124 -PEAR File_Ogg
125122
 123+== PEAR File_Ogg ==
 124+
126125 Tim Starling forked the PEAR File_Ogg package and improved it significantly in order to
127126 support this extension. Tim Starling has now taken over maintainership of File_Ogg and
128127 merged my changes into the latest release. This extension will now work with
@@ -132,11 +130,12 @@
133131 http://pear.php.net/package/File_Ogg
134132
135133 As per the usual convention, the PEAR base directory (the one with PEAR.php in
136 -it) must be in your include_path.
 134+it) must be in your include_path. Note you do not need to install PEAR, its included
 135+with the TMH.
137136
138137
139 -getID3
 138+== getID3 ==
 139+
140140 getID3 is used for metadata of WebM files.
141141
142142 getID3() by James Heinrich <info@getid3.org>
Index: trunk/extensions/TimedMediaHandler/TimedMediaHandler.i18n.php
@@ -49,7 +49,7 @@
5050 'timedmedia-derivative-480_880kbs.ogv' => 'Ogg 480P',
5151 'timedmedia-derivative-desc-480_880kbs.ogv' => 'Web streamable Ogg video (480P)',
5252
53 - 'timedmedia-derivative-720_VBR.ogv' => 'Ogg HQ',
 53+ 'timedmedia-derivative-720_VBR.ogv' => 'Ogg 720P',
5454 'timedmedia-derivative-desc-720_VBR.ogv' => 'High quality downloadable Ogg video (720P)',
5555
5656 // WebM profiles:
Index: trunk/extensions/TimedMediaHandler/TimedMediaTransformOutput.php
@@ -147,7 +147,7 @@
148148
149149 // Fallback text displayed for browsers without js and without video tag support:
150150 /// XXX note we may want to replace this with an image and download link play button
151 - wfMsg( 'timedmedia-no-player-js', $firstSource['src'] )
 151+ wfMsg( 'timedmedia-no-player-js', $firstSource['src'] )
152152 );
153153 return $s;
154154 }
Index: trunk/extensions/TimedMediaHandler/WebVideoTranscode/WebVideoTranscodeJob.php
@@ -77,6 +77,8 @@
7878 // unlink the .log file used in two pass encoding:
7979 wfSuppressWarnings();
8080 unlink( $destinationFile . '.log' );
 81+ // Sometimes ffmpeg gives the file log-0.log extension
 82+ unlink( $destinationFile . 'log-0.log');
8183 wfRestoreWarnings();
8284 }
8385 // remove any log files
Index: trunk/extensions/TimedMediaHandler/WebVideoTranscode/WebVideoTranscode.php
@@ -238,9 +238,9 @@
239239
240240 }
241241
242 - /*
 242+ /**
243243 * Based on the $wgEnabledTranscodeSet set of enabled derivatives we
244 - * sync the database with $wgEnabledTranscodeSet
 244+ * sync the database with $wgEnabledTranscodeSet and return sources that are ready
245245 *
246246 * If no transcode is in progress or ready add the job to the jobQueue
247247 *
@@ -297,10 +297,9 @@
298298 }
299299 // Try and add the source
300300 self::addSourceIfReady( $file, $sources, $transcodeKey, $options );
301 - }
302 -
 301+ }
303302 // Make sure we have at least one ogg and webm encode
304 - if( !$addOggFlag || !$addWebMFlag){
 303+ if( !$addOggFlag || !$addWebMFlag ){
305304 foreach( $wgEnabledTranscodeSet as $transcodeKey ){
306305 if( !$addOggFlag && self::$derivativeSettings[$transcodeKey]['videoCodec'] == 'theora' ){
307306 self::addSourceIfReady( $file, $sources, $transcodeKey, $options );
@@ -312,9 +311,9 @@
313312 }
314313 }
315314 }
316 -
317315 return $sources;
318316 }
 317+
319318 /**
320319 * Get the transcode state for a given filename and transcodeKey
321320 *
@@ -322,9 +321,9 @@
323322 */
324323 public static function isTranscodeReady( $fileName, $transcodeKey ){
325324
326 - // check if we need to populate the transcodeState cache:
 325+ // Check if we need to populate the transcodeState cache:
327326 if( !self::$transcodeStateCache || !isset( self::$transcodeStateCache[ $fileName ] ) ) {
328 - self::populateTranscodeStateCache( $fileName );
 327+ self::getTranscodeStateCache( $fileName );
329328 }
330329 // If no state is found the cache for this file is false:
331330 if( !isset( self::$transcodeStateCache[ $fileName ][ $transcodeKey ])
@@ -344,12 +343,12 @@
345344 }
346345
347346 /**
348 - * Populates the local transcoding state cache with the current DB state of transcodes
 347+ * Populates the transcode table with the current DB state of transcodes
349348 * if transcodes are not found in the database their state is set to "false"
350349 *
351350 * @param string $fileName key
352351 */
353 - public static function populateTranscodeStateCache( $fileName ){
 352+ public static function getTranscodeStateCache( $fileName ){
354353 wfProfileIn( __METHOD__ );
355354 $res = wfGetDB( DB_SLAVE )->select( 'transcode',
356355 array( 'transcode_key', 'transcode_time_success','transcode_time_addjob','transcode_final_bitrate' ) ,
@@ -369,12 +368,28 @@
370369 }
371370 /**
372371 * Remove any transcode jobs associated with a given $fileName
 372+ *
 373+ * also remove the transcode files:
373374 */
374 - public static function removeTranscodeJobs( $fileName ){
375 - wfGetDB( DB_MASTER )->delete( 'transcode',
 375+ public static function removeTranscodeJobs( &$file ){
 376+ $fileName = $file->getTitle()->getDbKey();
 377+
 378+ $res = wfGetDB( DB_SLAVE )->select( 'transcode',
 379+ array( 'transcode_key' ),
 380+ array( 'transcode_image_name' => $fileName )
 381+ );
 382+ // remove the file
 383+ foreach( $res as $transcodeRow ){
 384+ $filePath = self::getDerivativeFilePath($file, $transcodeRow->transcode_key );
 385+ if( ! @unlink( $filePath ) ){
 386+ wfDebug( "Could not delete file $filePath\n" );
 387+ }
 388+ }
 389+ // Remove the db entries
 390+ wfGetDB( DB_MASTER )->delete( 'transcode',
376391 array( 'transcode_image_name' => $fileName ),
377392 __METHOD__
378 - );
 393+ );
379394 }
380395
381396 /**
@@ -388,7 +403,7 @@
389404 if( self::isTranscodeReady( $fileName, $transcodeKey ) ){
390405 $sources[] = self::getDerivativeSourceAttributes( $file, $transcodeKey, $dataPrefix );
391406 } else {
392 - self::updateJobQueue( $file, $transcodeKey );
 407+ self::updateJobQueue( $file, $transcodeKey );
393408 }
394409 }
395410 /**
@@ -473,9 +488,9 @@
474489
475490 $fileName = $file->getTitle()->getDbKey();
476491
477 - // Check if we need to populate the transcodeState cache:
 492+ // Check if we need to update the transcode state:
478493 if( !self::$transcodeStateCache || !isset( self::$transcodeStateCache[ $fileName ] ) ) {
479 - self::populateTranscodeStateCache( $fileName );
 494+ self::getTranscodeStateCache( $fileName );
480495 }
481496
482497 // Check if the job has been added:
@@ -518,7 +533,7 @@
519534 );
520535 }
521536 // Update the state cache
522 - self::populateTranscodeStateCache( $fileName );
 537+ self::getTranscodeStateCache( $fileName );
523538 }
524539 // no jobId ? error out in some way?
525540 }
Index: trunk/extensions/TimedMediaHandler/TimedMediaHandler.hooks.php
@@ -99,20 +99,14 @@
100100 public static function checkArticleDeleteComplete( &$article, &$user, $reason, $id ){
101101 // Check if the article is a file and remove transcode jobs:
102102 if( $article->getTitle()->getNamespace() == NS_FILE ) {
103 - // We can't get the file since the article is deleted :(
104 - // so we can't:
105 - // $file = wfFindFile( $article->getTitle() );
106 - // $file->getHandler()->getMetadataType()
107103
108 -
109 - // So we have to use this unfortunate file name extension hack :(
110 - // XXX figure out a better way to do this.
111 - $fileName = $article->getTitle()->getDBkey();
112 - $ext = strtolower( pathinfo( "$fileName", PATHINFO_EXTENSION ) );
113 -
114 - if( $ext == 'ogg' || $ext == 'webm' || $ext == 'ogv' ){
115 - WebVideoTranscode::removeTranscodeJobs( $article->getTitle()->getDBkey() );
 104+ $file = wfFindFile( $article->getTitle() );
 105+ $mediaType = $file->getHandler()->getMetadataType();
 106+
 107+ if( $mediaType == 'webm' || $mediaType == 'ogg' ){
 108+ WebVideoTranscode::removeTranscodeJobs( $file );
116109 }
 110+
117111 }
118112 return true;
119113 }

Status & tagging log