What FFMPEG-PHP can do and how to use the most out of it

Need help using specific FFMPEG-PHP functions or some programming help? Let our experienced technicians help you debug your problem for FREE. Sign up today and post at our online community: FFMPEG-PHP Help Forums

You’ve probably heard of ffmpeg-php and it’s wide usability mostly in sites that involve with videos such as YouTube or any other similar site. Here’s a bit of an introduction to it and how to use it.

First thing, you’ve got to check that your web hosting provider actually has ffmpeg & ffmpeg-php extension installed on your account and then you could get started with ffmpeg. You can check if it’s installed by creating a PHP script and executing the following code:

extension_loaded('ffmpeg') or die("ffmpeg extension not loaded");

If you get “ffmpeg extension not loaded” then your web hosting provider does not have ffmpeg installed, if you get nothing, then you’re one the good track!

ffmpeg-php is very simple to learn, what it is pretty much is an interface that works with the ffmpeg software to make it easier for PHP developers to access.

Like any object in PHP, you’ll have to start with creating a new instance of it. You can do that by using the following line:

$ffmpegInstance = new ffmpeg_movie(“/path/to/movie/”);

Now that you’ve had that, you can use that instance to use the many features of ffmpeg-php which are from knowing the duration of the movie/audio in seconds to retrieving the bitrate of the movie/audio file.

Once here, it’s pretty much like object oriented programming, ex:
$ffmpegInstance->getDuration(); // Gets the duration in secs.
$ffmpegInstance->getVideoCodec(); // What type of compression/codec used

This can be very helpful when coding anything that has to do with uploading videos because you can know a lot of information about it. I’ve made a small script that pretty much retrieves all the information that ffmpeg can get right here

  • wesley

    WOW, information overload — NOT!

  • radhouane ayari

    Hello

    I’m working on project, that covers live streaming of video files.
    I’m planning to do this with flv format, ale swf players.
    One part of the project is about users uploading video in formats that they have, most of them are typical users, that don’t know the word codec ;-) and.. very often, can’t tell the difrence betwen mouse and keybord.
    That’s why i want to convert their videos to flv format when they’ve uploaded it, and then present it with flash player.

    I want to use HTTP streaming feature in ffserver, and encoding to flv.

    Any tips, info, problems i can encounter?

    The files are 100Mb at max. Most of them are video files captured from
    WebCams so they’re small. Some of them are captured with normal
    cameras.

    Big thanks for the feedback :-)

  • Novice

    Hello radhouane ayari,

    I am also working on similar requirement. Can we get in touch with each other? We may be a great help for each other. Hope to get in touch with you soon.

    Thanks.

  • http://www.pampi.ro Radu

    Hello i have one error.

    Paste it.

    [root@cs2 mplayer]# make
    ./version.sh `cc -dumpversion`
    cc -I./libavcodec -I./libavformat -Wdisabled-optimization -I. -I. -I./libavutil -Wall -Wno-switch -Wpointer-arith -Wredundant-decls -O4 -march=athlon-xp -mcpu=athlon-xp -pipe -ffast-math -fomit-frame-pointer -D_REENTRANT -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE -DHAVE_CONFIG_H -I/usr/X11R6/include -I/usr/include/freetype2 -c -o mplayer.o mplayer.c
    cc -I./libavcodec -I./libavformat -Wdisabled-optimization -I. -I. -I./libavutil -Wall -Wno-switch -Wpointer-arith -Wredundant-decls -O4 -march=athlon-xp -mcpu=athlon-xp -pipe -ffast-math -fomit-frame-pointer -D_REENTRANT -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE -DHAVE_CONFIG_H -I/usr/X11R6/include -I/usr/include/freetype2 -c -o vobsub.o vobsub.c
    make -C libvo libvo.a
    make[1]: Entering directory `/root/ffmpeg/mplayer/libvo’
    make[1]: `libvo.a’ is up to date.
    make[1]: Leaving directory `/root/ffmpeg/mplayer/libvo’
    make -C libao2
    make[1]: Entering directory `/root/ffmpeg/mplayer/libao2′
    make[1]: Nothing to be done for `libs’.
    make[1]: Leaving directory `/root/ffmpeg/mplayer/libao2′
    make -C input
    make[1]: Entering directory `/root/ffmpeg/mplayer/input’
    make[1]: Nothing to be done for `libs’.
    make[1]: Leaving directory `/root/ffmpeg/mplayer/input’
    make -C vidix
    make[1]: Entering directory `/root/ffmpeg/mplayer/vidix’
    make[1]: Nothing to be done for `libs’.
    make[1]: Leaving directory `/root/ffmpeg/mplayer/vidix’
    make -C libmpcodecs
    make[1]: Entering directory `/root/ffmpeg/mplayer/libmpcodecs’
    make[1]: Nothing to be done for `libs’.
    make[1]: Leaving directory `/root/ffmpeg/mplayer/libmpcodecs’
    make -C libaf
    make[1]: Entering directory `/root/ffmpeg/mplayer/libaf’
    make[1]: Nothing to be done for `libs’.
    make[1]: Leaving directory `/root/ffmpeg/mplayer/libaf’
    make -C libmpdemux libmpdemux.a
    make[1]: Entering directory `/root/ffmpeg/mplayer/libmpdemux’
    make[1]: `libmpdemux.a’ is up to date.
    make[1]: Leaving directory `/root/ffmpeg/mplayer/libmpdemux’
    make -C stream
    make[1]: Entering directory `/root/ffmpeg/mplayer/stream’
    cc -I../libavcodec -I../libavformat -Wdisabled-optimization -I. -I.. -I../libavutil -Wall -Wno-switch -Wpointer-arith -Wredundant-decls -O4 -march=athlon-xp -mcpu=athlon-xp -pipe -ffast-math -fomit-frame-pointer -D_REENTRANT -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE -DHAVE_CONFIG_H -I/usr/X11R6/include -I/usr/include/freetype2 -c -o stream_dvd.o stream_dvd.c
    In file included from /usr/include/netdb.h:28,
    from network.h:16,
    from stream.h:65,
    from stream_dvd.c:32:
    /usr/include/netinet/in.h:259: parse error before ‘(‘ token
    /usr/include/netinet/in.h:259: parse error before “__u32″
    /usr/include/netinet/in.h:260: parse error before ‘(‘ token
    /usr/include/netinet/in.h:260: parse error before “__u16″
    /usr/include/netinet/in.h:262: parse error before ‘(‘ token
    /usr/include/netinet/in.h:262: parse error before “__u32″
    /usr/include/netinet/in.h:264: parse error before ‘(‘ token
    /usr/include/netinet/in.h:264: parse error before “__u16″
    stream_dvd.c: In function `dvd_parse_chapter_range':
    stream_dvd.c:168: warning: passing arg 2 of `strtol’ from incompatible pointer type
    make[1]: *** [stream_dvd.o] Error 1
    make[1]: Leaving directory `/root/ffmpeg/mplayer/stream’
    make: *** [stream/stream.a] Error 2
    [root@cs2 mplayer]# make
    [root@cs2 mplayer]# yum -y install stream.h
    Gathering header information file(s) from server(s)
    Server: Red Hat Linux 9 base
    Server: Red Hat Linux 9 updates
    Finding updated packages
    Downloading needed headers
    Cannot find a package matching stream.h
    [root@cs2 mplayer]#

  • http://www.bala-krishna.com Bala Krishna

    Hi, I have already installed ffmpeg-php on my server.. but it work with all video files other then flv. I am not able to get flv video information through ffmpeg-php but for avi and other video files information return correctly. I am not sure if ffmpeg-php support flv video or not.. If you have any information please help me in this regards..

    Thanks

  • http://no VKS

    I have requirement to to record a video file from remote client machine’s webcam(from browser) to the server machine.Is it possible by using ffmpeg-php?

  • http://screenrant.com ScreenRant.com

    Um, wow. You should have called this post:

    “How to tell if ffmpeg is installed.”

    Totally misleading title.

    Vic

  • http://fastnext.com Alex

    Radu, if you don’t need DVD streaming, you may omit this error by compiling your ffmpeg binary with such directives:
    ./configure –disable-dvdnav –disable-dvdread –disable-dvdread-internal –disable-libdvdcss-internal

  • http://mccormicky.com mccormicky

    I found out I do have ffmpeg installed..So how to make the most of it? I would like to know.Knowing I have it installed just doesn’t seem to be enough for me.

  • Pingback: 2bouncy4u.com » Blog Archive » What is the best green web hosting service on the net?

  • http://www.abhijitdutta.com abhijit

    That link does not work. Can you please reupload that file so that I can check the code??

  • sachin

    i have ffmpeg version 0.6.0 adn available is 0.5.0

  • http://www.codescale.net Vladimir Gorej

    ffmpeg-php is dead project. Use https://github.com/char0n/ffmpeg-php instead. It is pure PHP port of that extension with additional functionality.