文字

Examples on using the ogg:// wrapper.

Example #1 Reading an OGG/Vorbis file

<?php
dl
( "oggvorbis.so" );


$fp  fopen ( 'ogg://myaudio.ogg' 'r' );


$metadata  stream_get_meta_data ( $fp );


$songdata  $metadata [ 'wrapper_data' ][ 0 ];

echo 
"OGG/Vorbis file encoded by:  { $songdata [ 'vendor' ]} \n." ;
echo 
"   { $songdata [ 'channels' ]}  channels of  { $songdata [ 'rate' ]} Hz sampling encoded at  { $songdata [ 'bitrate_nominal' ]} bps.\n" ;
foreach(
$songdata [ 'comments' ] as  $comment ) {
    echo 
"   $comment \n" ;
}

while (
$audio_data  fread ( $fp 8192 )) {
  

}

fclose ( $fp );

?>

Example #2 Encode an audio file to OGG/Vorbis

<?php
dl
( 'oggvorbis.so' );

$context  stream_context_create (array( 'ogg' =>array(
             
'pcm_mode'  =>  OGGVORBIS_PCM_S8 ,  
             
'rate'  =>  44100 ,                 
             
'bitrate'  =>  0.5 ,                
             
'channels'  =>  1 ,                 
             
'serialno'  =>  12345 )));          


$ogg  fopen ( 'ogg://mysong.ogg' 'a' false $context );

$pcm  fopen ( 'mysample.pcm' 'r' );


stream_copy_to_stream ( $pcm $ogg );

fclose ( $pcm );
fclose ( $ogg );
?>
上一篇: 下一篇: