Page MenuHomePhabricator

patchBug19476.patch

Authored By
bzimport
Nov 21 2014, 10:41 PM
Size
3 KB
Referenced Files
None
Subscribers
None

patchBug19476.patch

### Eclipse Workspace Patch 1.0
#P wmf-deployment
Index: extensions/OggHandler/OggHandler.php
===================================================================
--- extensions/OggHandler/OggHandler.php (revision 58505)
+++ extensions/OggHandler/OggHandler.php (working copy)
@@ -48,6 +48,9 @@
// Location of the OggThumb binary
$wgOggThumbLocation = '/usr/local/bin/oggThumb';
+//the location of ffmpeg2theora
+$wgffmpeg2theoraPath ='/usr/bin/ffmpeg2theora';
+
// Filename or URL path to the Cortado Java player applet.
//
// If no path is included, the path to this extension's
Index: extensions/OggHandler/OggHandler_body.php
===================================================================
--- extensions/OggHandler/OggHandler_body.php (revision 58505)
+++ extensions/OggHandler/OggHandler_body.php (working copy)
@@ -115,6 +115,35 @@
function getMetadata( $image, $path ) {
$metadata = array( 'version' => self::OGG_METADATA_VERSION );
+ //first try the (fast) light-on-memory (shell) path:
+ $ffmpgMeta = wfGetMediaJsonMeta( $path );
+ if( $ffmpgMeta ){
+ //try to recreate as much of the streams array as possible:
+ //@@todo clean up the code to use a simpler metadata format (hide concept of streams where possible)
+ $streams = array();
+ foreach($ffmpgMeta->video as $stream){
+ $streams[ $stream->id ] = array(
+ 'header' => array( 'PICW' => $stream->width,
+ 'PICH' => $stream->height
+ ),
+ 'type' => ucfirst( $stream->codec ),
+ 'length' => (isset( $stream->duration ) ? $stream->duration: $ffmpgMeta->duration )
+ );
+ }
+ foreach($ffmpgMeta->audio as $stream){
+ $streams[ $stream->id ] = array(
+ 'type' => ucfirst( $stream->codec ),
+ 'length' => (isset( $stream->duration ) ? $stream->duration: $ffmpgMeta->duration )
+ );
+ }
+
+ $metadata['length'] = $ffmpgMeta->duration;
+ $metadata['streams'] = $streams;
+ $metadata['bitrate'] = $ffmpgMeta->bitrate;
+
+ return serialize ( $metadata );
+ }
+
if ( !class_exists( 'File_Ogg' ) ) {
require( 'File/Ogg.php' );
}
@@ -397,10 +426,15 @@
} else {
$length = $this->getLength( $file );
foreach ( $unpacked['streams'] as $stream ) {
- $size += $stream['size'];
+ if( isset( $stream['size'] ) )
+ $size += $stream['size'];
}
}
- $bitrate = $length == 0 ? 0 : $size / $length * 8;
+ if( isset( $unpacked['bitrate'] ) ){
+ $bitrate = $unpacked['bitrate'];
+ }else{
+ $bitrate = $length == 0 ? 0 : $size / $length * 8;
+ }
return wfMsg( $msg, implode( '/', $streamTypes ),
$wgLang->formatTimePeriod( $length ),
$wgLang->formatBitrate( $bitrate ),
@@ -660,5 +694,25 @@
parent::__construct( $file, $videoUrl, false, $width, $height, $length, false, $path, $noIcon, $offset );
}
}
+/*utility functions*/
+
+
+/*
+ * gets the json metadata from a given file
+ */
+function wfGetMediaJsonMeta( $path ){
+ global $wgffmpeg2theoraPath;
+ if( ! is_file( $wgffmpeg2theoraPath ) ){
+ wfDebug("error could not find: $wgffmpeg2theoraPath ");
+ return false;
+ }
+ $cmd = wfEscapeShellArg( $wgffmpeg2theoraPath ) . ' ' . wfEscapeShellArg ( $path ). ' --info';
+ wfProfileIn( 'ffmpeg2theora' );
+ $json_meta_str = wfShellExec( $cmd );
+ wfProfileOut( 'ffmpeg2theora' );
+ $objMeta = FormatJson::decode( $json_meta_str );
+
+ return $objMeta;
+}
?>

File Metadata

Mime Type
text/x-diff
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
5360
Default Alt Text
patchBug19476.patch (3 KB)

Event Timeline