Jump to content


Photo

FFMPEG Integration?


  • Please log in to reply
6 replies to this topic

#1 stream

stream

    Junior Member

  • Member
  • Pip
  • 20 posts
  • Main OS: Windows XP

Posted 06 July 2011 - 12:38 PM

Can somebody provide FFMPEG support for UniServer.
Will be great to have abilities to test encode/decode.thumbnailing etc. on localhost!
Thank you in advance.

#2 BobS

BobS

    Project Helper

  • Super Moderator
  • PipPipPip
  • 334 posts
  • Location:Santiago Chile
  • Interests:Retiring, computer systems, system design, model railroads....
  • Wiki ID: BobS
  • Main OS: Windows 7

Posted 06 July 2011 - 01:55 PM

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

BobS

#3 stream

stream

    Junior Member

  • Member
  • Pip
  • 20 posts
  • Main OS: Windows XP

Posted 06 July 2011 - 04:28 PM

Right, but what I mean is FFMPEG + FFSERVER as PlugIn or something like that, but they need MinGW for Windows!
http://ffmpeg.org/ffserver.html
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.

#4 stream

stream

    Junior Member

  • Member
  • Pip
  • 20 posts
  • Main OS: Windows XP

Posted 02 November 2011 - 06:40 AM

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.

FFMPEG
http://sourceforge.n...2/files/FFmpeg/
http://ffmpeg.zeranoe.com/builds/
(download the archive)

MENCODER (still researching this)
http://sourceforge.n...er-win32/files/
(download the archive)

CODECS FOR MPLAYER (still researching this)
http://www1.mplayerh...al-20071007.zip
(download the archive)

PHP-FFMPEG
http://sergey89.ru/files/ffmpeg-php/
(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\
(C:\windows\system32)
Copying php_ffmpeg.dll to the PHP5 Extensions path.
(C:\UniServer\usr\local\php\extensions)

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:
;extension=php_fileinfo.dll
extension=php_ffmpeg.dll
extension=php_gd2.dll

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

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!

#5 stream

stream

    Junior Member

  • Member
  • Pip
  • 20 posts
  • Main OS: Windows XP

Posted 25 November 2011 - 12:42 PM

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')


<?php
if (empty($_GET['video_name'])){
	echo 'error';
}
else{
	$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";
exec($cmd);
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:

.htaccess

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/ffm...eora/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!

#6 BobS

BobS

    Project Helper

  • Super Moderator
  • PipPipPip
  • 334 posts
  • Location:Santiago Chile
  • Interests:Retiring, computer systems, system design, model railroads....
  • Wiki ID: BobS
  • Main OS: Windows 7

Posted 26 November 2011 - 11:48 PM

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.

Regards,
BobS

#7 seoinheritx

seoinheritx

    Junior Member

  • Member
  • Pip
  • 13 posts
  • SourceForge ID1
  • Wiki ID: 2
  • IRC Nickname: seoinheritx
  • Main OS: Windows Vista

Posted 31 January 2012 - 01:37 AM

Really necessary the integration that can be provided in the above post.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users