PHP处理音频文件 phpffmpeg 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 转帖(未经测试)php剪切或分割mp3文件的一个类并带实例类文件mp3_cut_class.php<?php/*作者:周春电子邮件:xxfaxy#qq.com #换成@微博:http://www.weibo.com/407497716*/class mp3_cut{var $data_buffer=1048576;var $error_message;var $old_file;var $new_file;var $start_time;var $file_size;var $time_length;var $byte_per_second;var $input_data;var $output_data;var $type;function mp3_cut($old_file,$time_length,$new_file,$start_time,$type){$this->old_file=$old_file;$this->new_file=$new_file;$this->start_time=$start_time;$this->time_length=$time_length;$this->type=$type;}function cut(){$this->set_input_file_size();$this->byte_per_second();$this->open_input_mp3();$this->open_output_mp3();$this->make_new_mp3($this->type);$this->close_output_mp3();$this->close_input_mp3();}function set_input_file_size(){$this->file_size=@filesize($this->old_file);}function byte_per_second(){$this->byte_per_second=(integer)($this->file_size/$this->time_length);}function make_new_mp3($type){$start_position=$this->start_time*$this->byte_per_second;if($type==1){fseek($this->input_data,$start_position);while(!@feof($this->input_data)){@fwrite($this->output_data,@fread($this->input_data,$this->data_buffer));}}else{while(@ftell($this->input_data)<=((integer)$start_position)){@fwrite($this->output_data,@fread($this->input_data,($this->byte_per_second/2)));}}}function open_input_mp3(){if(file_exists($this->old_file)){$this->input_data=fopen($this->old_file,"r");$result=true;}else{$this->error("打开文件错误");$result=false;}return $result;}function close_input_mp3(){if(@fclose($this->input_data)){$result=true;}else{$this->error("操作输入文件错误");$result=false;}return $result;}function open_output_mp3(){$this->output_data=@fopen($this->new_file,"w");if($this->output_data){$result=true;}else{$this->error("创建文件错误");$result=false;}return $result;}function close_output_mp3(){if(@fclose($this->output_data)){$result=true;}else{$this->error("操作输出文件错误");$result=false;}return $result;}function error($error_message){$this->error_message.=$error_message."<br>";}}?>例子文件index.php<?phprequire_once("mp3_cut_class.php");$mp3_cut=new mp3_cut("input.mp3",265,"output.mp3",120,0);//输入文件名,输入文件总时间,输出文件名,分割点时间,模式[0保存前段1保存后段]$mp3_cut->cut();echo $mp3_cut->error_message;?> IE源码正常file_get_contents和CURL抓取不到内容,求大牛 求助3 菜鸟请教一个PHP的问题 递归调用自定义函数出现内存使用的问题 firefox 的session疑问,请教各位哥哥 多级分类的数据库排序问题,请各位指点! 高分相送!!!php+odbc的查询问题! 关于父子分类权限继承的问题.求算法. 纯文本的格式显示 session突然不行了,急呀 php调用存储过程后出错Commands out of sync; you can't run this command now win下php5.5.12装不上memcache扩展
类文件
mp3_cut_class.php
<?php
/*
作者:周春
电子邮件:xxfaxy#qq.com #换成@
微博:http://www.weibo.com/407497716
*/
class mp3_cut{
var $data_buffer=1048576;
var $error_message;
var $old_file;
var $new_file;
var $start_time;
var $file_size;
var $time_length;
var $byte_per_second;
var $input_data;
var $output_data;
var $type;
function mp3_cut($old_file,$time_length,$new_file,$start_time,$type){
$this->old_file=$old_file;
$this->new_file=$new_file;
$this->start_time=$start_time;
$this->time_length=$time_length;
$this->type=$type;
}
function cut(){
$this->set_input_file_size();
$this->byte_per_second();
$this->open_input_mp3();
$this->open_output_mp3();
$this->make_new_mp3($this->type);
$this->close_output_mp3();
$this->close_input_mp3();
}
function set_input_file_size(){
$this->file_size=@filesize($this->old_file);
}
function byte_per_second(){
$this->byte_per_second=(integer)($this->file_size/$this->time_length);
}
function make_new_mp3($type){
$start_position=$this->start_time*$this->byte_per_second;
if($type==1){
fseek($this->input_data,$start_position);
while(!@feof($this->input_data)){
@fwrite($this->output_data,@fread($this->input_data,$this->data_buffer));
}
}
else{
while(@ftell($this->input_data)<=((integer)$start_position)){
@fwrite($this->output_data,@fread($this->input_data,($this->byte_per_second/2)));
}
}
}
function open_input_mp3(){
if(file_exists($this->old_file)){
$this->input_data=fopen($this->old_file,"r");
$result=true;
}
else{
$this->error("打开文件错误");
$result=false;
}
return $result;
}
function close_input_mp3(){
if(@fclose($this->input_data)){$result=true;}
else{
$this->error("操作输入文件错误");
$result=false;
}
return $result;
}
function open_output_mp3(){
$this->output_data=@fopen($this->new_file,"w");
if($this->output_data){$result=true;}
else{
$this->error("创建文件错误");
$result=false;
}
return $result;
}
function close_output_mp3(){
if(@fclose($this->output_data)){$result=true;}
else{
$this->error("操作输出文件错误");
$result=false;
}
return $result;
}
function error($error_message){
$this->error_message.=$error_message."<br>";
}
}
?>
例子文件
index.php
<?php
require_once("mp3_cut_class.php");
$mp3_cut=new mp3_cut("input.mp3",265,"output.mp3",120,0);
//输入文件名,输入文件总时间,输出文件名,分割点时间,模式[0保存前段1保存后段]
$mp3_cut->cut();
echo $mp3_cut->error_message;
?>