GithubHelp home page GithubHelp logo

char0n / ffmpeg-php Goto Github PK

View Code? Open in Web Editor NEW
491.0 34.0 127.0 2.59 MB

FFmpegPHP is a pure OO PHP port of ffmpeg-php library that was written in C. It adds an easy to use, object-oriented API for accessing and retrieving information from video and audio files. It has methods for returning frames from movie files as images that can be manipulated using PHP's image functions. This works well for automatically creating thumbnail images from movies. FFmpegPHP is also useful for reporting the duration and bitrate of audio files (mp3, wma...). FFmpegPHP can access many of the video formats supported by ffmpeg (mov, avi, mpg, wmv...)

Home Page: https://char0n.github.io/ffmpeg-php/

License: BSD 3-Clause "New" or "Revised" License

PHP 100.00%
php ffmpeg ffprobe video audio avconv

ffmpeg-php's Introduction

Build Status

FFmpegPHP

FFmpegPHP is a pure OO PSR-4 compatible PHP port of ffmpeg-php library (that was written in C). It adds an easy to use, object-oriented API for accessing and retrieving information from video and audio files. It has methods for returning frames from movie files as images that can be manipulated using PHP image functions. This works well for automatically creating thumbnail images from movies. FFmpegPHP is also useful for reporting the duration and bitrate of audio files (mp3, wma...). FFmpegPHP can access many of the video formats supported by ffmpeg (mov, avi, mpg, wmv...)

Drop-in replacement for ffmpeg-php

FFmpegPHP can be used as a drop in replacement for ffmpeg-php library.

Documentation

FFmpegPHP API documentation can be found here http://char0n.github.io/ffmpeg-php/.

Requirements

  • PHP >=7
  • PHP extensions: gd, mbstring, xml
  • ffmpeg or ffprobe

Installation

Source code

Grab the source code located in src/ directory and use it as you seem appropriate.

Composer installation

Grab the composer.phar which can install packages published on packagist.

 $ wget https://raw.githubusercontent.com/composer/getcomposer.org/1b137f8bf6db3e79a38a5bc45324414a6b1f9df2/web/installer -O - -q | php

This command will create file called composer.phar.

Create a file called composer.json and paste the following JSON into it:

 {
    "require": {
        "char0n/ffmpeg-php": "^3.0.0"
    }
 }

Install the FFmpegPHP by running the following command:

$ php composer.phar install

After this command is successfully executed, the new directory called vendor/ is created. File structure of your current working directory should now look like this:

 - composer.json
 - composer.phar
 - vendor/

To verify that everything works as expected create new file called test.php inside your current working directory with the following content.

<?php
require_once './vendor/autoload.php';

use Char0n\FFMpegPHP\Movie;

$movie = new Movie('./test.mp4');
var_dump($movie->getDuration());

Before you run the script you need to also download the testing movie file:

$ wget https://github.com/char0n/ffmpeg-php/raw/master/tests/data/test.mp4

Now run it.

$ php test.php

The output should be something similar to the following:

float(32.14)

Note

Notice the first line (require './vendor/autoload.php';) in the above script. This line is necessary because it configures how the FFmpegPHP will be included into your scripts and it auto-magically knows where to look for FFmpegPHP.

Using FFmpegPHP

Object Oriented interface

FFmpegPHP is build using PSR-4 standard and it's interface is purely Object Oriented. We're using standar OOP patterns to create our API.

use Char0n\FFMpegPHP\Movie;

$movie = new Movie('/path/to/media.mpeg');
$movie->getDuration(); // => 24

Compatibility layer

On top of our OO interface, there is an additional one that provides full compatibility with original ffmpeg-php library.

use Char0n\FFMpegPHP\Adapters\FFMpegMovie as ffmpeg_movie;

$movie = new ffmpeg_movie('/path/to/media.mpeg');
$movie->getDuration(); // => 24

Partnership with GoDaddy

GoDaddy started to use FFmpegPHP as part of it's services from November 2018. If you need a server with ffmpeg and FFmpegPHP installed on it contact GoDaddy and they'll do it for you as part of its "Expert Service". As author of FFmpegPHP I agreed to provide support for users coming from GoDaddy asking about FFmpegPHP. All incoming GoDaddy customers, please use GitHub issues as a support channel.

Author

References

ffmpeg-php's People

Contributors

abm-dan avatar char0n avatar danielholmes avatar glensc avatar icewave04 avatar ivoba avatar mikhail-radomskii avatar nabeelio avatar nburka avatar robwalch avatar themadness avatar toshy avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ffmpeg-php's Issues

Create tag versions for composer.phar

You may create tags corresponding to versions so packagist creates packages for each version. This would allow more control over the installed version via composer (e.g. 2.*@stable) without the need to put the specific commit hash (dev-master#1234567890abcdef)

More information:
https://packagist.org/about - Managing Versions

Add support for php 8.1

Doesn't work on php 8.1 because of classes implementing Serializable: https://php.watch/versions/8.1/serializable-deprecated

All those classes should:

  • remove implementing interface serializable
  • change serialize/unserialize methods into __serialize(): array and __unserialize(array $data).
Deprecated Functionality: Char0n\FFMpegPHP\OutputProviders\FFMpegProvider implements the Serializable interface, which is deprecated. 
Implement __serialize() and __unserialize() instead (or in addition, if support for old PHP versions is necessary) in 
/var/workspace/vendor/codescale/ffmpeg-php/src/OutputProviders/FFMpegProvider.php on line 7

Thumbnails with only width or height specified

I had problems with getFrameAtTime() when handling files with varying aspect ratio.
The getFrameAtTime() function stretches the thumbnails.
It happens here.

$image_size = ' -s '.$width.'x'.$height;

A quick line of code cold change this:

$image_size = " -vf \"scale=$width:$height\" ";

Thus a call like

getFrameAtTime(4,60,-1,5,'correct_aspect_ratio.jpg')

would result in an image that's always 60px in width and dynamic height, according to the a/r.
I did not test the performance impact of my proposal - but it should not be too bad.
One could also think of implementing the -crop filter in order to archive fixed size images.
But that's a bit more complicated.

This wont run on my mac and I have FFMPeg installed

Fatal error: Uncaught exception 'Exception' with message 'FFmpeg is not installed on host server' in /Applications/XAMPP/xamppfiles/htdocs/ffmpeg-php-master/provider/FFmpegOutputProvider.php:50 Stack trace: #0 /Applications/XAMPP/xamppfiles/htdocs/ffmpeg-php-master/FFmpegMovie.php(220): FFmpegOutputProvider->getOutput() #1 /Applications/XAMPP/xamppfiles/htdocs/ffmpeg-php-master/FFmpegMovie.php(209): FFmpegMovie->setProvider(Object(FFmpegOutputProvider)) #2 /Applications/XAMPP/xamppfiles/htdocs/t.php(11): FFmpegMovie->__construct('/Applications/X...') #3 {main} thrown in /Applications/XAMPP/xamppfiles/htdocs/ffmpeg-php-master/provider/FFmpegOutputProvider.php on line 50

Publicly accessible URLs throw exception

Problem

FFmpeg is capable of getting video information through (publicly accessible) URLs. Currently both the FFProbeProvider and FFMpegProvider include a !file_exists to check if a file exists on the current file system.

Suggestion

Change file_exists to file.

Audio/ClipFilter

I was not able to Clip an audio file, but when I created ClipFilter in Audio from the ClipFilter in Video, it worked, (for mp3 at least), maybe an idea to include in the code?

Can't Get Video's Frame Width and Height

in class FFmpegMovie https://github.com/char0n/ffmpeg-php/blob/master/FFmpegMovie.php line 21

protected static $REGEX_FRAME_WH = '/Video:.+?([1-9][0-9])x([1-9][0-9])/';

It's not meticulous enough in this case below:

Stream #0:0(eng): Video: h264 (Main) (avc1 / 0x31637661), yuv420p, 1280x544, 5493 kb/s, 23.98 fps, 23.98 tbr, 2997 tbn, 5994 tbc

Please fix this bug, thanks! XD

My FFmpeg info:
ffmpeg version 0.9, Copyright (c) 2000-2011 the FFmpeg developers
built on Dec 20 2011 11:30:32 with clang 3.0 (tags/Apple/clang-211.12)
configuration: --enable-gpl --enable-nonfree --enable-libx264 --enable-libaacplus --cc=clang
libavutil 51. 32. 0 / 51. 32. 0
libavcodec 53. 42. 0 / 53. 42. 0
libavformat 53. 24. 0 / 53. 24. 0
libavdevice 53. 4. 0 / 53. 4. 0
libavfilter 2. 53. 0 / 2. 53. 0
libswscale 2. 1. 0 / 2. 1. 0
libpostproc 51. 2. 0 / 51. 2. 0

phpunit

Craete xml configuration for phpunit, so that only running command

$ phpunit

is more than sufficient.

Edit audio

Hello! Thank you very much for the library.

I have a rookie doubt. I know how to manage audios in the old ffmpeg-php library. For the documentation.

But here it is not very clear :( Where can I see examples or docs?

I want to cut audios, join and change formats.

Thank you!

go daddy ffmpeg path to binary

hello I'm trying to find the path to ffmpeg binary. Im using peeps and its asking me for that, I already have the ffmpeg 4.3 version installed. Can anyone help me please.

Using ffmpeg-php locally in a MAMP server environment

Hey, I'm getting a:

FFmpeg is not installed on host server

error when trying to use ffmpeg-php locally. It works fine on my live server. Both have ffmpeg commands that work, but the versions are different and don't have the exact string 'FFmpeg' in each.

Live Server (ffmpeg-php is working):

$ ffmpeg

returns:

FFmpeg version SVN-r26402, Copyright (c) 2000-2011 the FFmpeg developers
  built on Mar 14 2011 01:39:58 with gcc 4.1.2 20080704 (Red Hat 4.1.2-48)
  configuration: --enable-shared --enable-gpl --enable-version3 --enable-nonfree --enable-pthreads --enable-x11grab --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libdc1394 --enable-libfaac --enable-libmp3lame --enable-libopenjpeg --enable-libtheora --enable-libvorbis --enable-libx264 --enable-libxvid --enable-zlib
  libavutil     50.36. 0 / 50.36. 0
  libavcore      0.16. 1 /  0.16. 1
  libavcodec    52.108. 0 / 52.108. 0
  libavformat   52.93. 0 / 52.93. 0
  libavdevice   52. 2. 3 / 52. 2. 3
  libavfilter    1.74. 0 /  1.74. 0
  libswscale     0.12. 0 /  0.12. 0
Hyper fast Audio and Video encoder
usage: ffmpeg [options] [[infile options] -i infile]... {[outfile options] outfile}...

Use -h to get full help or, even better, run 'man ffmpeg'

Local Server (ffmpeg-php is NOT working):

$ ffmpeg

returns:

ffmpeg version 1.2.1 Copyright (c) 2000-2013 the FFmpeg developers
  built on Jul  8 2013 15:05:32 with Apple LLVM version 4.2 (clang-425.0.28) (based on LLVM 3.2svn)
  configuration: --prefix=/usr/local/Cellar/ffmpeg/1.2.1 --enable-shared --enable-pthreads --enable-gpl --enable-version3 --enable-nonfree --enable-hardcoded-tables --enable-avresample --enable-vda --cc=cc --host-cflags= --host-ldflags= --enable-libx264 --enable-libfaac --enable-libmp3lame --enable-libxvid --enable-libfreetype --enable-libtheora --enable-libvorbis --enable-libvpx --enable-librtmp --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libvo-aacenc --enable-libass --enable-ffplay --enable-libspeex --enable-libschroedinger --enable-libfdk-aac --enable-libopus --enable-frei0r --enable-libopenjpeg --extra-cflags='-I/usr/local/Cellar/openjpeg/1.5.1/include/openjpeg-1.5 '
  libavutil      52. 18.100 / 52. 18.100
  libavcodec     54. 92.100 / 54. 92.100
  libavformat    54. 63.104 / 54. 63.104
  libavdevice    54.  3.103 / 54.  3.103
  libavfilter     3. 42.103 /  3. 42.103
  libswscale      2.  2.100 /  2.  2.100
  libswresample   0. 17.102 /  0. 17.102
  libpostproc    52.  2.100 / 52.  2.100
Hyper fast Audio and Video encoder
usage: ffmpeg [options] [[infile options] -i infile]... {[outfile options] outfile}...

I notice the error is from /vendor/codescale/ffmpeg-php/provider/FFmpegOutputProvider.php from an exec() call.

Have any ideas as to why it is not finding ffmpeg locally?

Thanks

Opening external file

I tired to get an external video file by calling

new FFmpegMovie('http://video-js.zencoder.com/oceans-clip.mp4');

but I get a 'Movie file not found' exception.
I want to know if its possible to load an external file like in FFmpeg-PHP,
btw its only to use getDuration();

Thanks!

Confused!

Sorry, this is more of a support issue than a code issue, but hey, you might as well ask...

I'm kind of confused about how to use this class, especially the adapter? Does this adapter allow me to carry out functions of ffmpeg-php without using the actual module, and if so, what's the syntax?

GdImage changes in PHP8.0

From PHP 8.0 and forward, GD extension uses \GdImage class objects instead of resource s for its underlying data structures.

https://php.watch/versions/8.0/gdimage

As a result the constructor for Frame will fail in PHP8.0 and above, giving the error "Param given by constructor is not valid gd resource".

ООП

Почему нельзя нормально написать ОПП, чтобы люди просто скопировали в свой проект https://github.com/char0n/ffmpeg-php/tree/master/src

require_once  'src/Movie.php';

$movie = new Movie('test.mp4');
var_dump($movie->getDuration());

Use namespaces / PSR-4

Since ffmpeg-php already requires PHP 5.3 it would be great if it would use namespaces and follow the PSR-2 standard (I'd recommon to at least follow PSR-0 for autoloading).

If you want to follow PSR standards [1] you could use php-cs-fixer.phar [2] to check for the requirements defined by the standards.

This would be more autoloader friendly and no own implementation of such an autoloader would be required. It would also better integrate into frameworks such as Symfony2 and Zend2 which already heavily depend on namespaces.

[1] PSR-0: https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-0.md PSR-1: https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-1-basic-coding-standard.md PSR-2: https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md
[2] https://github.com/fabpot/PHP-CS-Fixer

Matching width and height

Hello,

I run into a file that gave this output for the video stream:

Stream #0.0: Video: mjpeg (MJPG / 0x47504A4D), yuvj422p, 320x240, 15 tbr, 15 tbn, 15 tbc

That caused a problem with the pattern matching for width and height, because of that 0x in the codec description.

As a solution I have changed the regular expression like this:

protected static $REGEX_FRAME_WH = '/Video:.+?([1-9][0-9]*)x([1-9][0-9]*)/';

where it is assumed that the width and the height do not begin with a 0 digit.

This solution worked for me, so maybe you would like to include it in future releases?

Thank you. :-)

Pear Install

When I install this package via Pear, using

sudo pear channel-discover pear.codescale.net
sudo pear install codescale/FFmpegPHP2

The package is downloaded into my pear directory into folder called '*'

Moving this to FFmpegPHP2 allows the autoloader to start working, but it's kind of odd.

I've experience this in PHP 5.3.8 (from mac ports) on OS X Lion, and PHP 5.3.6 on Ubuntu and PHP 5.3.4 on Centos , so I think it might be a packaging issues.

Unable to find a suitable output format for 'file'

Hello there

Thanks for your great code. I'm about to deploy it for a site I'm developping. Just want to extract the frame after one second of that MOV file.

Unfortunately I'm seeing this error: "Unable to find a suitable output format for 'file'"

Here's the command that fails, taken from getFrameAtTime() in FFmpegMovie.php
ffmpeg -i [MOVIE FILE] -f image2 -ss 1 -vframes 1 [FRAME FILE PATH] 2>&1

No idea what this error means. Can you help me?

Cheers
Michael

pear installation fails.

Following the steps here https://github.com/CodeScaleInc/ffmpeg-php.

$ sudo pear channel-discover pear.codescale.net
$ sudo pear install codescale/FFmpegPHP2
downloading FFmpegPHP2-2.7.0.tgz ...
Starting to download FFmpegPHP2-2.7.0.tgz (1,541,863 bytes)
.................................................................................................................................................................................................................................................................................................................done: 1,541,863 bytes
could not extract the package.xml file from "/build/buildd/php5-5.5.9+dfsg/pear-build-download/FFmpegPHP2-2.7.0.tgz"
Download of "codescale/FFmpegPHP2" succeeded, but it is not a valid package archive
Error: cannot download "codescale/FFmpegPHP2"
Download failed
install failed

Bug in FFmpegMovie class constructor.

Value which is passed to FFmpegOutputProvider constructor(in case, when $outputProvider===null), must be $ffmpegBinary not 'ffmpeg' as it is now.
I have found this when using custom path to ffmpeg binary.

Also, I have noticed mistake in PHPDoc for method getDuration() - type of return value should be float (not int).

Thanks for work. =)

phpdoc command doesn't work

This is what I'm getting for the command in the readme:

# phpdoc -o HTML:Smarty:HandS -d . -t docs
PHP Version 5.3.9
phpDocumentor version 1.4.3

Parsing configuration file phpDocumentor.ini...
   (found in /usr/share/php/phpdocumentor/)...

done
Maximum memory usage set at 256M after considering php.ini...
using tokenizer Parser
ERROR: "." does not exist, skipping
ERROR: nothing parsed

If this is something I'm doing wrong, I think the readme should be more specific. Also, it would be helpful to have the docs online.

Support for PHP 8.0

  • add support for PHP 8.0 in local env
  • add support for PHP 8.0 in CI env
  • release new version of the library supporting PHP 8.0

AnimatedGifTest does not comply with PSR-4

Problem

When installing with composer

Class Char0n\FFMpegPHP\Tests\FFmpegAnimatedGifTest located in ./vendor/char0n/ffmpeg-php/tests/AnimatedGifTest.php does not comply with psr-4 autoloading standard. Skipping.

File is named AnimatedGifTest.php but the class is named FFmpegAnimatedGifTest.

Suggestion

Rename class to AnimatedGifTest.php

Avconv latest versions

There is a breaking change in the way the last avconv version displays a stream information (I didn't test with ffmpeg)

avconv version 11-6:11-1 :

Stream #0.0(und): Video: h264 (Main), yuv420p, 512x384 [PAR 1:1 DAR 4:3], 589 kb/s, 25 fps, 12800 tbn, 50 tbc``

avconv version 9.18

Stream #0.0(und): Video: h264 (Main), yuv420p, 512x384 [PAR 1:1 DAR 4:3], 589 kb/s, 25 fps, 25 tbr, 12800 tbn, 50 tbc

Latest avconv returns the tbn in addition to the tbr value which makes the parser break and ends with a « Zero division exception ».

The fix should be to change the FFmpegMovie::$REGEX_FRAME_RATE to

/([0-9\.]+\sfps,\s)?([0-9\.]+)\stb(?:r|n)/.

Intergrate alchemy ffmpeg

Integrate alchemy ffmpeg implementation as service provider. It will be easy with composer. Also as long as we support pear packages, we have to package alchemy library as pear package and serve it under codescale pear channel to satisfy pear requirements. We also need to notify alchemy about this.

https://github.com/alchemy-fr/PHP-FFmpeg

Video thumbnails broken due to use of imagegd2 function

In Versoin 2.3.3 of GD library for php, the GD2 image support has been disabled, you have to custom compile your own php version to enable this support
libgd/libgd#428

the call to imagegd2($gdImage) in function gdImageToBinaryData($gdImage) function no longer works, resulting

Warning: imagegd2(): GD2 image support has been disabled

Please replace with imagejpeg($gdImage) instead of imagegd2

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.