Add support for video to audio transcoding

This commit is contained in:
Romain Neutron 2013-10-10 15:09:10 +02:00
commit d3e97c974e
11 changed files with 127 additions and 59 deletions

View file

@ -103,4 +103,12 @@ abstract class DefaultAudio extends EventEmitter implements AudioInterface, Prog
return array($listener);
}
/**
* {@inheritDoc}
*/
public function getPasses()
{
return 1;
}
}

View file

@ -19,13 +19,6 @@ interface AudioInterface extends FormatInterface
*/
public function getAudioKiloBitrate();
/**
* Returns an array of extra parameters to add to ffmpeg commandline.
*
* @return array()
*/
public function getExtraParams();
/**
* Returns the audio codec.
*

View file

@ -12,4 +12,17 @@ namespace FFMpeg\Format;
interface FormatInterface
{
/**
* Returns the number of passes.
*
* @return string
*/
public function getPasses();
/**
* Returns an array of extra parameters to add to ffmpeg commandline.
*
* @return array()
*/
public function getExtraParams();
}

View file

@ -86,14 +86,6 @@ abstract class DefaultVideo extends DefaultAudio implements VideoInterface
return $this;
}
/**
* {@inheritDoc}
*/
public function getPasses()
{
return 1;
}
/**
* @return integer
*/

View file

@ -20,13 +20,6 @@ interface VideoInterface extends AudioInterface
*/
public function getKiloBitrate();
/**
* Returns the number of passes.
*
* @return string
*/
public function getPasses();
/**
* Returns the modulus used by the Resizable video.
*

View file

@ -20,6 +20,8 @@ use FFMpeg\Filters\Video\VideoFilters;
use FFMpeg\Filters\FilterInterface;
use FFMpeg\Format\FormatInterface;
use FFMpeg\Format\ProgressableInterface;
use FFMpeg\Format\AudioInterface;
use FFMpeg\Format\VideoInterface;
use FFMpeg\Media\Frame;
use Neutron\TemporaryFilesystem\Manager as FsManager;
@ -67,43 +69,51 @@ class Video extends Audio
if ($this->driver->getConfiguration()->has('ffmpeg.threads')) {
$filters->add(new SimpleFilter(array('-threads', $this->driver->getConfiguration()->get('ffmpeg.threads'))));
}
if (null !== $format->getVideoCodec()) {
$filters->add(new SimpleFilter(array('-vcodec', $format->getVideoCodec())));
if ($format instanceOf VideoInterface) {
if (null !== $format->getVideoCodec()) {
$filters->add(new SimpleFilter(array('-vcodec', $format->getVideoCodec())));
}
}
if (null !== $format->getAudioCodec()) {
$filters->add(new SimpleFilter(array('-acodec', $format->getAudioCodec())));
if ($format instanceOf AudioInterface) {
if (null !== $format->getAudioCodec()) {
$filters->add(new SimpleFilter(array('-acodec', $format->getAudioCodec())));
}
}
foreach ($filters as $filter) {
$commands = array_merge($commands, $filter->apply($this, $format));
}
$commands[] = '-b:v';
$commands[] = $format->getKiloBitrate() . 'k';
$commands[] = '-refs';
$commands[] = '6';
$commands[] = '-coder';
$commands[] = '1';
$commands[] = '-sc_threshold';
$commands[] = '40';
$commands[] = '-flags';
$commands[] = '+loop';
$commands[] = '-me_range';
$commands[] = '16';
$commands[] = '-subq';
$commands[] = '7';
$commands[] = '-i_qfactor';
$commands[] = '0.71';
$commands[] = '-qcomp';
$commands[] = '0.6';
$commands[] = '-qdiff';
$commands[] = '4';
$commands[] = '-trellis';
$commands[] = '1';
if ($format instanceOf VideoInterface) {
$commands[] = '-b:v';
$commands[] = $format->getKiloBitrate() . 'k';
$commands[] = '-refs';
$commands[] = '6';
$commands[] = '-coder';
$commands[] = '1';
$commands[] = '-sc_threshold';
$commands[] = '40';
$commands[] = '-flags';
$commands[] = '+loop';
$commands[] = '-me_range';
$commands[] = '16';
$commands[] = '-subq';
$commands[] = '7';
$commands[] = '-i_qfactor';
$commands[] = '0.71';
$commands[] = '-qcomp';
$commands[] = '0.6';
$commands[] = '-qdiff';
$commands[] = '4';
$commands[] = '-trellis';
$commands[] = '1';
}
if (null !== $format->getAudioKiloBitrate()) {
$commands[] = '-b:a';
$commands[] = $format->getAudioKiloBitrate() . 'k';
if ($format instanceOf AudioInterface) {
if (null !== $format->getAudioKiloBitrate()) {
$commands[] = '-b:a';
$commands[] = $format->getAudioKiloBitrate() . 'k';
}
}
$fs = FsManager::create();