commit
d395e9cf7a
5 changed files with 81 additions and 38 deletions
|
|
@ -73,14 +73,24 @@ Simple transcoding
|
||||||
|
|
||||||
To transcode a video, you have to pass the target format to FFMpeg.
|
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
|
The following example initialize a Ogg format and encodes a `Video.mpeg` to a
|
||||||
target file `file.ogv` :
|
target file `file.ogv` :
|
||||||
|
|
||||||
.. code-block:: php
|
.. code-block:: php
|
||||||
|
|
||||||
<?php
|
<?php
|
||||||
|
use FFMpeg\FFProbe;
|
||||||
use FFMpeg\Format\Video\Ogg;
|
use FFMpeg\Format\Video\Ogg;
|
||||||
|
|
||||||
|
$ffprobe = FFProbe::load($logger);
|
||||||
|
|
||||||
|
$ffmpeg->setProber($ffprobe);
|
||||||
|
|
||||||
$oggFormat = new Ogg();
|
$oggFormat = new Ogg();
|
||||||
|
|
||||||
$ffmpeg->open('Video.mpeg')
|
$ffmpeg->open('Video.mpeg')
|
||||||
|
|
@ -178,6 +188,8 @@ Advanced media type
|
||||||
This section presents usage for the different interfaces. You can combine
|
This section presents usage for the different interfaces. You can combine
|
||||||
them for your own formats.
|
them for your own formats.
|
||||||
|
|
||||||
|
.. _resizable-reference:
|
||||||
|
|
||||||
Resizable
|
Resizable
|
||||||
.........
|
.........
|
||||||
|
|
||||||
|
|
@ -207,13 +219,15 @@ The example below resizes a video by half.
|
||||||
->encode($format, 'file.mp4')
|
->encode($format, 'file.mp4')
|
||||||
->close();
|
->close();
|
||||||
|
|
||||||
|
.. _resamplable-reference:
|
||||||
|
|
||||||
Resamplable
|
Resamplable
|
||||||
...........
|
...........
|
||||||
|
|
||||||
This interface provides video resampling. The example below resample the video
|
This interface provides video resampling. The example below resample the video
|
||||||
at 15 frame per second with a I-frame every 30 image (see
|
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
|
.. code-block:: php
|
||||||
|
|
||||||
|
|
@ -234,6 +248,10 @@ at 15 frame per second with a I-frame every 30 image (see
|
||||||
return 30;
|
return 30;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function supportBFrames()
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$format = new MyFormat();
|
$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')
|
->encode($format, 'output-aac.mp4')
|
||||||
->close();
|
->close();
|
||||||
|
|
||||||
|
.. _ffprobe-reference:
|
||||||
|
|
||||||
FFProbe recipes
|
FFProbe recipes
|
||||||
---------------
|
---------------
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -231,7 +231,7 @@ class FFMpeg extends Binary
|
||||||
|
|
||||||
if ($format instanceof Video\Resizable) {
|
if ($format instanceof Video\Resizable) {
|
||||||
if ( ! $this->prober) {
|
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);
|
$result = json_decode($this->prober->probeStreams($this->pathfile), true);
|
||||||
|
|
@ -269,15 +269,22 @@ class FFMpeg extends Binary
|
||||||
|
|
||||||
if ($format instanceof Video\Resamplable) {
|
if ($format instanceof Video\Resamplable) {
|
||||||
$cmd_part2 .= ' -r ' . $format->getFrameRate();
|
$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) {
|
if ($format instanceof Video\Transcodable) {
|
||||||
$cmd_part2 .= ' -vcodec ' . $format->getVideoCodec();
|
$cmd_part2 .= ' -vcodec ' . $format->getVideoCodec();
|
||||||
}
|
}
|
||||||
|
|
||||||
$cmd_part2 .= ' -b ' . $format->getKiloBitrate() . 'k -g 25 -bf 3'
|
$cmd_part2 .= ' -b ' . $format->getKiloBitrate() . 'k'
|
||||||
. ' -threads ' . $threads
|
. ' -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'
|
. ' -sc_threshold 40 -flags +loop -cmp +chroma'
|
||||||
. ' -me_range 16 -subq 7 -i_qfactor 0.71 -qcomp 0.6 -qdiff 4 '
|
. ' -me_range 16 -subq 7 -i_qfactor 0.71 -qcomp 0.6 -qdiff 4 '
|
||||||
. ' -trellis 1 -qscale 1 '
|
. ' -trellis 1 -qscale 1 '
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,7 @@ class Dimension
|
||||||
public function __construct($width, $height)
|
public function __construct($width, $height)
|
||||||
{
|
{
|
||||||
if ($width <= 0 || $height <= 0) {
|
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;
|
$this->width = (int) $width;
|
||||||
|
|
|
||||||
|
|
@ -97,8 +97,13 @@ abstract class DefaultVideo extends DefaultAudio implements Interactive, Resampl
|
||||||
break;
|
break;
|
||||||
case self::RESIZEMODE_FIT:
|
case self::RESIZEMODE_FIT:
|
||||||
default:
|
default:
|
||||||
$width = $this->width;
|
if (null !== $this->width && null !== $this->height) {
|
||||||
$height = $this->height;
|
$width = $this->width;
|
||||||
|
$height = $this->height;
|
||||||
|
} else {
|
||||||
|
$width = $originalWidth;
|
||||||
|
$height = $originalHeight;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -30,9 +30,20 @@ interface Resamplable extends BaseVideo
|
||||||
*/
|
*/
|
||||||
public function getFrameRate();
|
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
|
* Returns the GOP size
|
||||||
*
|
*
|
||||||
|
* @see https://wikipedia.org/wiki/Group_of_pictures
|
||||||
|
*
|
||||||
* @return integer
|
* @return integer
|
||||||
*/
|
*/
|
||||||
public function getGOPSize();
|
public function getGOPSize();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue