Fix Clipping video transcoding progress not correct

This commit is contained in:
Igor Kosteski 2018-02-18 13:57:06 +01:00
commit 53a978e021
6 changed files with 25 additions and 8 deletions

View file

@ -121,7 +121,7 @@ abstract class DefaultAudio extends EventEmitter implements AudioInterface, Prog
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function createProgressListener(MediaTypeInterface $media, FFProbe $ffprobe, $pass, $total) public function createProgressListener(MediaTypeInterface $media, FFProbe $ffprobe, $pass, $total, $duration = 0)
{ {
$format = $this; $format = $this;
$listener = new AudioProgressListener($ffprobe, $media->getPathfile(), $pass, $total); $listener = new AudioProgressListener($ffprobe, $media->getPathfile(), $pass, $total);

View file

@ -80,12 +80,13 @@ abstract class AbstractProgressListener extends EventEmitter implements Listener
* *
* @throws RuntimeException * @throws RuntimeException
*/ */
public function __construct(FFProbe $ffprobe, $pathfile, $currentPass, $totalPass) public function __construct(FFProbe $ffprobe, $pathfile, $currentPass, $totalPass, $duration = 0)
{ {
$this->ffprobe = $ffprobe; $this->ffprobe = $ffprobe;
$this->pathfile = $pathfile; $this->pathfile = $pathfile;
$this->currentPass = $currentPass; $this->currentPass = $currentPass;
$this->totalPass = $totalPass; $this->totalPass = $totalPass;
$this->duration = $duration;
} }
/** /**
@ -255,7 +256,7 @@ abstract class AbstractProgressListener extends EventEmitter implements Listener
} }
$this->totalSize = $format->get('size') / 1024; $this->totalSize = $format->get('size') / 1024;
$this->duration = $format->get('duration'); $this->duration = (int) $this->duration > 0 ? (int) $this->duration : $format->get('duration');
$this->initialized = true; $this->initialized = true;
} }

View file

@ -24,8 +24,9 @@ interface ProgressableInterface extends EventEmitterInterface
* @param FFProbe $ffprobe * @param FFProbe $ffprobe
* @param Integer $pass The current pas snumber * @param Integer $pass The current pas snumber
* @param Integer $total The total pass number * @param Integer $total The total pass number
* @param Integer $duration The new video duration
* *
* @return array An array of listeners * @return array An array of listeners
*/ */
public function createProgressListener(MediaTypeInterface $media, FFProbe $ffprobe, $pass, $total); public function createProgressListener(MediaTypeInterface $media, FFProbe $ffprobe, $pass, $total, $duration = 0);
} }

View file

@ -125,7 +125,7 @@ abstract class DefaultVideo extends DefaultAudio implements VideoInterface
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function createProgressListener(MediaTypeInterface $media, FFProbe $ffprobe, $pass, $total) public function createProgressListener(MediaTypeInterface $media, FFProbe $ffprobe, $pass, $total, $duration = 0)
{ {
$format = $this; $format = $this;
$listeners = array(new VideoProgressListener($ffprobe, $media->getPathfile(), $pass, $total)); $listeners = array(new VideoProgressListener($ffprobe, $media->getPathfile(), $pass, $total));

View file

@ -62,7 +62,7 @@ class Audio extends AbstractStreamableMedia
$listeners = null; $listeners = null;
if ($format instanceof ProgressableInterface) { if ($format instanceof ProgressableInterface) {
$listeners = $format->createProgressListener($this, $this->ffprobe, 1, 1); $listeners = $format->createProgressListener($this, $this->ffprobe, 1, 1, 0);
} }
$commands = $this->buildCommand($format, $outputPathfile); $commands = $this->buildCommand($format, $outputPathfile);

View file

@ -24,6 +24,7 @@ use FFMpeg\Format\ProgressableInterface;
use FFMpeg\Format\AudioInterface; use FFMpeg\Format\AudioInterface;
use FFMpeg\Format\VideoInterface; use FFMpeg\Format\VideoInterface;
use Neutron\TemporaryFilesystem\Manager as FsManager; use Neutron\TemporaryFilesystem\Manager as FsManager;
use FFMpeg\Filters\Video\ClipFilter;
class Video extends Audio class Video extends Audio
{ {
@ -78,9 +79,23 @@ class Video extends Audio
try { try {
/** add listeners here */ /** add listeners here */
$listeners = null; $listeners = null;
if ($format instanceof ProgressableInterface) { if ($format instanceof ProgressableInterface) {
$listeners = $format->createProgressListener($this, $this->ffprobe, $pass + 1, $totalPasses); $filters = clone $this->filters;
$duration = 0;
/*
check the filters of the video,
and if the video has the ClipFilter than:
take the new video duration and send to the
FFMpeg\Format\ProgressListener\AbstractProgressListener class
*/
foreach ($filters as $filter) {
if($filter instanceof ClipFilter){
$duration = $filter->getDuration()->toSeconds();
break;
}
}
$listeners = $format->createProgressListener($this, $this->ffprobe, $pass + 1, $totalPasses, $duration);
} }
$this->driver->command($passCommands, false, $listeners); $this->driver->command($passCommands, false, $listeners);