ffmpeg sample code

ffmpeg

Install ffmpeg library in your server first.

Place a video file of any type on current directory (or anywhere), here it is clock.avi .

Click more for source code:

PHP
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
extension_loaded('ffmpeg') or die('Error in loading ffmpeg');
$ffmpegInstance = new ffmpeg_movie('clock.avi');
echo "getDuration: " . $ffmpegInstance->getDuration() .
"getFrameCount: " . $ffmpegInstance->getFrameCount() .
"getFrameRate: " . $ffmpegInstance->getFrameRate() .
"getFilename: " . $ffmpegInstance->getFilename() .
"getComment: " . $ffmpegInstance->getComment() .
"getTitle: " . $ffmpegInstance->getTitle() .
"getAuthor: " . $ffmpegInstance->getAuthor() .
"getCopyright: " . $ffmpegInstance->getCopyright() .
"getArtist: " . $ffmpegInstance->getArtist() .
"getGenre: " . $ffmpegInstance->getGenre() .
"getTrackNumber: " . $ffmpegInstance->getTrackNumber() .
"getYear: " . $ffmpegInstance->getYear() .
"getFrameHeight: " . $ffmpegInstance->getFrameHeight() .
"getFrameWidth: " . $ffmpegInstance->getFrameWidth() .
"getPixelFormat: " . $ffmpegInstance->getPixelFormat() .
"getBitRate: " . $ffmpegInstance->getBitRate() .
"getVideoBitRate: " . $ffmpegInstance->getVideoBitRate() .
"getAudioBitRate: " . $ffmpegInstance->getAudioBitRate() .
"getAudioSampleRate: " . $ffmpegInstance->getAudioSampleRate() .
"getVideoCodec: " . $ffmpegInstance->getVideoCodec() .
"getAudioCodec: " . $ffmpegInstance->getAudioCodec() .
"getAudioChannels: " . $ffmpegInstance->getAudioChannels() .
"hasAudio: " . $ffmpegInstance->hasAudio();

//___________________________________Code end here_____________________________________

I also can be used for file format conversion

Eg: exec(‘ffmpeg -i ‘.$SourcePath.’ ‘.$Destination);

Here $SourcePath any file of any format , and destionation also another format.

eg: exec(‘ffmpeg -i saji.3gp saji.flv’);

95 Comments , , ,

95 Responses to “ffmpeg sample code”

  1. Rottenberg August 5, 2007 at 12:42 pm #

    Hi,
    I’m seaching how to transcode various videos type to .flv.

    Do you know where can I find informations about all parameters to use in the exec (ffmpeg…)

    thank your for your help

    best regards

    Michel

  2. Adrian December 30, 2007 at 1:43 am #

    Does anyone know the command to implement the water mark feature. I’ve installed eveything and it works fine i just need to know how to use the water mark feature.

    thanks

  3. naveen February 7, 2008 at 12:24 pm #

    friend, i am using a pre compiled ffmpeg in my shared server(RHEL) and the output flv that i got has no audio(libmp3lame.so is missing).
    Since i dont have shell access to the server i asked our hosting team to install it for us.The installation path looks like usr/local/bin .. and /lib for libraries..all the required files are there but i am not able to execute ffmpeg within my php program.
    can u please suggest a solution for this.

  4. Sajith M.R February 7, 2008 at 12:34 pm #

    The installation of ffmpeg is pretty crap. You need to compile the ffmpeg with libmp3lame enabled. Since you didnt have root access, its more difficult, and your hosting solution provider may not aware of this installation procedure. So instead of ffmpeg, you can use mencoder. Tell them to install mencoder in your server. The usage of mencoder can be found from this blog itself. http://www.sajithmr.com/mencoder-video-convertion-tool/

  5. naveen February 7, 2008 at 2:36 pm #

    Hi
    Thanks for ur reply.
    Can we get a ffmpeg exectable binary which also contain libmp3lame.Which means it will b a single exectable library.

  6. Sajith M.R February 7, 2008 at 2:43 pm #

    Hello Naveen

    You can get ffmpeg executables for windows. But for linux machine you need to install it after proper compilation. Since it is utter configurable and flexible, you need to MAKE it for your own use. FFMPEG Sound problem is a big problem in various linux os. Download full ffmpeg from source forge and compile it by enabling all the options. Since you did nt have root access, it is depending with your provider. More over application like ffmpeg , mencoder etc, root accessed server is a must !!!

  7. naveen February 23, 2008 at 12:06 am #

    hello sajith,
    do u know how to create an html thumbnail view , provided an url as input in php or javascript.Similar to a screen shot .
    We are trying it on a linux server.

  8. KiduMon March 15, 2008 at 4:56 pm #

    Hello Sajith,

    While uploading my small files are convert into flv with out any issue..

    But with big files (>1MB) is not converting.. please help me..

    This is my code…

    $srcWidth = “320″;
    $srcHeight = “240″;
    $srcAB = “32″;
    $srcAR = “22050″;
    exec($ffmpegPath . ” -i ” . $srcFile . ” -ar ” . $srcAR . ” -ab ” . $srcAB . ” -f flv -s ” . $srcWidth . “x” . $srcHeight . ” ” . $destFile . ” | ” . $flvtool2Path . ” -U stdin ” . $destFile);

    Thanks in advance

  9. Sajith M.R March 15, 2008 at 5:10 pm #

    I dont think size of file is a problem for ffmpeg. Instead checking through your web browser with exec command, go to shell / command prompt and check using ffmpeg function call directly.

    I think your problem is web server’s file uploading, see your webserver’s uploading file size limit in configuration . Do unit testing , means test one by one, first convertion on multiple type/size files using ffmpeg command directly, and if everything works fine, test with php library. OKay

    (you can use mencoder also for video convertion)
    http://www.sajithmr.com/mencoder-video-convertion-tool/

    Thanks
    Sajith

  10. KiduMon March 15, 2008 at 5:23 pm #

    Thanks sajith,

    I tried it all that way.. I changed webserver’s uploading file size limit to 10M

    1. Files 1MB moves to the desired folder but when it comes to the converted folder size seems to 0kb

    That means it’s not get converted , am i right?

    Please help me!!!

  11. Sajith M.R March 15, 2008 at 6:15 pm #

    You can see the error message while you apply the command ffmpeg direclty from command prompt. see the error log or messages arrive when you try to convert big file.
    I repeat , never try it through php or apache , try directly from command prompt to see what actually happening behind. if there is a convertion, it shows result like input:thisfile.3gp output: thatfile.flv etc etc audio: video: etc. Okay

    Thanks
    Sajith

  12. KiduMon March 15, 2008 at 7:26 pm #

    Sajith,

    Undefined method ‘timestamp’ for nil:Nillclass
    and alist of errors…

    help me..

  13. Sajith M.R March 15, 2008 at 7:30 pm #

    Sorry Chanchel, I am not familiar with this error :( And when i googled it , nothing listed. Try some other files , i dont think it’s compilation error of ffmpeg, or try mencoder.

  14. Jonathan March 25, 2008 at 11:36 am #

    Hi Mr Sajith,

    Im wondering if you can point out much clearer on how to convert videos using ffmpeg through php script. Ive been trying to do this for a week and still no progress. I tried:

    exec(“ffmpeg -i ‘inputFile.avi’ ‘outputFile.flv’”);

    but to no effect. Is there a problem with exec() function in PHP in converting this videos? I tried using your tutorial and I managed to run it properly but converting them is really painful. :(

    Need some help.

  15. Sajith M.R March 25, 2008 at 11:44 am #

    Hi Jonathan,
    ffmpeg is not a php function or script to convert video files. It is an application. Before you convert files from php, you have to check the ffmpeg binary working from your command prompt(windows) or shell (linux) , by typing

    ffmpeg -i ‘inputFile.avi’ ‘outputFile.flv

    For its 100% working , you have to install ffmpeg properly with libamr, lame etc support for all file format including 3gp (if you want). If it works fine in shell, your ffmpeg is okay. Exec is only a php function for executing shell commands. So if the former settings are okay, the rest will work without any error.

    • velu January 4, 2012 at 12:31 pm #

      i use win xp run ffmpeg successfuly in dos but in php exec not working plz help me

  16. Jonathan March 25, 2008 at 11:49 am #

    I have tried working with ffmpeg on a shell client, command prompt to be more specific and it is working fine on a command line. What I need to do is to access ffmpeg through php script. I have a webserver which records a video and I need to convert those videos to other formats.

    Thanks.

  17. Sajith M.R March 25, 2008 at 11:50 am #

    And when i tried ffmpeg in windows, everything worked very well. But when i tried in linux everything ok except the audio for flv output. When we convert some files into flv , there was no audio output. Since our server for mobshare was linux, i installed all the libraries for sound (mp3lame, amrlib etc).

    On that time, i got mencoder, another video converting tool in linux (Backend of mplayer), and it worked very well with all format. So in our site http://www.mobshare.in , we are using mencoder for video conversion . See my post on mencoder from
    http://www.sajithmr.com/mencoder-video-convertion-tool/

  18. Sajith M.R March 25, 2008 at 11:57 am #

    Hi Jonathan,
    Then you are using windows os in your php server. Then you have to do some more security thing with apache configuration. You have to change the safe_mode option in httpd.conf file for executing exec commmand from php script. If there is any antivirus etc running , these all affect the execution of exec command.

    When safe mode is enabled, you can only execute executables within the safe_mode_exec_dir

    See this: http://in.php.net/function.exec

    And do the needful for windows security configuration

    Regards
    Sajith

  19. Jonathan March 25, 2008 at 12:06 pm #

    Sorry If I havent informed the situation very well. The webserver is running on Debian Linux. I used red5 server to accomplish the Record and Audio Capture things. Now what I need to do is to convert the files recorded to other formats using ffmpeg through php classes/scripts.

    I have checked the phpinfo(); of the site and the safe mode is turned to off. I am wondering what I could be missing in here. Is my exec(); line command enough or is there something I might have not include? Shall I use flvtool2 too? Like I have seen others have done after converting a file? if so, how would it be?

  20. Sajith M.R March 25, 2008 at 12:17 pm #

    If the ffmpeg is working well through shell, your ffmpeg installation and configuration is okay. Now from your comment, i got that, you could not initiate or execute same thing via php code. And your exec is not working as you expected, right ?

    try $result = exec(“whoami”); and echo the $result

    When you run exec from php, the user of linux will be apache (not all time, commonly apache) and when you try this using command prompt, the user will be root or some other else. Here also the permission problem.

    anyway echo the result of exec, sothat you can see what is the error. place the files to be converted under apache’s web root and give needful permissions. (try with 777)

    Some simple debugging can solve your problem. Please be patient and check apache’s error log after call exec function. if error log is disabled, enable it from httpd.conf and point a file to show error log.

    In another terminal , open that error file using tale command ( http://www.sajithmr.com/tail/ ) so that you can see the live error reporting.

    From these , i am damn sure, you can solve your exec ffmpeg issue. Be confident and go on :)

    Regards
    Sajith

  21. Jonathan March 25, 2008 at 12:20 pm #

    Thank you and I will try what you have advised. I will inform you the progress as I go along and thanks for the help. Also, the cheering helps. :)

    Jonathan

  22. Jonathan March 26, 2008 at 7:53 am #

    Hi mr Sajith,
    I tried executing ffmpeg via SSH client. When i type ‘ffmpeg’ an error occurs which says:

    “ffmpeg: error while loading shared libraries: libvorbisenc.so.2: cannot open shared object file: No such file or directory”.

    Does it mean I didnt compile libvorbis or other stuffs the way it should be? If so.. What should I do so that ffmpeg can detect it?

    Thanks in advance.
    Jonathan

  23. Sajith M.R March 26, 2008 at 8:56 am #

    At last you found your ffmpeg is not working properly from ssh. This is what i am telling from the beginning. This is called atomic testing. Test one by one before testing the whole system. So make sure to compile ffmpeg by enabling all the libraries.

    The compilation process is not that much simple. You need to compile it very carefully.

  24. Jonathan March 26, 2008 at 9:01 am #

    Do I have to do the ‘./configure && make && make install’ to each and everyone again? FFmpeg seems to be trying to open a file from the shared libraries which is called libvorbisenc.so.2. I dont know where to start, Im thinking what folder is the shared libraries and if I can just put the file which ffmpeg is searching for?

  25. Sajith M.R March 26, 2008 at 9:08 am #

    a single line can enable all the libraries … like
    –enable mp3laame -enable lib etc

    See this link: http://groups.google.com/group/ffmpeg-php/web/installing-ffmpeg-and-ffmpeg-php-on-centos

    It might be a useful one for you.

    Use google properly for perfect installation. when ever an error comes, paste the exact sentence on google. it will lead you to the exact page.

    Regards
    Sythoos

  26. Jonathan March 26, 2008 at 1:03 pm #

    Hi,

    I used this command on my shell ldd ‘which ffmpeg’ and it gives me this output:

    linux-gate.so.1 => (0xffffe000)
    libavdevice.so.52 => /usr/lib/libavdevice.so.52 (0x4001d000)
    libavformat.so.52 => /usr/lib/libavformat.so.52 (0×40024000)
    libavcodec.so.51 => /usr/lib/libavcodec.so.51 (0x400bd000)
    libavutil.so.49 => /usr/lib/libavutil.so.49 (0x4054d000)
    libm.so.6 => /lib/libm.so.6 (0x4055c000)
    libc.so.6 => /lib/libc.so.6 (0×40581000)
    libz.so.1 => /usr/lib/libz.so.1 (0x4069c000)
    libdl.so.2 => /lib/libdl.so.2 (0x406b0000)
    libmp3lame.so.0 => /usr/lib/libmp3lame.so.0 (0x406b4000)
    /lib/ld-linux.so.2 (0×40000000)
    libvorbisenc.so.2 => not found
    libvorbis.so.0 => not found

    It seems that the last two files were missing, and I just want to ask/confirm that if I just get this files and just put it inside the ‘/usr/lib’ folder, does it have any possibility of solving the problem? I tried recompiling the libvorbis but to no effect. Thanks

  27. Sajith M.R March 26, 2008 at 1:15 pm #

    I dont know linux libraries in deep. In my case i used ubuntu. All were in a simple step using apt-get install ffmpeg … So it is working fine there.

    http://wiki.kartbuilding.net/index.php/Ffmpeg

    The manual configuration sometimes become very crap. And in my radhat server i used mencoder for video conversion.

    Once the ffmpeg installed well, i can help you in php part. But all the minimum thing needed is, set the ffmpeg RUN

  28. Jonathan March 27, 2008 at 8:08 am #

    Hi,
    Finally ffmpeg run through shell command and now I can execute it via php script. Im just thinking and maybe you can help me out. Here is the situation:

    The thing is I am recording a video via red5 server and it automatically saves the video to a .flv file. I converted a lot of .flv video via ffmpeg but the video recorded through the server is different. Along with the flv file it has its .meta file.
    I dont know what it was but all I know if I have for example a ‘test.flv’ along with it is ‘test.flv.meta’ and when i try to convert it via ffmpeg it says unsuported format. Do you have any ideas what should be done or is it possible for ffmpeg to convert it?

  29. Sajith M.R March 27, 2008 at 10:18 am #

    Hi Jonathan,

    I have no experience with red server. From my bare knowledge , i guess the following things:

    If there is a meta file with .flv , it will be an xml format file or something to save the extra attribute of .flv file. It might be latest flash player’s settings. In new flash players (8) the meta file also load with the flv file and retrieve attributes from that meta and plays . The process is called flv meta injector.

    And ffmpeg conversion problem. Since ffmpeg is an opensource and its development is still on, latest flv version might not be supported. These all are my guess, not from real knowledge. Check your red server configuration for recording video in older flv format , or without meta injection or something.

    And for which website, you are doing these things ? If it is private, need not to mention. Just asked.

    Anyway
    Go on
    Sajith

  30. Jonathan March 29, 2008 at 8:48 am #

    Its me again, :)
    I just wanted to ask if it is possible to join two audio file in ffmpeg or mencoder.. I’ve successfully joined two video file through mencoder but I cant find a possible command to join two audio file. I tried something like:

    copy audio1.mp3 audio2.mp3 > final.mp3

    But it just create a file that has 1Kb. :( Is there a way to join audio files using this applications??

  31. VKS March 29, 2008 at 9:59 am #

    Hi Sajith,
    I have requrment to to record a video file from remote client machine’s webcam(from browser) to the server machine.Is it possible by using ffmpeg.Iam using PHP and apache server for my development.Is it possible by using ffmpeg.any idea.

    Thanks,
    VKS.

  32. VKS March 31, 2008 at 2:50 pm #

    Hi Jonathan,
    One question, how u use the RED server from PHP.I think it is running in JAVA, is it possible to use from PHP?

    Thanks,
    VKS

  33. Sajith M.R April 2, 2008 at 1:12 pm #

    Hi Jonathan, i did nt try audio joining yet. :)
    And please clear the doubt of VKS in this thread regarding red server.

    Thanks
    Sajith

  34. Jonathan April 2, 2008 at 1:24 pm #

    Hi VKS, regarding your question, I am running it via Macromedia Flash, Flash connects through red5 server that is how web recording is achieved. Anyway, I didnt use PHP in web recording, but if I would, I believe Flash would stand as a middleman between PHP and Red5. But I do not have enough knowledge as of now, Im still exploring it.
    And by the way, Sajith, I have achieved audio concatenation/joining through mencoder.
    But do you have any idea if mencoder can join two audio and play them together, like overlaying an audio to another audio? That they would play together at the very start of the track?

  35. Sajith M.R April 2, 2008 at 1:33 pm #

    Joathan, from these thread i got the info that you are a very good programmer, and regarding this mencoder merging, might be you are the apt person to solve this audio merging b’cause i stopped all the mencoder works when my video to flv conversion done :)

    Anyway, was a good discussion with you .

  36. Jonathan April 2, 2008 at 1:41 pm #

    I see.. Anyway I just want to let you know that I appreciate what you contributed and it really helped me from the very start. Thanks and this thread is awesome. :D

  37. naveen April 6, 2008 at 3:39 pm #

    Hello sajith,

    do u know any free tools that can be used to convert pdf to swf .if u have done any flick magazine app before in flash and php please let me know the issues come under it.
    thanks

  38. Sajith M.R April 7, 2008 at 1:00 pm #

    I have no idea about PDF to SWF (FLASH) Conversion. Sorry naveen

  39. ovidiu July 23, 2008 at 7:43 pm #

    Holo
    I want to use the information from exec(‘ffmpeg -i file1 file2′,$output,$return_var);
    If I run the ffmpeg command from shell it is OK a lot of information is dispayed after, echo return_var is 0 so it is OK but the $output is always empty in PHP.

    Any ideeas?

    ovidiu

  40. sarayu July 25, 2008 at 1:18 pm #

    Hi Sajith,

    I converted video files into flv in cmd prompt successfully .But when i try to use to convert this in my php file by using exec command
    it wont be converted.can u plaese help me about this.Here is my code. The exec for “hello World” is executed successfully.But the 2nd
    exec command could not be executed.

    $in = “../FFmpeg/monkeydog.wmv”;
    $out = “../FFmpeg/mn.flv”;
    $ffmpegPath = “../FFmpeg/ffmpeg”;
    echo exec(‘echo Hello World!’);
    exec(‘$ffmpegPath -i $in -ar 22050 -ab 32 -f flv $out’);

  41. Gyan August 12, 2008 at 2:05 pm #

    Hi Sajith,

    i want to convert wmv file to flv but i am not success.
    please help to this conversion.
    ffmpeg is already installed on server

    please open the iduce.com/test.php

    from here you can download the file and check what is the mistake and you can also check my server inf at given bottom link

    thanks
    and regards

  42. sridhar August 21, 2008 at 4:49 pm #

    how to keep play,stop,pause buttons for swf file.
    please help me

  43. Tamer Qtaish August 21, 2008 at 7:30 pm #

    Hello Sajith!
    Don’t worry I am not going to ask you any questions, not yet…
    I just got started to read about ffmpeg, I am considering it as one of my strong options for a project I am doing.
    So while I was doing my search I stumbled on this form.
    I was both amazed and surprised by how you don’t only have the knowledge but also share it freely! I like went through all the question and answers… Lots of details and crystal clear answers.

    So to sum it up I just want to say “GREAT JOB”
    And thank you!

    All the best,
    Tamer Qtaish

  44. Sajith M.R August 21, 2008 at 7:49 pm #

    Thank you Tamer, Ideas and knowledge are always for sharing… it grows as you share it… don’t let anyone to re-invent the same wheel , so share :)

  45. izero August 28, 2008 at 1:51 pm #

    Why you do not use fflib.net? Try http://www.intuitive.sk/fflib/

  46. Yedhumohan September 1, 2008 at 2:50 pm #

    i have done flv conversion in command prompt.But once i tried with php script,conversion has not been done

  47. rammy September 19, 2008 at 2:14 am #

    hi sajith i have doubt first i want to know spouse i host my website and ffmpeg not installed can i install or i have to contact webhosting service and how i can change mov,avi in flv with specific resolution

  48. rahman October 4, 2008 at 10:46 pm #

    i am the newbie for ffmpeg,i want to know it is a script or application,where can i run this file in my local server(mypc)
    give basic idea,i am using windows,i need reply from u brother

  49. s October 27, 2008 at 7:24 pm #

    i hate linux and i hate those who built this stupid ffmpeg only for linux ! fuck you geek

  50. jdj November 7, 2008 at 6:41 am #

    It seems as if you need to get a web host that has the ffmpeg library for php so that you can execute the ffmpeg commands with exec(). I found documentation of ffmpeg: http://ffmpeg.mplayerhq.hu/ffmpeg-doc.html that helped out a lot. I assume that the exec() function requires parameters that can be found in the ffmpeg documentation such as:

    exec(ffmpeg -f oss -i /dev/dsp -f video4linux2 -i /dev/video0 /tmp/out.mpg)

  51. hans November 15, 2008 at 12:45 am #

    Question I am trying to solve is this. We have flash based property tour tool that takes photos of property listings and displays them in sequence. Is there a way to take the swf that is displayed typically in a browser window and capture 30 seconds of it and convert to mpg using ffmpeg? Thanks in advance.

  52. hans November 15, 2008 at 12:47 am #

    or please let me know if there is another way to accomplish this… thanks.

  53. boja November 19, 2008 at 11:16 pm #

    Hi,
    first of all i would thank you every one, i have learn lot from this discussion.
    i’m having the same problem exec(‘ffmpeg ..’) is not working on my server. i have read all the previous comments & tried those actions
    but the problem is still remaining. ffmpeg is working fine in my terminal & not working through my php code with exec(‘ ‘)

    i have check error_log file; it’s saying(also tried with whoami..)

    sh: /whoami: No such file or directory
    sh: /pwd: No such file or directory
    sh: /ffmpeg: No such file or directory

    the file path is correct & it has this file permissions(i hv tried with chmod -R 777 filename)

    -rwxrwxrwx 1 apache

    please help me to solve this!

    my server details are:

    Linux and OS is Fedora ,Apache/2.2.3 (Fedora),PHP Version 5.2.6

  54. Rohit February 26, 2009 at 11:05 am #

    Hey
    I have implemented the ffmpeg in the site, But it is not working well, Problem is the it takes too much time to upload the videos.can any one tells me how i can make it fast

  55. vasu February 26, 2009 at 2:02 pm #

    hi
    how do i strip a certain section of a video(m3). say to post 5-10 sec audio to listen b4 some1 dwnloads it.. using ffmpeg

    thanx
    vasu

  56. Sajith M.R February 27, 2009 at 7:10 am #

    @Rohit
    To work the uploading fast, do a queuing machanism for converting videos. See the implementation in mobshare.in

    Register there and upload a pic, it wont come that time, instead a processing symbol will be shown. The real image will be displayed after a little bit time of processing

  57. Rohit February 27, 2009 at 10:15 am #

    Hey
    Thanks for reply me. This is my site link http://www.iceageadultvideo.com.Please register here and upload any video. I am facing two problems in this site.One it takes too much time in uploading the videos and second in flash player i wanna fast speed flash player. I will be very thankful to you if u can help me in this

  58. Rohit February 27, 2009 at 12:11 pm #

    Hey
    when i enter the above like this
    extension_loaded(‘ffmpeg’) or die(‘Error in loading ffmpeg’);

    $ffmpegInstance = new ffmpeg_movie(‘http://iceageadultvideo.com/flvideo/102.flv‘);
    echo “getDuration: ” . $ffmpegInstance->getDuration() .
    “getFrameCount: ” . $ffmpegInstance->getFrameCount() .
    “getFrameRate: ” . $ffmpegInstance->getFrameRate() .
    “getFilename: ” . $ffmpegInstance->getFilename() .
    “getComment: ” . $ffmpegInstance->getComment() .
    “getTitle: ” . $ffmpegInstance->getTitle() .
    “getAuthor: ” . $ffmpegInstance->getAuthor() .
    “getCopyright: ” . $ffmpegInstance->getCopyright() .
    “getArtist: ” . $ffmpegInstance->getArtist() .
    “getGenre: ” . $ffmpegInstance->getGenre() .
    “getTrackNumber: ” . $ffmpegInstance->getTrackNumber() .
    “getYear: ” . $ffmpegInstance->getYear() .
    “getFrameHeight: ” . $ffmpegInstance->getFrameHeight() .
    “getFrameWidth: ” . $ffmpegInstance->getFrameWidth() .
    “getPixelFormat: ” . $ffmpegInstance->getPixelFormat() .
    “getBitRate: ” . $ffmpegInstance->getBitRate() .
    “getVideoBitRate: ” . $ffmpegInstance->getVideoBitRate() .
    “getAudioBitRate: ” . $ffmpegInstance->getAudioBitRate() .
    “getAudioSampleRate: ” . $ffmpegInstance->getAudioSampleRate() .
    “getVideoCodec: ” . $ffmpegInstance->getVideoCodec() .
    “getAudioCodec: ” . $ffmpegInstance->getAudioCodec() .
    “getAudioChannels: ” . $ffmpegInstance->getAudioChannels() .
    “hasAudio: ” . $ffmpegInstance->hasAudio();

    in my site of one video. It gives me following description.please tell me how i can get excellent quality video from this which will buffer too much

    getDuration: 14.89getFrameCount: 445getFrameRate: 29.9166660309getFilename: http://iceageadultvideo.com/flvideo/102.flvgetComment: getTitle: getAuthor: getCopyright: getArtist: getGenre: getTrackNumber: 0getYear: 0getFrameHeight: 1200getFrameWidth: 1600getPixelFormat: yuv420pgetBitRate: 64000getVideoBitRate: getAudioBitRate: 64000getAudioSampleRate: 22050getVideoCodec: flvgetAudioCodec: mp3getAudioChannels: 2hasAudio: 1

  59. Rohit February 27, 2009 at 12:30 pm #

    Hey
    Any one tell me which is best bit rate in ffmpeg so videos will low in buffering in video player

  60. PJaxon March 9, 2009 at 9:34 am #

    @ Rohit…. `best` is such a subjective term. Low quality bitrates are less than 300k, but then your video will get pixelated. If you use the -sameq switch in your ffmpeg command, then the quality will be as high as the original, but then it could stream slowly depending upon your server, the bandwidth coming out of it, the bandwidth of your users, and their machine spec’s. I like 500k bitrates, personally.

    @Sajith: Thanks for the function list. Now I can make my encoding engine smarter.

  61. Rohit March 12, 2009 at 9:58 am #

    Hey
    Any one can tell me solution of pixlated video.Please see this link http://www.iceagevideo.com.In this video is pixlated. I am using ffmpeg to convert the video format to flv.I am also using -sameq in the ffmpeg command. Any one tell me solution then video will be clear

  62. narayana March 19, 2009 at 10:04 am #

    hi.
    thanks for your work. i am happy. I hope you will work better in coming days.
    Narayana
    kathmandu
    Nepal

  63. John April 1, 2009 at 5:13 am #

    Please help me

    How can I join two flv files ?

  64. raman May 28, 2009 at 4:56 pm #

    iam looking for ffmpeg php windows dll files, how to setup ffmpeg in wamp could you please help in this regard.

  65. srinivas June 1, 2009 at 1:00 pm #

    hi,
    i have windows sever, i am using php for developing any video to flv using ffmpeg. please provide the php code for converstion any video to flv on fly.

    thank you.

  66. srinivas June 6, 2009 at 12:17 pm #

    hi,
    i need conversion of any video to ‘.flv’ using FFMPeg on fly in php code. this is need to done by uploading a video

    thank you.

  67. Ujjwal Das June 13, 2009 at 9:50 pm #

    Hello Expert,

    I am trying to convert into .flv file from other format.

    i am using this command
    $srcFile = “/home/amitadut/public_html/gallery_video/robot.avi”;
    $destFile = “/home/amitadut/public_html/gallery_video/robot.flv”;
    $ffmpegPath = “/usr/local/bin/ffmpeg”;
    $flvtool2Path = “/usr/local/bin/flvtool2″;
    // Create our FFMPEG-PHP class
    $ffmpegObj = new ffmpeg_movie($srcFile);
    // Save our needed variables
    $srcWidth = makeMultipleTwo($ffmpegObj->getFrameWidth());
    $srcHeight = makeMultipleTwo($ffmpegObj->getFrameHeight());
    $srcFPS = $ffmpegObj->getFrameRate();
    $srcAB = intval($ffmpegObj->getAudioBitRate()/1000);
    $srcAR = $ffmpegObj->getAudioSampleRate();
    // Call our convert using exec()
    exec($ffmpegPath . ” -i ” . $srcFile . ” -ar ” . $srcAR . ” -ab ” . $srcAB . ” -f flv -s ” . $srcWidth . “x” . $srcHeight . ” ” . $destFile . ” | ” . $flvtool2Path . ” -U stdin ” . $destFile);
    But file is creating with 0 kb filesize.

    can you tell me why 0 kb is creating??????????/

    i have also print some propeties of ffmpeg for you

    srcWidth: 160
    srcHeight: 112
    srcFPS: 25
    srcAB: 32
    srcAR: 32000
    getDuration: 9.60000038147
    getFrameCount: 240
    getFrameRate: 25
    getFilename: /home/amitadut/public_html/gallery_video/robot.avi
    getComment:
    getTitle:
    getAuthor:
    getCopyright:
    getArtist:
    getGenre:
    getTrackNumber: 0
    getYear: 0
    getFrameHeight: 112
    getFrameWidth: 160
    getPixelFormat: yuv420p
    getBitRate: 183948
    getVideoBitRate: 104857200
    getAudioBitRate: 32000
    getAudioSampleRate: 32000
    getVideoCodec: mpeg1video
    getAudioCodec: mp2
    getAudioChannels: 1
    hasAudio: 1

  68. Ajay June 17, 2009 at 1:00 pm #

    Hi Sajith,

    New to use this FFmpeg. and to linux also.

    I installed ffmpeg and trying to use the Library of the ffmpeg.
    #include “libavcodec/avcodec.h”
    #include “libavformat/avformat.h”
    I am using simple sample code ,which takes vedio stream ,and convert it to someformat.

    I am facing problem is when i wrote the C Code .
    I complied it which is not the problem,but linking is getting problem.

    It is giving like this
    test.c:(.text+0xf6): undefined reference to `av_register_all’
    test.c:(.text+0x12b): undefined reference to `av_open_input_file’
    test.c:(.text+0×146): undefined reference to `av_find_stream_info’
    test.c:(.text+0×183): undefined reference to `dump_format’
    test.c:(.text+0x1f6): undefined reference to `avcodec_find_decoder’
    test.c:(.text+0×242): undefined reference to `avcodec_open’
    test.c:(.text+0×257): undefined reference to `avcodec_alloc_frame’
    test.c:(.text+0x25f): undefined reference to `avcodec_alloc_frame’
    test.c:(.text+0×294): undefined reference to `avpicture_get_………

    Means it is unable to link with the contents of the header files ..
    Please do guide me ..what is the worng thing i am doing.

  69. sandeep June 23, 2009 at 11:25 am #

    i want to run ffmpeg in my system but its not run properly
    and error msg are comming
    “Error in loading ffmpeg”
    pls help me

  70. Web-Farmer June 23, 2009 at 11:52 pm #

    Hi folk,

    Currently I come to work with FFMPEG to convert video stream into flv in php. Can anyone give how could i do this using php? Does anybody has class or source code for that?

    A little help appreciate…

    Web-Farmer
    http://www,letsnurture.com

  71. kumar July 30, 2009 at 10:47 am #

    Hello!
    I want to resize jpeg image. Already resized but problem is image quality not good. i.e. Original image size is 640*480. After resize 200* auto. Resize image not looking same as original image. Anybody give an idea..

  72. jeetu August 20, 2009 at 5:18 pm #

    i’m installing ffmpeg and did this code

    c:/ffmpeg/ffmpeg.exe –i d:/myfile.mpg d:/myfile.flv /y

    on the DOS and then came this error

    unable to find a suitable output format for ‘ui’

    how can i solve this?

    i’m using windows xp by the way.

    thanks.

  73. syaam March 31, 2010 at 2:50 pm #

    I downloaded ffmpeg.exe from some site.. i placed that exe file in server. after that i executed above code..Then i got an error msg like this
    “Error in loading ffmpeg..

    what sholud i do?

  74. martunis May 25, 2010 at 2:36 pm #

    output : fail
    Is there a problem with exec().
    I have checked the phpinfo(); and ffmpeg turn on
    I use ubuntu 10.04. Please help.

  75. martunis May 25, 2010 at 2:38 pm #

    extension_loaded(‘ffmpeg’) or die(‘error in loading ffmpeg’);
    if(exec(‘ffmpeg -i saman600.flv saman6001.avi’))
    echo”success”;
    else
    echo”fail”;

    output : fail

  76. Muhammad Atif Agha January 15, 2011 at 2:32 am #

    Hey Sajith thanks a lot for the successful script.

    I think you have not mentioned users that they should buy ffmpeg supported domain.
    Actually cpanels don’t provide support for ffmpeg, because it is RAM consuming application. For this, you have to buy ffmpeg supported domain.

    I am using Citrex Domain, its working 100% perfectly.

    Exec is a system call, which is made in Linux C, and it is used for launching or initiating any proces, so you have to run this application and this function is also available in php.
    exec(‘ffmpeg -i abc.3gp abc.flv’);

    Buy domain from some ffmpeg supported domain e.g Citrex and enjoy.

    Regards
    Atif

  77. satya January 27, 2011 at 11:37 am #

    hi,

    thank you so much for your help to manage videos with ffmpeg.

    please write a command to grab the image in jpg,png or gif for that converted flv video.

    thanks in advance

  78. Alex March 31, 2011 at 12:57 pm #

    hello, I try to get thumbnail from certain part of video but doesn’t work, I got error “Fatal error: Call to a member function toGDImage() on a non-object”
    I try everything but nothing, my code is
    getFrameCount() / 4);
    $frame = $movie->GetFrame( $thumbnailOf );
    $image = $frame->toGDImage();
    $name_of_image = ‘my_pics.jpg’;
    imagejpeg($image, $video_path.$name_of_image, 100);
    echo ”;

    Can someone help me !?

  79. Alex March 31, 2011 at 12:58 pm #

    This is the code:

    $file = $video_path.$video["video"];
    $movie = new ffmpeg_movie($file);
    $thumbnailOf = (int) round($movie->getFrameCount() / 4);
    $frame = $movie->GetFrame( $thumbnailOf );
    $image = $frame->toGDImage();
    $name_of_image = ‘my_pics.jpg’;
    imagejpeg($image, $video_path.$name_of_image, 100);
    echo ”;

  80. Alex March 31, 2011 at 1:03 pm #


    $file = $video_path.$video["video"];
    $movie = new ffmpeg_movie($file);
    $thumbnailOf = (int) round($movie->getFrameCount() / 4);
    $frame = $movie->GetFrame( $thumbnailOf );
    $image = $frame->toGDImage();
    $name_of_image = ‘my_pics.jpg’;
    imagejpeg($image, $video_path.$name_of_image, 100);
    echo "";

  81. Praveen April 5, 2011 at 11:04 pm #

    @Sajith M.R

    Is there a way to find if FFMPEG library file exist in linux and windows using PHP ?

    Thanks
    Praveen

    • Sajith M.R April 16, 2011 at 3:28 pm #

      Search for ffmpeg.exe in Windows, and in linux type ‘whereis ffmpeg’ in command prompt

  82. Sandhirasegaran.M April 28, 2011 at 2:02 pm #

    Hi Sajith,

    Am new to ffmpeg, we are working in both windows and linux.

    Development is in windows where as in house server is in linux.

    So we have to configure in both windows and linux, first i have to install in windows then convert any video format to .flv format and capture image to display in home page.

    I have install in windows and got ffmpeg section in phpinfo().

    With the help of ffmpeg am able to get video attributes only, how to convert video format and capture image.

    If possible explain step wise to capture completely.

    Thanks in advance

  83. Sandhirasegaran.M April 28, 2011 at 2:12 pm #

    The way i have install ffmpeg as follows,

    1. Copied avcodec-51.dll, avformat-51.dll, avutil-49.dll and pthreadGC2.dll to windows/system32 directory.

    2. Copied php_ffmpeg.dll to /php/ext directory.

    3. Downloaded ffmpeg.exe and ffplay.exe and copied in a directory.

    4. Added following code in php.ini.

    extension=php_ffmpeg.dll

    then restarted apache.

    Above install is it enough for video format conversion.

    Please guide me to complete my project ( Video library management )

    Thanks in advance

  84. Nilesh April 29, 2011 at 5:16 pm #

    Dear Sajith,

    We are developing video website in house. We have video player that support only .flv file. so, we find out php script to convert all other format video file to .FLV and its running nice if, the .avi. mpg etc file size is small. Once, i try to upload big files like 50 mb, 80 mb then its not convert.

    We can upload only 10 MB not more then. Please help soon.

    Can you please help me here?

    Thanks,

  85. Nilesh April 29, 2011 at 5:18 pm #

    Dear Sajith,

    We are developing video website in house. We have video player that support only .flv file. so, we find out php script to convert all other format video file to .FLV and its running nice if, the .avi. mpg etc file size is small. Once, i try to upload big files like 50 mb, 80 mb then its not convert.

    If, you want to see the php script then please let us know.

    We can upload only 10 MB not more then. Please help soon.

    Can you please help me here?

    Thanks,

  86. Muthuraj May 2, 2011 at 8:44 pm #

    Hi Mr.Sajith,

    I a newbie to ffmpeg after a long battle i have successfully installed ffmepg in my linux server, but now i need to join two or more flv video files using ffmpeg (by using php coding not in command prompt), can you please guide me to do this activity?

    Thanks in advance, looking forward to hear from you.

    Thanks & Regards,
    Muthuraj S

  87. attish May 24, 2011 at 5:47 pm #

    bhai sajit M.R thanks for the code but this procedure is only for linux. this is not work in php hwo to convert file in php ?? any user ask abt that question u dont reply it . why ??? if u have no idea abt that simple says i have no idea . but u dont reply it becuase u feel u r a loser …………………………

  88. Shah Zeb August 3, 2011 at 7:10 pm #

    @ Nilesh

    Edit your php.ini configuration file

    ;;;;;;;;;;;;;;;;;;;
    ; Resource Limits ;
    ;;;;;;;;;;;;;;;;;;;

    max_execution_time = 6000 ; Maximum execution time of each script, in seconds
    max_input_time = 6000 ; Maximum amount of time each script may spend parsing request data
    memory_limit = 99M ; Maximum amount of memory a script may consume (16MB)

    ;;;;;;;;;;;;;;;;;
    ; Data Handling ;
    ;;;;;;;;;;;;;;;;;

    ; Maximum size of POST data that PHP will accept.
    post_max_size = 1024M

    ;;;;;;;;;;;;;;;;
    ; File Uploads ;
    ;;;;;;;;;;;;;;;;

    ; Maximum allowed size for uploaded files.
    upload_max_filesize = 1024M

  89. Shah Zeb August 4, 2011 at 2:52 am #

    Hi Sajith M.R,
    My project is working fine locally on windows. But when I run the project on linux dedicated server, the converted flv video has no sound. And when I add the “-acodec mp3″ line in ffmpeg command, ffmpeg coverts no video. ffmpeg only converts the video with no audio when there is no -vcodec and -acodec lines present in commands. I contacted my hosting company, they says that libmp3lame is enabled. Can you tell me what is the problem, why there is no audio in converted video. And also why ffmpeg doesn’t generates the output flv, if there is -acodec line present in ffmpeg command.

    Your help is highly appreciated! THanks

  90. Jagan September 23, 2011 at 8:16 am #

    Hai Mr.Sajith. I successfully installed ffmpeg libraries in my windows machine. It is working in my command prompt but the problem is when i’m trying to access it via php it shows error ‘like error in loading ffmpeg while executing the below line. plz help me
    extension_loaded(‘ffmpeg’) or die(‘Error in loading ffmpeg’);

    • Sajith M.R September 27, 2011 at 9:18 pm #

      While running form PHP you need to provide full path, eg: C:/Windows/ffmpeg.exe rather than just exec(‘ffmpeg ‘)

Trackbacks/Pingbacks

  1. Bookmarks for November 12th through November 22nd « Peng’s Blog - November 22, 2009

    [...] ffmpeg sample code | Programming Ideas, Logics, Tips and Tricks – [...]

Leave a Reply

More in Downloads, php source code (42 of 45 articles)


With the support of component ezc , You can read your email via pop3 protocol. The email and password ...