In this post will show you how to upload and convert a video file to FLV using FFmpeg in CodeIgniter Application.
If your hosting server in windows , you need to download FFmpeg.exe file from FFmpeg official website, and put it in your root folder.
if your hosting server in Linux , you need to install FFmpeg, to check FFmpeg availability print phpinfo(),Find FFmpeg on that window if it doesn’t found then it means your server has not installed FFmpeg.
Note : FFMpeg commands are running only in Linux environment.
Form View – This is for uploading video
Select Video : | |
Controller function
upload->initialize($config); $this->load->library('upload', $config); if(!$this->upload->do_upload()) { // If there is any error $err_msgs .= 'Error in Uploading video '.$this->upload->display_errors().'
'; } else { $upload_data= $this->upload->data(); $video_path = $upload_data['file_name']; // ffmpeg command to convert video exec("ffmpeg -i ".$upload_data['full_path']." ".$upload_data['file_path'].$upload_data['raw_name'].".flv"); /// In the end update video name in DB $array = array('video' => $upload_data['raw_name'].'.'.'flv'); $this->db->set($array); $query = $this->db->update('videos_tbl'); } } ?>
Requirements
1.Create folder called “video” in the root folder
2.sometimes mime types has to be added for flv and wmv.so add the following lines into config->mimes.php file
'wmv' => array('video/wmv', 'video/x-ms-wmv', 'flv-application/octet-stream', 'application/octet-stream'), 'flv' => array('video/flv', 'video/x-flv','flv-application/octet-stream', 'application/octet-stream'),
3.Need to increase the maximium upload size of php.ini if you need to upload a video size of more than 2MB (Deafult is 2M).
change following line in php.ini (Here I have add 10M.)
upload_max_filesize = 10M
For more information on increasing file upload limit visit my previous post : How to Increase file size upload limit using .htaccess ?
How do i Create video thumbnails using ffmpeg?
we can generate thumbnails in Linux using ffmpeg with single command shown below
ffmpeg -itsoffset -5 -i pathToVideoFile.avi -vcodec mjpeg -vframes 1 -an -f rawvideo -s 400x600 path/To/Destination/Folder/test.jpg
This command generates a 400×600 sized thumbnail at the 5th second in the video.