r57439 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r57438‎ | r57439 | r57440 >
Date:21:39, 6 October 2009
Author:dale
Status:resolved (Comments)
Tags:
Comment:
added oggThumb support
Modified paths:
  • /branches/wmf-deployment/extensions/OggHandler/OggHandler.php (modified) (history)
  • /branches/wmf-deployment/extensions/OggHandler/OggHandler_body.php (modified) (history)

Diff [purge]

Index: branches/wmf-deployment/extensions/OggHandler/OggHandler.php
@@ -45,6 +45,9 @@
4646 // Location of the FFmpeg binary
4747 $wgFFmpegLocation = '/usr/bin/ffmpeg';
4848
 49+// Location of the OggThumb binary
 50+$wgOggThumbLocation = '/usr/bin/oggThumb';
 51+
4952 // Filename or URL path to the Cortado Java player applet.
5053 //
5154 // If no path is included, the path to this extension's
Index: branches/wmf-deployment/extensions/OggHandler/OggHandler_body.php
@@ -173,7 +173,7 @@
174174 }
175175
176176 function doTransform( $file, $dstPath, $dstUrl, $params, $flags = 0 ) {
177 - global $wgFFmpegLocation;
 177+ global $wgFFmpegLocation, $wgOggThumbLocation;
178178
179179 $width = $params['width'];
180180 $srcWidth = $file->getWidth();
@@ -233,45 +233,57 @@
234234 wfMkdirParents( dirname( $dstPath ) );
235235
236236 wfDebug( "Creating video thumbnail at $dstPath\n" );
 237+
 238+ //first check for oggThumb
 239+ if( $wgOggThumbLocation && is_file( $wgOggThumbLocation ) ){
 240+ $cmd = wfEscapeShellArg( $wgOggThumbLocation ) .
 241+ ' -t '. intval( $thumbTime ) . ' ' .
 242+ ' -n ' . wfEscapeShellArg( $dstPath ) . ' ' .
 243+ ' ' . wfEscapeShellArg( $file->getPath() ) . ' 2>&1';
 244+ $returnText = wfShellExec( $cmd, $retval );
237245
238 - $cmd = wfEscapeShellArg( $wgFFmpegLocation ) .
239 - ' -ss ' . intval( $thumbTime ) . ' ' .
240 - ' -i ' . wfEscapeShellArg( $file->getPath() ) .
241 - # MJPEG, that's the same as JPEG except it's supported by the windows build of ffmpeg
242 - # No audio, one frame
243 - ' -f mjpeg -an -vframes 1 ' .
244 - wfEscapeShellArg( $dstPath ) . ' 2>&1';
245 -
246 - $retval = 0;
247 - $returnText = wfShellExec( $cmd, $retval );
 246+ //check if it was successful or if we should try ffmpeg:
 247+ if ( $this->removeBadFile( $dstPath, $retval ) || $retval ) {
 248+ $cmd = wfEscapeShellArg( $wgFFmpegLocation ) .
 249+ ' -ss ' . intval( $thumbTime ) . ' ' .
 250+ ' -i ' . wfEscapeShellArg( $file->getPath() ) .
 251+ # MJPEG, that's the same as JPEG except it's supported by the windows build of ffmpeg
 252+ # No audio, one frame
 253+ ' -f mjpeg -an -vframes 1 ' .
 254+ wfEscapeShellArg( $dstPath ) . ' 2>&1';
 255+
 256+ $retval = 0;
 257+ $returnText = wfShellExec( $cmd, $retval );
248258
249 - if ( $this->removeBadFile( $dstPath, $retval ) || $retval ) {
250 - #re-attempt encode command on frame time 1 and with mapping (special case for chopped oggs)
251 - $cmd = wfEscapeShellArg( $wgFFmpegLocation ) .
252 - ' -map 0:1 '.
253 - ' -ss 1 ' .
254 - ' -i ' . wfEscapeShellArg( $file->getPath() ) .
255 - ' -f mjpeg -an -vframes 1 ' .
256 - wfEscapeShellArg( $dstPath ) . ' 2>&1';
257 -
258 - $retval = 0;
259 - $returnText = wfShellExec( $cmd, $retval );
260 - //if still bad return error:
261 - if ( $this->removeBadFile( $dstPath, $retval ) || $retval ) {
262 - // Filter nonsense
263 - $lines = explode( "\n", str_replace( "\r\n", "\n", $returnText ) );
264 - if ( substr( $lines[0], 0, 6 ) == 'FFmpeg' ) {
265 - for ( $i = 1; $i < count( $lines ); $i++ ) {
266 - if ( substr( $lines[$i], 0, 2 ) != ' ' ) {
267 - break;
 259+ if ( $this->removeBadFile( $dstPath, $retval ) || $retval ) {
 260+ #re-attempt encode command on frame time 1 and with mapping (special case for chopped oggs)
 261+ $cmd = wfEscapeShellArg( $wgFFmpegLocation ) .
 262+ ' -map 0:1 '.
 263+ ' -ss 1 ' .
 264+ ' -i ' . wfEscapeShellArg( $file->getPath() ) .
 265+ ' -f mjpeg -an -vframes 1 ' .
 266+ wfEscapeShellArg( $dstPath ) . ' 2>&1';
 267+
 268+ $retval = 0;
 269+ $returnText = wfShellExec( $cmd, $retval );
 270+ //if still bad return error:
 271+ if ( $this->removeBadFile( $dstPath, $retval ) || $retval ) {
 272+ // Filter nonsense
 273+ $lines = explode( "\n", str_replace( "\r\n", "\n", $returnText ) );
 274+ if ( substr( $lines[0], 0, 6 ) == 'FFmpeg' ) {
 275+ for ( $i = 1; $i < count( $lines ); $i++ ) {
 276+ if ( substr( $lines[$i], 0, 2 ) != ' ' ) {
 277+ break;
 278+ }
 279+ }
 280+ $lines = array_slice( $lines, $i );
268281 }
 282+ // Return error box
 283+ return new MediaTransformError( 'thumbnail_error', $width, $height, implode( "\n", $lines ) );
269284 }
270 - $lines = array_slice( $lines, $i );
271 - }
272 - // Return error box
273 - return new MediaTransformError( 'thumbnail_error', $width, $height, implode( "\n", $lines ) );
 285+ }
274286 }
275 - }
 287+ }
276288 return new OggVideoDisplay( $file, $file->getURL(), $dstUrl, $width, $height, $length, $dstPath );
277289 }
278290

Comments

#Comment by Brion VIBBER (talk | contribs)   22:41, 6 October 2009

disables thumbnailing entirely if oggthumb not present; i don't think that's what we intended :)

Status & tagging log