jenkins-bot has submitted this change and it was merged.
Change subject: (bug 41737) create resized thumbnails from thumb
......................................................................
(bug 41737) create resized thumbnails from thumb
instead of creating all thumbs from the video file, only create one
thumb per position and resize that to the requested size.
Bug: 41737
Change-Id: I1455d060117f05000f3c3b6dd37b34acbd6b10d9
---
M TimedMediaThumbnail.php
1 file changed, 61 insertions(+), 2 deletions(-)
Approvals:
Aaron Schulz: Looks good to me, approved
jenkins-bot: Verified
diff --git a/TimedMediaThumbnail.php b/TimedMediaThumbnail.php
index 2d121a7..a082dbc 100644
--- a/TimedMediaThumbnail.php
+++ b/TimedMediaThumbnail.php
@@ -10,7 +10,14 @@
wfMkdirParents( dirname( $options['dstPath'] ), null,
__METHOD__ );
}
- wfDebug( "Creating video thumbnail at" . $options['dstPath']
. "\n" );
+ wfDebug( "Creating video thumbnail at " . $options['dstPath']
. "\n" );
+ if(
+ isset( $options['width'] ) && isset( $options['height']
) &&
+ $options['width'] != $options['file']->getWidth() &&
+ $options['height'] != $options['file']->getHeight()
+ ){
+ return self::resizeThumb( $options );
+ }
// try OggThumb, and fallback to ffmpeg
$result = self::tryOggThumb( $options );
if ( $result === false ) {
@@ -41,7 +48,7 @@
}
$time = self::getThumbTime( $options );
- $dstPath = $options['dstPath'];
+ $dstPath = $options['dstPath'];
$videoPath = $options['file']->getLocalRefPath();
$cmd = wfEscapeShellArg( $wgOggThumbLocation )
@@ -138,6 +145,58 @@
/**
* @param $options array
+ * @return bool|MediaTransformError
+ */
+ static function resizeThumb( $options ) {
+ $file = $options['file'];
+ $params = array();
+ foreach( array( 'start', 'thumbtime' ) as $key ) {
+ if( isset( $options[ $key ] ) ) {
+ $params[ $key ] = $options[ $key ];
+ }
+ }
+ $params["width"] = $file->getWidth();
+ $params["height"] = $file->getHeight();
+
+ $poolKey = $file->getRepo()->getSharedCacheKey( 'file', md5(
$file->getName() ) );
+ $posOptions = array_flip( array( 'start', 'thumbtime' ) );
+ $poolKey = wfAppendQuery( $poolKey, array_intersect_key(
$options, $posOptions ) );
+
+ if ( MWInit::classExists( 'PoolCounterWorkViaCallback' ) ) {
+ $work = new PoolCounterWorkViaCallback(
'TMHTransformFrame',
+ '_tmh:frame:' . $poolKey,
+ array( 'doWork' => function() use ($file,
$params) {
+ return $file->transform( $params,
File::RENDER_NOW );
+ } ) );
+ $thumb = $work->execute();
+ } else {
+ $thumb = $file->transform( $params, File::RENDER_NOW );
+ }
+
+ if ( !$thumb || $thumb->isError() ) {
+ return $thumb;
+ }
+ $src = $thumb->getStoragePath();
+ if ( !$src ) {
+ return false;
+ }
+ $thumbFile = new UnregisteredLocalFile( $file->getTitle(),
+ RepoGroup::singleton()->getLocalRepo(), $src, false );
+ $thumbParams = array(
+ "width" => $options['width'],
+ "height" => $options['height']
+ );
+ $scaledThumb = $thumbFile->getHandler()->doTransform(
$thumbFile,
+ $options['dstPath'], $options['dstPath'], $thumbParams
);
+
+ if ( !$scaledThumb || $scaledThumb->isError() ) {
+ return $scaledThumb;
+ }
+ return true;
+ }
+
+ /**
+ * @param $options array
* @return bool|float|int
*/
static function getThumbTime( $options ){
--
To view, visit https://gerrit.wikimedia.org/r/31646
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I1455d060117f05000f3c3b6dd37b34acbd6b10d9
Gerrit-PatchSet: 5
Gerrit-Project: mediawiki/extensions/TimedMediaHandler
Gerrit-Branch: master
Gerrit-Owner: J <[email protected]>
Gerrit-Reviewer: Aaron Schulz <[email protected]>
Gerrit-Reviewer: J <[email protected]>
Gerrit-Reviewer: Mdale <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits