Jump to content
The Uniform Server Community

FFMPEG Integration?


Recommended Posts

I assume you're specifically referring to using ffserver, which is a multimedia streaming server for live broadcasts?



Link to comment
Share on other sites

Right, but what I mean is FFMPEG + FFSERVER as PlugIn or something like that, but they need MinGW for Windows!


Exactly: Live Streams, VoD, Movie Catalog, etc.


If it's possible to make a place where users can share code: For example I have a Movie Catalog with 3 type of options: View Internal NET, View External NET, Download (yes it's basic PHP + MySQL), but many users will be glad to copy and if modified or add additional options to post back.

Something like this?


Thank you in advance.

Link to comment
Share on other sites

  • 3 months later...

Here I will write how to I make FFMPEG + FFMPEG-PHP to work in Uniform Server


later I will include Mencoder + Codecs + FLVTool2

This guide is for x86 systems NOT for x64!!!


A little explain:

ffmpeg-php.dll and ffmpeg.exe are NOT the same thing. ffmpeg-php is used to talk to ffmpeg.exe through php scripting.





(download the archive)


MENCODER (still researching this)


(download the archive)


CODECS FOR MPLAYER (still researching this)


(download the archive)




(download the archive incl. support for PHP 5.3.X)


Extract all the files you have download in separate folders in a temp directory.


Stop all running instances of the server!!!


1) copy ffmpeg to C:\UniServer\usr\local\bin\ffmpeg (you can choose any path)

2) copy mencoder to C:\UniServer\usr\local\bin\mencoder (you can choose any path)

3) copy mplayer codecs in C:\UniServer\usr\local\bin\mencoder\codecs (all the codecs should be in that codecs folder of mencoder)

4) copy all php-ffmpeg to %SystemRoot%\system32\ and php\ext (extension folder)


Copying avcodec.dll & avformat.dll and any other *.DLL in package to the %SystemRoot%\system32\


Copying php_ffmpeg.dll to the PHP5 Extensions path.



5) open php.ini and add extension=php_ffmpeg.dll

php.ini is located in C:\UniServer\usr\local\php

The line need to look something like this:



6) Restart web server and go to the admin panel.

Click phpinfo() from the left side and scroll down and look for this between exif and filter



ffmpeg-php version	0.6.3
ffmpeg-php built on	Jul 12 2011 03:54:13
ffmpeg-php gd support	enabled
ffmpeg libavcodec version	Lavc52.72.2
ffmpeg libavformat version	Lavf52.64.2
ffmpeg swscaler version	SwS0.11.0

Directive	Local Value	Master Value
ffmpeg.allow_persistent	0	0
ffmpeg.show_warnings	0	0


Voila ;)


7) Make sure the path to ffmpeg is set to be like this one:

// Set our source file
$ffmpegpath = "C:/UniServer/usr/local/bin/ffmpeg/bin/ffmpeg.exe";
$flvtool2path = "C:/UniServer/usr/local/bin/flvtool2/flvtool2.exe";
$input = 'file.flv';
$output = 'file.jpg';


N.B. I need help to make the path relative and NOT absolute!

Link to comment
Share on other sites

  • 4 weeks later...

Example ffmpeg-screenshot-grabber.php

(save the code as is w/o modification except the path to ffmpeg, etc.)

While running form PHP you need to provide full path, eg: C:/UniServer/usr/local/bin/ffmpeg/bin/ffmpeg.exe rather than just exec('ffmpeg')



if (empty($_GET['video_name'])){
echo 'error';
$video_name = $_GET['video_name'];
$video_ext = $_GET['video_ext'];

// *nix ffmpeg path/usr/sbin/ffmpeg
// put the relative path to the ffmpeg.exe file for windows
$ffmpeg = 'ffmpeg\ffmpeg';

// the input video file
$video  = $video_name.$video_ext;

// where you'll save the image
// define the output file
$image  = 'thumbs/'.$video_name.'.jpg';

// specify the time to get the screen shot at (can easily be randomly generated)
// default time to get the image
$second = 15;

// get the duration and a random place within that

$cmd = "$ffmpeg -i $video 2>&1";
if (preg_match('/Duration: ((\d+):(\d+):(\d+))/s', `$cmd`, $time)) {
$total = ($time[2] * 3600) + ($time[3] * 60) + $time[4];
$second = rand(1, ($total - 1));

// get the screenshot
// finally assemble the command and execute it
$cmd = "$ffmpeg  -itsoffset -$second  -i $video -vcodec mjpeg -vframes 1 -an -f rawvideo -s 720x480 $image";
//$return = `$cmd`;
exec($cmd, $output);



Thanks to the author from here


You'll need to make additional modification on your php.ini to accept larger files and to be able the scripts to work property, as described below:


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 = 128M ; 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


If you wish additional tunning on your dev encoder server you'll need to modify the .htaccess file too with the following sample settings:



AddType video/ogg .ogv .ogm .ogg

AddType audio/ogg .oga .ogg

AddType video/mp4 .mp4

AddType video/webm .webm

AddType video/x-m4v .m4v

AddType text/x-vcard .vcf


php_value max_execution_time 6000

php_value upload_max_filesize 1024M

php_value post_max_size 1024M

php_value memory_limit 128M


We will add additional tools for maximum compatibility and production.


1. We are using great utility called MP4Box from the gpac package (http://gpac.sourceforge.net/) for post-processing.

The post processing is necessary because ffmpeg stores the moov-atoms (video meta information) in the end of the file, however, this data needs to be stored at the beginning to give the users the ability to seek the video until it fully loaded. MP4Box moves them at the beginning and processes the file making him match all the required standards and appropriate for streaming through the module.


Sample MP4Box usage:


MP4Box -add temp.mp4 output.mp4


2. The other tool is FLVMeta (http://code.google.com/p/flvmeta/)


It can be used as replacement of flvtool2, but in my opinion it can do some things better that flvtool2.

You can remux a MP4/M4V video file to a injected FLV video file.

It's important to know that your MP4/M4V video file HAS to be encoded using H.264 for video and AAC for audio.

The command for inject the FLV Metadata is very easy, it requires only two parameters, the input and the output file without any flag, here is the command:


flvmeta input.flv injected_output.flv


3. Another great tool that we use for full HTML5 and Open Source compatibility is ffmpeg2theora - http://v2v.cc/~j/ffmpeg2theora/index.html

With this piece of software we can convert our files to OGV file format.


I'll explain the integration steps above later or soon depends how free time I have ;)


Later I'll share (some day) how to prepare the encoder script which will convert some video files from one format to another and how-to make a page with flash fallback html5 player to playthe video file to all devices compatibility :)


Some people around me asking me why you share that knowledge it's lost of money? - so my answer is simple:

Knowledge is power and must be free so share it!

Link to comment
Share on other sites

Thanks for posting this, stream. If weren't so busy getting working on The Uniform Server, the Wiki and answering Forum questions, we would give you more help. Perhaps in a few more months (March-April?).


I also should add that what you're doing is EXACTLY what The Uniform Server was intended to do: create a platform for others to develop new add-on solutions.


Some people around me asking me why you share that knowledge it's lost of money? - so my answer is simple:

Knowledge is power and must be free so share it!

We obviously agree! These are just tools and you must learn how to use them first. THEN you can use the tools to help create the money-making business.




Link to comment
Share on other sites

  • 2 months later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Create New...