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

Written By: Zeeshan Rasool  |  Posted In: Codeigniter, Web Development


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.

$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().'
'; } 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'); }

If you enjoyed this post, please consider leaving a comment below or subscribing to the RSS feed to have future articles delivered to your feed reader. You can also follow us on Facebook or Twitter @99Points


Zeeshan Rasool is the founder and editor of this blog. Beside this, he is an experienced PHP web developer and freelancer. He loves to create best and interactive web apps. You can follow him at twitter @99_Points and facebook OR drop an email at 99points.info@gmail.com

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

  • shahmy August 14, 2010 at 5:30 am

    Hi To All,
    I was try using this code but it”s not working. please help me.
    Thank You.

  • aboughaly August 18, 2010 at 11:29 pm

    this not work
    please fix this

    ineed it please
    thanks

  • syeda September 19, 2010 at 8:45 am

    how can i install FFMPEG in my PC and include the ffmpeg file in php. please give me the reply as so as possible.

  • ZeeShaN September 19, 2010 at 12:14 pm

    hi,
    For windows, you need to download ffmpeg.exe from ffmpeg site. Just download that file and paste it in main root directory where your project is hosted.
    And just use the simple command with exec(“ffmpeg -i OR system(“ffmpeg ” to get it working.

    For Linux server, you need to install ffmpeg plugin on server but I dont how to install it.
    So you should get some help.

  • Zaraq September 28, 2010 at 7:55 am

    hi i have installed ffmpeg in php also in ffmpeg in root folder that is C:\ffmpeg|ffmpeg.exe

    i uplaoded n convered video files in php but now i m trying to use ths in codeigniter.. to me i see some problems in ur code culd u tell me that this code worked in ur codeigniter..

    u r using this code in controller.. plz help us..

  • ZeeShaN September 28, 2010 at 8:48 am

    Yes im using this code in codeigniter and put ffmpeg.exe in that folder where your project is hosted. c:\wamp\www\yourProjectFolder\ffmpeg.exe
    and then use above code.

    Good Luck !

  • Zaraq September 28, 2010 at 1:30 pm

    (@zeeshan) hi i msged u before but so far u didnt reply, please tell me where is ur code converting video to flv format. it only uploads file so far i ve corrected n run this code.. plz give me ur wise tip.

    thanks.

  • shahmy September 29, 2010 at 7:08 am

    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.

  • ZeeShaN September 29, 2010 at 8:42 am

    @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

  • aungaung January 3, 2011 at 11:33 pm

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

  • aungaung January 4, 2011 at 2:04 am

    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 )

  • momen January 4, 2011 at 9:05 am

    how can take the image from video using ffmpeg

  • Chandra January 25, 2011 at 9:58 am

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

  • ZeeShaN January 25, 2011 at 1:18 pm

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

  • fellipecruz February 7, 2011 at 7:49 pm

    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 ?

  • Davor April 17, 2011 at 7:24 pm

    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?

  • ndiayejp September 19, 2011 at 4:30 pm

    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

  • kaushik February 20, 2012 at 10:55 am

    hello…the flv conversion from mov file is not working..please help………..

  • joe March 9, 2012 at 11:37 am

    hi,
    i have this error
    _____________________________
    Severity: Notice

    Message: Undefined property: Test::$upload

    Filename: controllers/test.php

    Line Number: 22
    ____________________________


    $config['max_width'] = ”;
    $config['max_height'] = ”;

    Line 22 $this->upload->initialize($config);
    $this->load->library(‘upload’, $config);

    if(!$this->upload->do_upload($file))

  • Friv March 11, 2012 at 7:52 am

    Thanks for sharing! I never managed to make this work with Windows hosting and that’s why I have Linux with FFmpeg installed.

  • Student June 30, 2012 at 3:58 am

    may be u should check mime file.

  • webghost December 6, 2012 at 2:55 am

    can you please make a tutorial wherein it allows to upload a csv file,,.match the csv fields to a fields in a certain table in db and if the fields match then it will insert whatever record the csv has,..,please thank you in advance

  • student April 14, 2013 at 1:42 pm

    i am beginner in codeigniter.i don,t know how to upload video,will u say step by step procedure for upload a video?help me plz,

Post comment


Email Subscriber!

Be the first to know about new updates


Advertisement

Categories

Popular post

Recommend