Upload and Convert video to FLV using FFmpeg in Codeigniter

PHP CMS Frameworks November 04, 2012 4 comments

In this article, we are going to discuss about How to upload and convert video into FLV format using FFMpeg in Codeigniter. FFMpeg commands are running only in Linux environment. If you want to use it in windows, you need download ffmpeg.exe file. Click here to download FFMpeg.exe. Download the FFmpeg executable file and place it in your root folder. If you are using Linux server, Use print phpinfo() function to check whether your hosting server has FFmpeg installed or you need it to be installed.

Use the below code for uploading and converting the video file in Codeigniter.

$file = 'video_file';
$config['upload_path'] = './video_folder/';
$config['allowed_types'] = 'mov|mpeg|mp3|avi';
$config['max_size'] = '50000';
$config['max_width']   = '';
$config['max_height']   = '';

$this->upload->initialize($config);
$this->load->library('upload', $config);

if(!$this->upload->do_upload($file))
{
// If there is any error
$err_msgs .= 'Error in Uploading video '.$this->upload->display_errors().'<br />';
}
else
{
$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'];

// ffmpeg command to convert video

exec("ffmpeg -i ".$directory_path_full." ".$directory_path.$file_name.".flv"); 

// $file_name is same file name that is being uploaded but you can give your custom video name after converting So use something like myfile.flv.

/// In the end update video name in DB 
$array = array(
'video' => $file_name.'.'.'flv',
);
$this->db->set($array);
$this->db->where('id',$id); // Table where you put video name
$query = $this->db->update('user_videos');
}

Comments · 4

?
PHP CMS Frameworks
11 November 2012 at 04:21
Thank you for your feedback.
?
Unknown
21 February 2014 at 21:20
Thanks buddy... it helped me a lot...
?
Unknown
24 March 2014 at 13:09
I am trying to use this code but i need a sample file to figure out how it works.

Could you please share the sample file for me ?

Thanks from now
?
Unknown
24 March 2014 at 13:09
I am trying to use this code but i need a sample file to figure out how it works.

Could you please share the sample file for me ?

Thanks from now

Post a Comment