Index: trunk/extensions/OggHandler/OggHandler.php |
— | — | @@ -40,6 +40,9 @@ |
41 | 41 | |
42 | 42 | /******************* CONFIGURATION STARTS HERE **********************/ |
43 | 43 | |
| 44 | +//Location of oggThumb binary |
| 45 | +$wgOggThumbLocation = '/usr/bin/oggThumb'; |
| 46 | + |
44 | 47 | // Set the supported ogg codecs: |
45 | 48 | $wgOggVideoTypes = array( 'Theora' ); |
46 | 49 | $wgOggAudioTypes = array( 'Vorbis', 'Speex', 'FLAC' ); |
Index: trunk/extensions/OggHandler/OggHandler_body.php |
— | — | @@ -215,48 +215,107 @@ |
216 | 216 | return new OggVideoDisplay( $file, $targetFileUrl, $dstUrl, $width, $height, $length, $dstPath, $noIcon ); |
217 | 217 | } |
218 | 218 | |
219 | | - $thumbTime = false; |
| 219 | + $thumbStatus = $this->gennerateThumb($file, $dstPath,$params, $width, $height); |
| 220 | + if( $thumbStatus !== true ) { |
| 221 | + return $thumbStatus; |
| 222 | + } |
| 223 | + |
| 224 | + return new OggVideoDisplay( $file, $file->getURL(), $dstUrl, $width, $height, $length, $dstPath ); |
| 225 | + } |
| 226 | + /** |
| 227 | + * Generate a thumbnail at a specified path |
| 228 | + * @param $file The source ogg file |
| 229 | + * @param $dstPath The target location for the jpeg |
| 230 | + * @param $params The parameters / options for the thumb request |
| 231 | + * @param $width The target output width |
| 232 | + * @param $height The target output height |
| 233 | + */ |
| 234 | + function gennerateThumb($file, $dstPath, $params, $width, $height){ |
| 235 | + global $wgFFmpegLocation, $wgOggThumbLocation; |
| 236 | + |
| 237 | + $length = $this->getLength( $file ); |
| 238 | + $thumbtime = false; |
220 | 239 | if ( isset( $params['thumbtime'] ) ) { |
221 | | - $thumbTime = $this->parseTimeString( $params['thumbtime'], $length ); |
| 240 | + $thumbtime = $this->parseTimeString( $params['thumbtime'], $length ); |
222 | 241 | } |
223 | | - if ( $thumbTime === false ) { |
224 | | - # Seek to midpoint by default, it tends to be more interesting than the start |
225 | | - $thumbTime = $length / 2; |
| 242 | + if ( $thumbtime === false ) { |
| 243 | + // If start time param isset use that for the thumb: |
| 244 | + if( isset( $params['start'] ) ){ |
| 245 | + $thumbtime = $this->parseTimeString( $params['start'], $length ); |
| 246 | + }else{ |
| 247 | + # Seek to midpoint by default, it tends to be more interesting than the start |
| 248 | + $thumbtime = $length / 2; |
| 249 | + } |
226 | 250 | } |
227 | | - |
228 | 251 | wfMkdirParents( dirname( $dstPath ) ); |
229 | 252 | |
230 | 253 | wfDebug( "Creating video thumbnail at $dstPath\n" ); |
231 | 254 | |
232 | | - $cmd = wfEscapeShellArg( $wgFFmpegLocation ) . |
233 | | - ' -ss ' . intval( $thumbTime ) . ' ' . |
234 | | - ' -i ' . wfEscapeShellArg( $file->getPath() ) . |
| 255 | + // First check for oggThumb |
| 256 | + if( $wgOggThumbLocation && is_file( $wgOggThumbLocation ) ){ |
| 257 | + $cmd = wfEscapeShellArg( $wgOggThumbLocation ) . |
| 258 | + ' -t '. intval( $thumbtime ) . ' ' . |
| 259 | + ' -n ' . wfEscapeShellArg( $dstPath ) . ' ' . |
| 260 | + ' ' . wfEscapeShellArg( $file->getPath() ) . ' 2>&1'; |
| 261 | + $returnText = wfShellExec( $cmd, $retval ); |
| 262 | + //check if it was successful or if we should try ffmpeg: |
| 263 | + if ( !$this->removeBadFile( $dstPath, $retval ) ) { |
| 264 | + return true; |
| 265 | + } |
| 266 | + } |
| 267 | + |
| 268 | + $cmd = wfEscapeShellArg( $wgFFmpegLocation ) . |
| 269 | + ' -ss ' . intval( $thumbtime ) . ' ' . |
| 270 | + ' -i ' . wfEscapeShellArg( $file->getPath() ) . |
235 | 271 | # MJPEG, that's the same as JPEG except it's supported by the windows build of ffmpeg |
236 | 272 | # No audio, one frame |
237 | 273 | ' -f mjpeg -an -vframes 1 ' . |
238 | 274 | wfEscapeShellArg( $dstPath ) . ' 2>&1'; |
239 | | - |
| 275 | + |
240 | 276 | $retval = 0; |
241 | 277 | $returnText = wfShellExec( $cmd, $retval ); |
242 | 278 | |
243 | 279 | if ( $this->removeBadFile( $dstPath, $retval ) || $retval ) { |
244 | | - // Filter nonsense |
245 | | - $lines = explode( "\n", str_replace( "\r\n", "\n", $returnText ) ); |
246 | | - if ( substr( $lines[0], 0, 6 ) == 'FFmpeg' ) { |
247 | | - for ( $i = 1; $i < count( $lines ); $i++ ) { |
248 | | - if ( substr( $lines[$i], 0, 2 ) != ' ' ) { |
249 | | - break; |
| 280 | + #re-attempt encode command on frame time 1 and with mapping (special case for chopped oggs) |
| 281 | + $cmd = wfEscapeShellArg( $wgFFmpegLocation ) . |
| 282 | + ' -map 0:1 '. |
| 283 | + ' -ss 1 ' . |
| 284 | + ' -i ' . wfEscapeShellArg( $file->getPath() ) . |
| 285 | + ' -f mjpeg -an -vframes 1 ' . |
| 286 | + wfEscapeShellArg( $dstPath ) . ' 2>&1'; |
| 287 | + $retval = 0; |
| 288 | + $returnText = wfShellExec( $cmd, $retval ); |
| 289 | + } |
| 290 | + |
| 291 | + if ( $this->removeBadFile( $dstPath, $retval ) || $retval ) { |
| 292 | + #No mapping, time zero. A last ditch attempt. |
| 293 | + $cmd = wfEscapeShellArg( $wgFFmpegLocation ) . |
| 294 | + ' -ss 0 ' . |
| 295 | + ' -i ' . wfEscapeShellArg( $file->getPath() ) . |
| 296 | + ' -f mjpeg -an -vframes 1 ' . |
| 297 | + wfEscapeShellArg( $dstPath ) . ' 2>&1'; |
| 298 | + |
| 299 | + $retval = 0; |
| 300 | + $returnText = wfShellExec( $cmd, $retval ); |
| 301 | + // If still bad return error: |
| 302 | + if ( $this->removeBadFile( $dstPath, $retval ) || $retval ) { |
| 303 | + // Filter nonsense |
| 304 | + $lines = explode( "\n", str_replace( "\r\n", "\n", $returnText ) ); |
| 305 | + if ( substr( $lines[0], 0, 6 ) == 'FFmpeg' ) { |
| 306 | + for ( $i = 1; $i < count( $lines ); $i++ ) { |
| 307 | + if ( substr( $lines[$i], 0, 2 ) != ' ' ) { |
| 308 | + break; |
| 309 | + } |
250 | 310 | } |
| 311 | + $lines = array_slice( $lines, $i ); |
251 | 312 | } |
252 | | - $lines = array_slice( $lines, $i ); |
| 313 | + // Return error box |
| 314 | + return new MediaTransformError( 'thumbnail_error', $width, $height, implode( "\n", $lines ) ); |
253 | 315 | } |
254 | | - // Return error box |
255 | | - return new MediaTransformError( 'thumbnail_error', $width, $height, implode( "\n", $lines ) ); |
256 | 316 | } |
257 | | - |
258 | | - return new OggVideoDisplay( $file, $file->getURL(), $dstUrl, $width, $height, $length, $dstPath ); |
| 317 | + // If we did not return an error return true to continue media thum display |
| 318 | + return true; |
259 | 319 | } |
260 | | - |
261 | 320 | function canRender( $file ) { return true; } |
262 | 321 | function mustRender( $file ) { return true; } |
263 | 322 | |