Index: branches/wmf-deployment/extensions/OggHandler/OggHandler.php |
— | — | @@ -45,6 +45,9 @@ |
46 | 46 | // Location of the FFmpeg binary |
47 | 47 | $wgFFmpegLocation = '/usr/bin/ffmpeg'; |
48 | 48 | |
| 49 | +// Location of the OggThumb binary |
| 50 | +$wgOggThumbLocation = '/usr/bin/oggThumb'; |
| 51 | + |
49 | 52 | // Filename or URL path to the Cortado Java player applet. |
50 | 53 | // |
51 | 54 | // If no path is included, the path to this extension's |
Index: branches/wmf-deployment/extensions/OggHandler/OggHandler_body.php |
— | — | @@ -173,7 +173,7 @@ |
174 | 174 | } |
175 | 175 | |
176 | 176 | function doTransform( $file, $dstPath, $dstUrl, $params, $flags = 0 ) { |
177 | | - global $wgFFmpegLocation; |
| 177 | + global $wgFFmpegLocation, $wgOggThumbLocation; |
178 | 178 | |
179 | 179 | $width = $params['width']; |
180 | 180 | $srcWidth = $file->getWidth(); |
— | — | @@ -233,45 +233,57 @@ |
234 | 234 | wfMkdirParents( dirname( $dstPath ) ); |
235 | 235 | |
236 | 236 | 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 ); |
237 | 245 | |
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 ); |
248 | 258 | |
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 ); |
268 | 281 | } |
| 282 | + // Return error box |
| 283 | + return new MediaTransformError( 'thumbnail_error', $width, $height, implode( "\n", $lines ) ); |
269 | 284 | } |
270 | | - $lines = array_slice( $lines, $i ); |
271 | | - } |
272 | | - // Return error box |
273 | | - return new MediaTransformError( 'thumbnail_error', $width, $height, implode( "\n", $lines ) ); |
| 285 | + } |
274 | 286 | } |
275 | | - } |
| 287 | + } |
276 | 288 | return new OggVideoDisplay( $file, $file->getURL(), $dstUrl, $width, $height, $length, $dstPath ); |
277 | 289 | } |
278 | 290 | |