Index: trunk/extensions/TimedMediaHandler/handlers/WebMHandler/WebMHandler.php |
— | — | @@ -18,8 +18,9 @@ |
19 | 19 | $getID3->option_tags_process = false; // Copy tags to root key 'tags' and encode to $this->encoding |
20 | 20 | $getID3->option_tags_html = false; // Copy tags to root key 'tags_html' properly translated from various encodings to HTML entities |
21 | 21 | |
22 | | - // Analyze file and store returned data in $ThisFileInfo |
| 22 | + // Analyze file to get metadata structure: |
23 | 23 | $id3 = $getID3->analyze( $path ); |
| 24 | + |
24 | 25 | // Unset some parts of id3 that are too detailed and matroska specific: |
25 | 26 | unset( $id3['matroska'] ); |
26 | 27 | // remove file paths |
— | — | @@ -32,6 +33,7 @@ |
33 | 34 | |
34 | 35 | return serialize( $id3 ); |
35 | 36 | } |
| 37 | + |
36 | 38 | /** |
37 | 39 | * Get the "media size" |
38 | 40 | */ |
Index: trunk/extensions/TimedMediaHandler/TimedMediaHandler_body.php |
— | — | @@ -128,15 +128,19 @@ |
129 | 129 | 'offset' => $this->getOffset( $file ), |
130 | 130 | 'width' => $params['width'], |
131 | 131 | 'height' => $srcWidth == 0 ? $srcHeight : $params['width']* $srcHeight / $srcWidth, |
132 | | - 'isVideo' => ( $srcHeight != 0 && $srcWidth != 0 ) |
| 132 | + 'isVideo' => ( $srcHeight != 0 && $srcWidth != 0 ), |
| 133 | + 'thumbtime' => ( isset( $params['thumbtime'] ) )? $params['thumbtime'] : false, |
| 134 | + 'start' => ( isset( $params['start'] ) )? $params['start'] : false, |
| 135 | + 'end' => ( isset( $params['end'] ) )? $params['end'] : false |
133 | 136 | ); |
134 | 137 | // No thumbs for audio |
135 | 138 | if( $baseConfig['isVideo'] === false ){ |
136 | 139 | return new TimedMediaTransformOutput( $baseConfig ); |
137 | 140 | } |
138 | 141 | |
139 | | - // Setup pointer to thumb url: |
| 142 | + // Setup pointer to thumb arguments |
140 | 143 | $baseConfig['thumbUrl'] = $dstUrl; |
| 144 | + $baseConfig['dstPath'] = $dstPath; |
141 | 145 | |
142 | 146 | // Check if transform is deferred: |
143 | 147 | if ( $flags & self::TRANSFORM_LATER ) { |
— | — | @@ -144,7 +148,7 @@ |
145 | 149 | } |
146 | 150 | |
147 | 151 | // Generate thumb: |
148 | | - $thumbStatus = TimedMediaThumbnail::get( $file, $dstPath, $params, $width, $height ); |
| 152 | + $thumbStatus = TimedMediaThumbnail::get( $baseConfig ); |
149 | 153 | if( $thumbStatus !== true ){ |
150 | 154 | return $thumbStatus; |
151 | 155 | } |
— | — | @@ -171,21 +175,6 @@ |
172 | 176 | return $wgLang->formatTimePeriod( $this->getLength( $file ) ); |
173 | 177 | } |
174 | 178 | } |
175 | | - |
176 | | - function parserTransformHook( $parser, $file ) { |
177 | | - if ( isset( $parser->mOutput->hasOggTransform ) ) { |
178 | | - return; |
179 | | - } |
180 | | - $parser->mOutput->hasOggTransform = true; |
181 | | - $parser->mOutput->addOutputHook( 'TimedMediaHandler' ); |
182 | | - } |
183 | | - |
184 | | - static function outputHook( $outputPage, $parserOutput, $data ) { |
185 | | - $instance = MediaHandler::getHandler( 'application/ogg' ); |
186 | | - if ( $instance ) { |
187 | | - $instance->setHeaders( $outputPage ); |
188 | | - } |
189 | | - } |
190 | 179 | } |
191 | 180 | // Setup named Timed Media handlers |
192 | 181 | class TimedMediaHandlerOgg extends TimedMediaHandler { |
Index: trunk/extensions/TimedMediaHandler/TimedMediaHandler.hooks.php |
— | — | @@ -16,9 +16,6 @@ |
17 | 17 | $wgMediaHandlers['application/ogg'] = 'OggHandler'; |
18 | 18 | $wgMediaHandlers['video/webm'] = 'WebMHandler'; |
19 | 19 | |
20 | | - // Parser hook for TimedMediaHandler output |
21 | | - $wgParserOutputHooks['TimedMediaHandler'] = array( 'TimedMediaHandler', 'outputHook' ); |
22 | | - |
23 | 20 | // Setup a hook for iframe embed handling: |
24 | 21 | $wgHooks['ArticleFromTitle'][] = 'TimedMediaIframeOutput::iframeHook'; |
25 | 22 | |
Index: trunk/extensions/TimedMediaHandler/TimedMediaThumbnail.php |
— | — | @@ -1,34 +1,23 @@ |
2 | 2 | <?php |
3 | 3 | class TimedMediaThumbnail { |
4 | 4 | |
5 | | - function get( $file, $dstPath, $params, $width, $height){ |
| 5 | + static function get( $options ){ |
6 | 6 | global $wgFFmpegLocation, $wgOggThumbLocation; |
7 | | - $thumbtime = self::getThumbTime($file, $params ); |
| 7 | + $thumbtime = self::getThumbTime( $options ); |
8 | 8 | |
9 | | - wfMkdirParents( dirname( $dstPath ) ); |
| 9 | + // Set up lodal pointer to file |
| 10 | + $file = $options['file']; |
| 11 | + |
| 12 | + wfMkdirParents( dirname( $options['dstPath'] ) ); |
10 | 13 | |
11 | | - wfDebug( "Creating video thumbnail at $dstPath\n" ); |
| 14 | + wfDebug( "Creating video thumbnail at" . $options['dstPath'] . "\n" ); |
12 | 15 | |
13 | | - $width = ( isset( $params['width'] ) |
14 | | - && |
15 | | - $params['width'] > 0 |
16 | | - && |
17 | | - $params['width'] < $file->getWidth() |
18 | | - ) ? $params['width'] : $file->getWidth(); |
19 | | - |
20 | | - $height = ( isset( $params['height'] ) |
21 | | - && |
22 | | - $params['height'] > 0 |
23 | | - && |
24 | | - $params['height'] < $file->getHeight() |
25 | | - ) ? $params['height'] : $file->getHeight(); |
26 | | - |
27 | 16 | // If ogg try OggThumb: |
28 | | - if( self::tryOggThumb($file, $dstPath, $width, $height, $thumbtime ) ){ |
| 17 | + if( self::tryOggThumb( $options) ){ |
29 | 18 | return true; |
30 | 19 | } |
31 | 20 | // Else try and return the ffmpeg thumbnail attempt: |
32 | | - return self::tryFfmpegThumb($file, $dstPath, $width, $height, $thumbtime ); |
| 21 | + return self::tryFfmpegThumb( $options ); |
33 | 22 | } |
34 | 23 | /** |
35 | 24 | * Try to render a thumbnail using oggThumb: |
— | — | @@ -37,11 +26,11 @@ |
38 | 27 | * @param $dstPath {string} Destination path for the rendered thumbnail |
39 | 28 | * @param $dstPath {array} Thumb rendering parameters ( like size and time ) |
40 | 29 | */ |
41 | | - function tryOggThumb($file, $dstPath, $width, $height, $thumbtime ){ |
| 30 | + static function tryOggThumb( $options ){ |
42 | 31 | global $wgOggThumbLocation; |
43 | 32 | |
44 | 33 | // Check for ogg format file and $wgOggThumbLocation |
45 | | - if( !$file->getHandler()->getMetadataType() == 'ogg' |
| 34 | + if( !$options['file']->getHandler()->getMetadataType() == 'ogg' |
46 | 35 | || !$wgOggThumbLocation |
47 | 36 | || !is_file( $wgOggThumbLocation ) |
48 | 37 | ){ |
— | — | @@ -49,37 +38,37 @@ |
50 | 39 | } |
51 | 40 | |
52 | 41 | $cmd = wfEscapeShellArg( $wgOggThumbLocation ) . |
53 | | - ' -t '. intval( $thumbtime ) . ' ' . |
54 | | - ' -n ' . wfEscapeShellArg( $dstPath ) . ' ' . |
55 | | - ' ' . wfEscapeShellArg( $file->getPath() ) . ' 2>&1'; |
| 42 | + ' -t '. intval( $options['thumbtime'] ) . ' ' . |
| 43 | + ' -n ' . wfEscapeShellArg( $options['dstPath'] ) . ' ' . |
| 44 | + ' ' . wfEscapeShellArg( $options['file']->getPath() ) . ' 2>&1'; |
56 | 45 | $returnText = wfShellExec( $cmd, $retval ); |
57 | 46 | |
58 | 47 | // Check if it was successful |
59 | | - if ( !$file->getHandler()->removeBadFile( $dstPath, $retval ) ) { |
| 48 | + if ( !$options['file']->getHandler()->removeBadFile( $options['dstPath'], $retval ) ) { |
60 | 49 | return true; |
61 | 50 | } |
62 | 51 | return false; |
63 | 52 | } |
64 | 53 | |
65 | | - function tryFfmpegThumb($file, $dstPath, $width, $height, $thumbtime ){ |
| 54 | + static function tryFfmpegThumb( $options ){ |
66 | 55 | global $wgFFmpegLocation; |
67 | 56 | if( !$wgFFmpegLocation || !is_file( $wgFFmpegLocation ) ){ |
68 | 57 | return false; |
69 | 58 | } |
70 | 59 | |
71 | 60 | $cmd = wfEscapeShellArg( $wgFFmpegLocation ) . |
72 | | - ' -ss ' . intval( $thumbtime ) . ' ' . |
73 | | - ' -i ' . wfEscapeShellArg( $file->getPath() ) . |
| 61 | + ' -ss ' . intval( $options['thumbtime'] ) . ' ' . |
| 62 | + ' -i ' . wfEscapeShellArg( $options['file']->getPath() ) . |
74 | 63 | # MJPEG, that's the same as JPEG except it's supported by the windows build of ffmpeg |
75 | 64 | # No audio, one frame |
76 | 65 | ' -f mjpeg -an -vframes 1 ' . |
77 | | - wfEscapeShellArg( $dstPath ) . ' 2>&1'; |
| 66 | + wfEscapeShellArg( $options['dstPath'] ) . ' 2>&1'; |
78 | 67 | |
79 | 68 | $retval = 0; |
80 | 69 | $returnText = wfShellExec( $cmd, $retval ); |
81 | 70 | |
82 | 71 | // Check if it was successful |
83 | | - if ( !$file->getHandler()->removeBadFile( $dstPath, $retval ) ) { |
| 72 | + if ( !$options['file']->getHandler()->removeBadFile( $options['dstPath'], $retval ) ) { |
84 | 73 | return true; |
85 | 74 | } |
86 | 75 | // Filter nonsense |
— | — | @@ -93,25 +82,21 @@ |
94 | 83 | $lines = array_slice( $lines, $i ); |
95 | 84 | } |
96 | 85 | // Return error box |
97 | | - return new MediaTransformError( 'thumbnail_error', $width, $height, implode( "\n", $lines ) ); |
| 86 | + return new MediaTransformError( 'thumbnail_error', $options['width'], $options['height'], implode( "\n", $lines ) ); |
98 | 87 | } |
99 | 88 | |
100 | | - function getThumbTime( $file, $params ){ |
101 | | - |
102 | | - $length = $file->getLength(); |
| 89 | + static function getThumbTime( $options ){ |
| 90 | + $length = $options['file']->getLength(); |
103 | 91 | $thumbtime = false; |
104 | | - if ( isset( $params['thumbtime'] ) ) { |
105 | | - $thumbtime = TimedMediaHandler::parseTimeString( $params['thumbtime'], $length ); |
| 92 | + if ( $options['thumbtime'] ) { |
| 93 | + return TimedMediaHandler::parseTimeString( $options['thumbtime'], $length ); |
106 | 94 | } |
107 | | - if ( $thumbtime === false ) { |
108 | | - // If start time param isset use that for the thumb: |
109 | | - if( isset( $params['start'] ) ){ |
110 | | - $thumbtime = TimedMediaHandler::parseTimeString( $params['start'], $length ); |
111 | | - }else{ |
112 | | - # Seek to midpoint by default, it tends to be more interesting than the start |
113 | | - $thumbtime = $length / 2; |
114 | | - } |
115 | | - } |
116 | | - return $thumbtime; |
| 95 | + // If start time param isset use that for the thumb: |
| 96 | + if( $options['start'] ) { |
| 97 | + return TimedMediaHandler::parseTimeString( $options['start'], $length ); |
| 98 | + }else{ |
| 99 | + // Seek to midpoint by default, it tends to be more interesting than the start |
| 100 | + return $length / 2; |
| 101 | + } |
117 | 102 | } |
118 | 103 | } |
\ No newline at end of file |