r57444 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r57443‎ | r57444 | r57445 >
Date:22:46, 6 October 2009
Author:dale
Status:ok
Tags:
Comment:
fixed ffmpeg fallback for oggThumb
Modified paths:
  • /branches/wmf-deployment/extensions/OggHandler/OggHandler_body.php (modified) (history)

Diff [purge]

Index: branches/wmf-deployment/extensions/OggHandler/OggHandler_body.php
@@ -233,7 +233,8 @@
234234 wfMkdirParents( dirname( $dstPath ) );
235235
236236 wfDebug( "Creating video thumbnail at $dstPath\n" );
237 -
 237+
 238+ $retval = 0;
238239 //first check for oggThumb
239240 if( $wgOggThumbLocation && is_file( $wgOggThumbLocation ) ){
240241 $cmd = wfEscapeShellArg( $wgOggThumbLocation ) .
@@ -241,49 +242,49 @@
242243 ' -n ' . wfEscapeShellArg( $dstPath ) . ' ' .
243244 ' ' . wfEscapeShellArg( $file->getPath() ) . ' 2>&1';
244245 $returnText = wfShellExec( $cmd, $retval );
 246+ if ( !$this->removeBadFile( $dstPath, $retval ) || $retval ) {
 247+ return new OggVideoDisplay( $file, $file->getURL(), $dstUrl, $width, $height, $length, $dstPath );
 248+ }
 249+ }
 250+ //try ffmpeg:
 251+ $cmd = wfEscapeShellArg( $wgFFmpegLocation ) .
 252+ ' -ss ' . intval( $thumbTime ) . ' ' .
 253+ ' -i ' . wfEscapeShellArg( $file->getPath() ) .
 254+ # MJPEG, that's the same as JPEG except it's supported by the windows build of ffmpeg
 255+ # No audio, one frame
 256+ ' -f mjpeg -an -vframes 1 ' .
 257+ wfEscapeShellArg( $dstPath ) . ' 2>&1';
 258+
 259+ $retval = 0;
 260+ $returnText = wfShellExec( $cmd, $retval );
245261
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 );
258 -
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 );
 262+ if ( $this->removeBadFile( $dstPath, $retval ) || $retval ) {
 263+ #re-attempt encode command on frame time 1 and with mapping (special case for chopped oggs)
 264+ $cmd = wfEscapeShellArg( $wgFFmpegLocation ) .
 265+ ' -map 0:1 '.
 266+ ' -ss 1 ' .
 267+ ' -i ' . wfEscapeShellArg( $file->getPath() ) .
 268+ ' -f mjpeg -an -vframes 1 ' .
 269+ wfEscapeShellArg( $dstPath ) . ' 2>&1';
 270+
 271+ $retval = 0;
 272+ $returnText = wfShellExec( $cmd, $retval );
 273+ //if still bad return error:
 274+ if ( $this->removeBadFile( $dstPath, $retval ) || $retval ) {
 275+ // Filter nonsense
 276+ $lines = explode( "\n", str_replace( "\r\n", "\n", $returnText ) );
 277+ if ( substr( $lines[0], 0, 6 ) == 'FFmpeg' ) {
 278+ for ( $i = 1; $i < count( $lines ); $i++ ) {
 279+ if ( substr( $lines[$i], 0, 2 ) != ' ' ) {
 280+ break;
281281 }
282 - // Return error box
283 - return new MediaTransformError( 'thumbnail_error', $width, $height, implode( "\n", $lines ) );
284282 }
285 - }
 283+ $lines = array_slice( $lines, $i );
 284+ }
 285+ // Return error box
 286+ return new MediaTransformError( 'thumbnail_error', $width, $height, implode( "\n", $lines ) );
286287 }
287 - }
 288+ }
288289 return new OggVideoDisplay( $file, $file->getURL(), $dstUrl, $width, $height, $length, $dstPath );
289290 }
290291

Status & tagging log