Jun
30

CodeIgniter Tutorial: Upload and Convert video to FLV using FFmpeg.


Today, I will show, how can we upload and convert a video file to flv using FFmpeg in CodeIgniter website. FFmpeg commands runs in Linux but in Window server we need to download FFmpeg.exe file from its site. Which we have to put in our site root folder. IF your server is Linux then you also need verify that your hosting server has FFmpeg installed or you need it to be installed. For checking FFmpeg availability print phpinfo() in any file and run this command on server where you will get PHP version and other server settings. Find FFmpeg on that window if it doesn’t found then it means server has no FFmpeg installed.

Here is uploading code of video file in CodeIgniter.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
$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'); 	
}

Add To Facebook Stumble This Digg This Add To Del.icio.us Add To Reddit Add To Yahoo Add To Twitter


Written by ZeeShaN

ZeeShaN RasooL is a web developer who loves to work in latest technologies to create more interactive dynamic and beautiful web pages.

  • ndiayejp

    a problem i can’t upload the flv the ffmpeg exe doesn’t work ! i install it in my web base application (work on easyphp) ! somedy help me please

    September 19 2011
    CommentsLike

    • If I add 3gp|mp4 it doesn’t work do I need to change something in exec(“ffmpeg -i “.$directory_path_full.” “.$directory_path.$file_name.”.flv”);

      The error is: the file extension is not allowed:
      $config['allowed_types'] = ‘mov|mpeg|mp3|avi|3gp|mp4′; is my allowed hings!
      What can it be?

      April 17 2011
      CommentsLike
      • fellipecruz

        I put the code in the controller, copy the ffmpeg in root folder and make a uploader view, the video is loaded in the host, but still in .mov extension, I tried shahmy solutions but send error, which can be error ?

        February 07 2011
        CommentsLike
        • ZeeShaN

          for windows based server, you should place ffmpeg.exe file in project folder root. But on linux server the ffmpeg should be installed.

          January 25 2011
          CommentsLike
          • Chandra

            Could u tell me ho can i used ffmpeg in wamp server i cant figure it out

            January 25 2011
            CommentsLike
            • momen

              how can take the image from video using ffmpeg

              January 04 2011
              CommentsLike
              • aungaung

                hi, I use xampp version 5. I can not implement ffmpeg. Please, anybody!
                If anybody has ffmpeg files, upload and guide how to implement it on my localhost ( xampp )

                January 04 2011
                CommentsLike
                • aungaung

                  please, give download link for ffmpeg.exe !!!!

                  January 03 2011
                  CommentsLike
                  • ZeeShaN

                    @Zaraq, hi You can get your answer in shahmy’s comment.
                    @Shahmy, You can also put this ffmpeg in same root folder where your project is hosted.

                    Cheers

                    September 29 2010
                    CommentsLike
                    • shahmy

                      Thank You For you post.
                      It is work properly. I was add following exec. Than it work properly.
                      exec(the/path/to/ffmpeg.exe.”ffmpeg -i “.$directory_path_full.” “.$directory_path.$file_name.”.flv”);

                      Thank you.

                      September 29 2010
                      CommentsLike








                      Enter your Email:

                      Click Here for Popular

                      Who I Am

                      Zeeshan Rasool

                      Software Engineer - PHP
                      Lahore - Pakistan

                      zeeshan(@)99points.info
                      Skype: zeeshan-rasool
                      gTalk: zishan.rasool85

                      Categories

                      Tags

                      Comments