r58228 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r58227‎ | r58228 | r58229 >
Date:21:51, 27 October 2009
Author:dale
Status:deferred
Tags:
Comment:
* ffmpeg2theora support for metadata ( should have been part of r57933 )
Modified paths:
  • /trunk/extensions/OggHandler/OggHandler_body.php (modified) (history)

Diff [purge]

Index: trunk/extensions/OggHandler/OggHandler_body.php
@@ -110,12 +110,14 @@
111111 if ( isset( $metadata['error'] ) ) {
112112 return false;
113113 }
114 - foreach ( $metadata['streams'] as $stream ) {
115 - if ( in_array( $stream['type'], $wgOggVideoTypes ) ) {
116 - return array(
117 - $stream['header']['PICW'],
118 - $stream['header']['PICH']
119 - );
 114+ if( isset( $metadata['streams'] ) ){
 115+ foreach ( $metadata['streams'] as $stream ) {
 116+ if ( in_array( $stream['type'], $wgOggVideoTypes ) ) {
 117+ return array(
 118+ $stream['header']['PICW'],
 119+ $stream['header']['PICH']
 120+ );
 121+ }
120122 }
121123 }
122124 return array( false, false );
@@ -124,10 +126,39 @@
125127 function getMetadata( $image, $path ) {
126128 $metadata = array( 'version' => self::OGG_METADATA_VERSION );
127129
 130+ //first try the (fast) light-on-memory (shell) path:
 131+ $ffmpgMeta = wfGetMediaJsonMeta( $path );
 132+ if( $ffmpgMeta ){
 133+ //try to recreate as much of the streams array as possible:
 134+ //@@todo clean up the code to use a simpler metadata format (hide concept of streams where possible)
 135+ $streams = array();
 136+ foreach($ffmpgMeta->video as $stream){
 137+ $streams[ $stream->id ] = array(
 138+ 'header' => array( 'PICW' => $stream->width,
 139+ 'PICH' => $stream->height
 140+ ),
 141+ 'type' => ucfirst( $stream->codec ),
 142+ 'length' => (isset( $stream->duration ) ? $stream->duration: $ffmpgMeta->duration )
 143+ );
 144+ }
 145+ foreach($ffmpgMeta->audio as $stream){
 146+ $streams[ $stream->id ] = array(
 147+ 'type' => ucfirst( $stream->codec ),
 148+ 'length' => (isset( $stream->duration ) ? $stream->duration: $ffmpgMeta->duration )
 149+ );
 150+ }
 151+
 152+ $metadata['length'] = $ffmpgMeta->duration;
 153+ $metadata['streams'] = $streams;
 154+ $metadata['bitrate'] = $ffmpgMeta->bitrate;
 155+
 156+ return serialize ( $metadata );
 157+ }
 158+
 159+
128160 if ( !class_exists( 'File_Ogg' ) ) {
129161 require( 'File/Ogg.php' );
130162 }
131 -
132163 try {
133164 $f = new File_Ogg( $path );
134165 $streams = array();
@@ -468,10 +499,15 @@
469500 } else {
470501 $length = $this->getLength( $file );
471502 foreach ( $unpacked['streams'] as $stream ) {
472 - $size += $stream['size'];
 503+ if( isset( $stream['size'] ) )
 504+ $size += $stream['size'];
473505 }
474506 }
475 - $bitrate = $length == 0 ? 0 : $size / $length * 8;
 507+ if( $size != 0 ){
 508+ $bitrate = $length == 0 ? 0 : $size / $length * 8;
 509+ }else{
 510+ $bitrate = $unpacked['bitrate'];
 511+ }
476512 return wfMsg( $msg, implode( '/', $streamTypes ),
477513 $wgLang->formatTimePeriod( $length ),
478514 $wgLang->formatBitrate( $bitrate ),
@@ -804,7 +840,26 @@
805841 }
806842 /*utility functions*/
807843
 844+
808845 /*
 846+ * gets the json metadata from a given file
 847+ */
 848+function wfGetMediaJsonMeta( $path ){
 849+ global $wgffmpeg2theoraPath;
 850+ if( ! is_file( $wgffmpeg2theoraPath ) ){
 851+ wfDebug("error could not find: $wgffmpeg2theoraPath ");
 852+ return false;
 853+ }
 854+ $cmd = wfEscapeShellArg( $wgffmpeg2theoraPath ) . ' ' . wfEscapeShellArg ( $path ). ' --info';
 855+ wfProfileIn( 'ffmpeg2theora' );
 856+ $json_meta_str = wfShellExec( $cmd );
 857+ wfProfileOut( 'ffmpeg2theora' );
 858+ $objMeta = FormatJson::decode( $json_meta_str );
 859+
 860+ return $objMeta;
 861+}
 862+
 863+/*
809864 * outputs a minimal iframe for remote embedding (with mv_embed loaded via the script-loader if enabled)
810865 */
811866 function output_iframe_page( $title ) {

Follow-up revisions

RevisionCommit summaryAuthorDate
r60495* Removed buggy stopgap solution for bug #19476 (ffmpeg2theora shell call), s...tstarling08:56, 30 December 2009

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r57933* white space fixes...dale23:20, 19 October 2009

Status & tagging log