Index: trunk/extensions/OggHandler/OggHandler_body.php |
— | — | @@ -110,12 +110,14 @@ |
111 | 111 | if ( isset( $metadata['error'] ) ) { |
112 | 112 | return false; |
113 | 113 | } |
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 | + } |
120 | 122 | } |
121 | 123 | } |
122 | 124 | return array( false, false ); |
— | — | @@ -124,10 +126,39 @@ |
125 | 127 | function getMetadata( $image, $path ) { |
126 | 128 | $metadata = array( 'version' => self::OGG_METADATA_VERSION ); |
127 | 129 | |
| 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 | + |
128 | 160 | if ( !class_exists( 'File_Ogg' ) ) { |
129 | 161 | require( 'File/Ogg.php' ); |
130 | 162 | } |
131 | | - |
132 | 163 | try { |
133 | 164 | $f = new File_Ogg( $path ); |
134 | 165 | $streams = array(); |
— | — | @@ -468,10 +499,15 @@ |
469 | 500 | } else { |
470 | 501 | $length = $this->getLength( $file ); |
471 | 502 | foreach ( $unpacked['streams'] as $stream ) { |
472 | | - $size += $stream['size']; |
| 503 | + if( isset( $stream['size'] ) ) |
| 504 | + $size += $stream['size']; |
473 | 505 | } |
474 | 506 | } |
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 | + } |
476 | 512 | return wfMsg( $msg, implode( '/', $streamTypes ), |
477 | 513 | $wgLang->formatTimePeriod( $length ), |
478 | 514 | $wgLang->formatBitrate( $bitrate ), |
— | — | @@ -804,7 +840,26 @@ |
805 | 841 | } |
806 | 842 | /*utility functions*/ |
807 | 843 | |
| 844 | + |
808 | 845 | /* |
| 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 | +/* |
809 | 864 | * outputs a minimal iframe for remote embedding (with mv_embed loaded via the script-loader if enabled) |
810 | 865 | */ |
811 | 866 | function output_iframe_page( $title ) { |