After some tests it would appear that this bug has something to do directly with the clipped video. If I take 100% of the video, then the percentage transcoded goes up to 100%. If I take only 30% of the video, then the percentage transcoded goes up tot 64-65%.
I'm using https://github.com/PHP-FFMpeg/PHP-FFMpeg for my symfony3 project. Installed via composer.
When the video is done transcoding (when the transcodage percentage reaches 100%) I would like to start another type of operation on the video I just created.
However, it would appear that I never get to 100% when I clip a video. It seems to stop at 65% every time.
$format->on('progress', function ($video, $format, $percentage) use ($videoExportPath, $temporary_video_path) {
//This part never goes past 65%...
dump("$percentage % transcoded");
if($percentage == 100) {
//never enters this part..
dump("$percentage % transcoded");
$video = $this->ffmpeg->open($videoExportPath);
$filterConcat = new ConcatVideoFilter();
$filterConcat->addFile($temporaryVideoPath);
dump("second video...");
$video
->addFilter($filterConcat)
->save($this->createNewMP4Format(), $videoExportPath);
}
});
I've looked at the lib to see what is causing this but unfortunately I can not find any indication. The X264 format extends to the DefaultVideo class where the progress listeners are created. Here is the exact function that does that.
public function createProgressListener(MediaTypeInterface $media, FFProbe $ffprobe, $pass, $total)
{
$format = $this;
$listeners = array(new VideoProgressListener($ffprobe, $media->getPathfile(), $pass, $total));
foreach ($listeners as $listener) {
$listener->on('progress', function () use ($format, $media) {
$format->emit('progress', array_merge(array($media, $format), func_get_args()));
});
}
return $listeners;
}
And yes the first video I want to create actually gets clipped correctly. Does clipping a video (reducing the length of a video) have something to do with the transcoding percentage to never reach 100%?
Is there a more elegant way to know when a video is done transcoding?
After some tests it would appear that this bug has something to do directly with the clipped video. If I take 100% of the video, then the percentage transcoded goes up to 100%. If I take only 30% of the video, then the percentage transcoded goes up tot 64-65%.
It would appear that I was right about this. To fix this I calculated the percentage difference based on the amount clipped amount.
//Where $max is length of the clipped video
//Where $duration is the length of the original video
$temp = ($max*100/$duration);
$percentLimit = (95-ceil($temp));
As of right now this seems to work rather well.
if($percentage == $percentLimit) {
dump("$percentage % transcoded");
$ffmpegservice->concatWithOutro($videoExportPath, $videoExportPathFinal, $temporaryVideoPath);
}
It's not perfect, but it works.