r65149 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r65148‎ | r65149 | r65150 >
Date:00:17, 17 April 2010
Author:dale
Status:deferred (Comments)
Tags:
Comment:
* restored basic video thumb support per the already deployed oggThumb ( while ffmpeg gets updated ? )
Modified paths:
  • /trunk/extensions/OggHandler/OggHandler.php (modified) (history)
  • /trunk/extensions/OggHandler/OggHandler_body.php (modified) (history)

Diff [purge]

Index: trunk/extensions/OggHandler/OggHandler.php
@@ -40,6 +40,9 @@
4141
4242 /******************* CONFIGURATION STARTS HERE **********************/
4343
 44+//Location of oggThumb binary
 45+$wgOggThumbLocation = '/usr/bin/oggThumb';
 46+
4447 // Set the supported ogg codecs:
4548 $wgOggVideoTypes = array( 'Theora' );
4649 $wgOggAudioTypes = array( 'Vorbis', 'Speex', 'FLAC' );
Index: trunk/extensions/OggHandler/OggHandler_body.php
@@ -215,48 +215,107 @@
216216 return new OggVideoDisplay( $file, $targetFileUrl, $dstUrl, $width, $height, $length, $dstPath, $noIcon );
217217 }
218218
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;
220239 if ( isset( $params['thumbtime'] ) ) {
221 - $thumbTime = $this->parseTimeString( $params['thumbtime'], $length );
 240+ $thumbtime = $this->parseTimeString( $params['thumbtime'], $length );
222241 }
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+ }
226250 }
227 -
228251 wfMkdirParents( dirname( $dstPath ) );
229252
230253 wfDebug( "Creating video thumbnail at $dstPath\n" );
231254
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() ) .
235271 # MJPEG, that's the same as JPEG except it's supported by the windows build of ffmpeg
236272 # No audio, one frame
237273 ' -f mjpeg -an -vframes 1 ' .
238274 wfEscapeShellArg( $dstPath ) . ' 2>&1';
239 -
 275+
240276 $retval = 0;
241277 $returnText = wfShellExec( $cmd, $retval );
242278
243279 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+ }
250310 }
 311+ $lines = array_slice( $lines, $i );
251312 }
252 - $lines = array_slice( $lines, $i );
 313+ // Return error box
 314+ return new MediaTransformError( 'thumbnail_error', $width, $height, implode( "\n", $lines ) );
253315 }
254 - // Return error box
255 - return new MediaTransformError( 'thumbnail_error', $width, $height, implode( "\n", $lines ) );
256316 }
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;
259319 }
260 -
261320 function canRender( $file ) { return true; }
262321 function mustRender( $file ) { return true; }
263322

Follow-up revisions

RevisionCommit summaryAuthorDate
r65563In OggHandler:...tstarling07:49, 27 April 2010
r65889MFT r65563 (and reverted base revisions r65149 and r65156): oggThumb supporttstarling01:11, 4 May 2010

Comments

#Comment by Ilmari Karonen (talk | contribs)   07:15, 17 April 2010

"gennerateThumb"? Really?

#Comment by Mdale (talk | contribs)   21:13, 18 April 2010

( thanks, fixed in r65156 )

Status & tagging log