Reputation: 409
I want to convert uploaded audio files to mp3 with ffmpeg in codeigniter.I've put the ffmpeg files in my codeigniter root folder.And here is my code controller,
$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()
)
);
Next what is code to convert the audio file to mp3 using ffmpeg.Or any other way to do this?Can anybody suggest me?
Upvotes: 0
Views: 1282
Reputation: 7080
You cannot convert files using PHP but you can use ffmpeg
$ ffmpeg -i input.mp4 output.mp3
in PHP you can use exec() to execute above command
exec("ffmpeg -i /path/to/input.mp4 /path/to/output.mp3");
Upvotes: 1