http://www.mediawiki.org/wiki/Special:Code/MediaWiki/84561
Revision: 84561
Author: dale
Date: 2011-03-22 21:28:22 +0000 (Tue, 22 Mar 2011)
Log Message:
-----------
adds support for scaled image thumbnails to oggThumb and ffempg thumbnail
rendering. This prevents 1080P jpegs being used as the poster for small embeds.
Modified Paths:
--------------
trunk/extensions/TimedMediaHandler/TimedMediaHandler.php
trunk/extensions/TimedMediaHandler/TimedMediaHandler_body.php
trunk/extensions/TimedMediaHandler/TimedMediaThumbnail.php
Modified: trunk/extensions/TimedMediaHandler/TimedMediaHandler.php
===================================================================
--- trunk/extensions/TimedMediaHandler/TimedMediaHandler.php 2011-03-22
21:25:03 UTC (rev 84560)
+++ trunk/extensions/TimedMediaHandler/TimedMediaHandler.php 2011-03-22
21:28:22 UTC (rev 84561)
@@ -10,7 +10,7 @@
exit( 1 );
}
-// Set up the timed media handler dir:
+// Set up the timed media handler dir:
$timedMediaDir = dirname(__FILE__);
$wgTimedMediaHandlerFileExtensions = array( 'ogg', 'ogv', 'oga', 'webm');
Modified: trunk/extensions/TimedMediaHandler/TimedMediaHandler_body.php
===================================================================
--- trunk/extensions/TimedMediaHandler/TimedMediaHandler_body.php
2011-03-22 21:25:03 UTC (rev 84560)
+++ trunk/extensions/TimedMediaHandler/TimedMediaHandler_body.php
2011-03-22 21:28:22 UTC (rev 84561)
@@ -42,13 +42,18 @@
}
function makeParamString( $params ) {
+ // Add the width param string ( same as images {width}px )
+ $paramString ='';
+ $paramString.= ( isset( $params['width'] ) )? $params['width']
. 'px' : '';
+ $paramString.= ( $paramString != '' )? '-' : '';
+
if ( isset( $params['thumbtime'] ) ) {
$time = $this->parseTimeString( $params['thumbtime'] );
if ( $time !== false ) {
- return 'seek=' . $time;
+ return $paramString. 'seek=' . $time;
}
}
- return 'mid';
+ return $paramString ;
}
function parseParamString( $str ) {
@@ -60,7 +65,7 @@
}
function normaliseParams( $image, &$params ) {
- $timeParam = array('thumbtime', 'start', 'end');
+ $timeParam = array( 'thumbtime', 'start', 'end' );
// Parse time values if endtime or thumbtime can't be more than
length -1
foreach($timeParam as $pn){
if ( isset( $params[$pn] ) ) {
@@ -163,7 +168,7 @@
'length' => $this->getLength( $file ),
'offset' => $this->getOffset( $file ),
'width' => $params['width'],
- 'height' => $srcWidth == 0 ? $srcHeight :
$params['width']* $srcHeight / $srcWidth,
+ 'height' => $srcWidth == 0 ? $srcHeight : round(
$params['width']* $srcHeight / $srcWidth ),
'isVideo' => !$this->isAudio( $file ),
'thumbtime' => ( isset( $params['thumbtime'] ) )?
$params['thumbtime'] : intval( $file->getLength() / 2 ),
'start' => ( isset( $params['start'] ) )?
$params['start'] : false,
@@ -183,7 +188,7 @@
if ( $flags & self::TRANSFORM_LATER ) {
return new TimedMediaTransformOutput($options);
}
-
+
// Generate thumb:
$thumbStatus = TimedMediaThumbnail::get( $options );
if( $thumbStatus !== true ){
Modified: trunk/extensions/TimedMediaHandler/TimedMediaThumbnail.php
===================================================================
--- trunk/extensions/TimedMediaHandler/TimedMediaThumbnail.php 2011-03-22
21:25:03 UTC (rev 84560)
+++ trunk/extensions/TimedMediaHandler/TimedMediaThumbnail.php 2011-03-22
21:28:22 UTC (rev 84561)
@@ -4,7 +4,7 @@
static function get( $options ){
global $wgFFmpegLocation, $wgOggThumbLocation;
$thumbtime = self::getThumbTime( $options );
-
+
// Set up lodal pointer to file
$file = $options['file'];
if( !is_dir( dirname( $options['dstPath'] ) ) ){
@@ -40,9 +40,17 @@
}
$cmd = wfEscapeShellArg( $wgOggThumbLocation ) .
- ' -t '. intval( $options['thumbtime'] ) . ' ' .
- ' -n ' . wfEscapeShellArg( $options['dstPath'] ) . ' ' .
+ ' -t '. intval( $options['thumbtime'] ) . ' ';
+
+ // Setting height to 0 will keep aspect:
+ // http://dev.streamnik.de/75.html
+ if( isset( $options['width'] ) ){
+ $cmd.= ' -s ' . intval( $options['width'] ) . 'x0 ';
+ }
+
+ $cmd.= ' -n ' . wfEscapeShellArg( $options['dstPath'] ) . ' ' .
' ' . wfEscapeShellArg( $options['file']->getPath() ) .
' 2>&1';
+
$returnText = wfShellExec( $cmd, $retval );
// Check if it was successful
@@ -59,8 +67,13 @@
}
$cmd = wfEscapeShellArg( $wgFFmpegLocation ) .
- ' -i ' . wfEscapeShellArg( $options['file']->getPath()
) .
- ' -ss ' . intval( $options['thumbtime'] ) .
+ ' -i ' . wfEscapeShellArg( $options['file']->getPath()
);
+ // Set the output size if set in options:
+ if( isset( $options['width'] ) && isset( $options['height'] ) ){
+ $cmd.= ' -s '. intval( $options['width'] ) . 'x' .
intval( $options['height'] );
+ }
+
+ $cmd.=' -ss ' . intval( $options['thumbtime'] ) .
# MJPEG, that's the same as JPEG except it's supported
by the windows build of ffmpeg
# No audio, one frame
' -f mjpeg -an -vframes 1 ' .
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs