Merge pull request #5 from nlegoff/review

Review
This commit is contained in:
Romain Neutron 2012-06-06 02:36:46 -07:00
commit d395e9cf7a
5 changed files with 81 additions and 38 deletions

View file

@ -73,14 +73,24 @@ Simple transcoding
To transcode a video, you have to pass the target format to FFMpeg.
When you define a format which implements the
:ref:`Resizable <resizable-reference>` interface.
You must set FFprobe (see :ref:`FF-probe<ffprobe-reference>`)
for probing the media and found its height and size.
The following example initialize a Ogg format and encodes a `Video.mpeg` to a
target file `file.ogv` :
.. code-block:: php
<?php
use FFMpeg\FFProbe;
use FFMpeg\Format\Video\Ogg;
$ffprobe = FFProbe::load($logger);
$ffmpeg->setProber($ffprobe);
$oggFormat = new Ogg();
$ffmpeg->open('Video.mpeg')
@ -178,6 +188,8 @@ Advanced media type
This section presents usage for the different interfaces. You can combine
them for your own formats.
.. _resizable-reference:
Resizable
.........
@ -207,13 +219,15 @@ The example below resizes a video by half.
->encode($format, 'file.mp4')
->close();
.. _resamplable-reference:
Resamplable
...........
This interface provides video resampling. The example below resample the video
at 15 frame per second with a I-frame every 30 image (see
`GOP on wikipedia <https://wikipedia.org/wiki/Group_of_pictures>`_).
`GOP on wikipedia <https://wikipedia.org/wiki/Group_of_pictures>`_) and supports
B-frames (see `B-frames on wikipedia <https://wikipedia.org/wiki/Video_compression_picture_types>`_)
.. code-block:: php
@ -234,6 +248,10 @@ at 15 frame per second with a I-frame every 30 image (see
return 30;
}
public function supportBFrames()
{
return true;
}
}
$format = new MyFormat();
@ -477,6 +495,8 @@ latest AvConv / FFMPeg version, aac encoding has to be executed with extra comma
->encode($format, 'output-aac.mp4')
->close();
.. _ffprobe-reference:
FFProbe recipes
---------------

View file

@ -231,7 +231,7 @@ class FFMpeg extends Binary
if ($format instanceof Video\Resizable) {
if ( ! $this->prober) {
throw new LogicException('You must set a valid prober if you use RESIZEMODE_INSET');
throw new LogicException('You must set a valid prober if you use a resizable format');
}
$result = json_decode($this->prober->probeStreams($this->pathfile), true);
@ -269,15 +269,22 @@ class FFMpeg extends Binary
if ($format instanceof Video\Resamplable) {
$cmd_part2 .= ' -r ' . $format->getFrameRate();
/**
* @see http://sites.google.com/site/linuxencoding/x264-ffmpeg-mapping
*/
if ($format->supportBFrames()) {
$cmd_part2 .= ' -b_strategy 1 -bf 3 -g ' . $format->getGOPSize();
}
}
if ($format instanceof Video\Transcodable) {
$cmd_part2 .= ' -vcodec ' . $format->getVideoCodec();
}
$cmd_part2 .= ' -b ' . $format->getKiloBitrate() . 'k -g 25 -bf 3'
$cmd_part2 .= ' -b ' . $format->getKiloBitrate() . 'k'
. ' -threads ' . $threads
. ' -refs 6 -b_strategy 1 -coder 1 -qmin 10 -qmax 51 '
. ' -refs 6 -coder 1 -qmin 10 -qmax 51 '
. ' -sc_threshold 40 -flags +loop -cmp +chroma'
. ' -me_range 16 -subq 7 -i_qfactor 0.71 -qcomp 0.6 -qdiff 4 '
. ' -trellis 1 -qscale 1 '

View file

@ -33,7 +33,7 @@ class Dimension
public function __construct($width, $height)
{
if ($width <= 0 || $height <= 0) {
throw InvalidArgumentException('Width and height should be positive integer');
throw new InvalidArgumentException('Width and height should be positive integer');
}
$this->width = (int) $width;

View file

@ -97,8 +97,13 @@ abstract class DefaultVideo extends DefaultAudio implements Interactive, Resampl
break;
case self::RESIZEMODE_FIT:
default:
if (null !== $this->width && null !== $this->height) {
$width = $this->width;
$height = $this->height;
} else {
$width = $originalWidth;
$height = $originalHeight;
}
break;
}

View file

@ -30,9 +30,20 @@ interface Resamplable extends BaseVideo
*/
public function getFrameRate();
/**
* Returns true if the current format supports B-Frames
*
* @see https://wikipedia.org/wiki/Video_compression_picture_types
*
* @return Boolean
*/
public function supportBFrames();
/**
* Returns the GOP size
*
* @see https://wikipedia.org/wiki/Group_of_pictures
*
* @return integer
*/
public function getGOPSize();