我想在codeigniter中使用ffmpeg将上传的音频文件转换为mp3。我已将ffmpeg文件放在我的codeigniter根文件夹中。这里是我的代码控制器,
$this->upload->initialize(
array(
"upload_path" => './uploads/',
"overwrite" => FALSE,
"max_filename" => 300,
"encrypt_name" => TRUE,
"remove_spaces" => TRUE,
"allowed_types" => "mp3|amr",
"max_size" => $this->settings->info->file_size,
)
);
if ( ! $this->upload->do_upload('audio_file')) {
$error = array('error' => $this->upload->display_errors());
$this->template->jsonError(lang("error_97") . "<br /><br />" .
$this->upload->display_errors() . "<br />" . mime_content_type($_FILES['audio_file']['tmp_name']));
}
// $data = $this->upload->data();
$data = array('upload_data' => $this->upload->data());
$video_path = $data['upload_data']['file_name'];
$directory_path = $data['upload_data']['file_path'];
$directory_path_full = $data['upload_data']['full_path'];
$file_name = $data['upload_data']['raw_name'];
exec("ffmpeg -i " . $directory_path_full . " " . $directory_path . $file_name . ".mp3");
$file_name = $file_name . '.' . 'mp3';
$audioid = $this->feed_model->add_audio(
array(
"file_name" => $file_name,
"file_type" => $data['file_type'],
"extension" => $data['file_ext'],
"file_size" => $data['file_size'],
"userid" => $this->user->info->ID,
"timestamp" => time()
)
);
接下来使用ffmpeg.Or将音频文件转换为mp3的代码是什么?还有其他方法可以吗?
答案 0 :(得分:0)
您无法使用PHP转换文件,但可以使用 ffmpeg
$ ffmpeg -i input.mp4 output.mp3
在PHP中,您可以使用exec()执行上述命令
exec("ffmpeg -i /path/to/input.mp4 /path/to/output.mp3");