转码百分比永远不会超过 65% php-ffmpeg

Percentage transcoded never goes past 65% php-ffmpeg

编辑

经过一些测试,这个错误似乎与剪辑的视频有直接关系。如果我拍摄 100% 的视频,那么转码的百分比会上升到 100%。如果我只拍摄视频的 30%,那么转码的百分比会上升到 64-65%。

简介

我正在为我的 symfony3 项目使用 https://github.com/PHP-FFMpeg/PHP-FFMpeg。通过作曲家安装。

当视频完成转码后(当转码率达到100%时)我想对刚创建的视频进行另一种操作。

问题

但是,当我剪辑视频时,我似乎从来没有达到 100%。好像每次都停在65%

    $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);
        }
    });

我查看了库以了解是什么原因造成的,但不幸的是我找不到任何迹象。 X264 格式扩展到创建进度侦听器的 DefaultVideo class。这是执行此操作的确切函数。

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;
}

问题

是的,我想创建的第一个视频实际上被正确剪辑了。剪辑视频(缩短视频长度)与转码率永远达不到100%有关系吗?

是否有更优雅的方式来了解视频何时完成转码?


https://github.com/PHP-FFMpeg/PHP-FFMpeg/issues/201

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%.

看来我是对的。为了解决这个问题,我根据裁剪金额计算了百分比差异。

//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));

目前这似乎工作得很好。

    if($percentage == $percentLimit) {
        dump("$percentage % transcoded");
        $ffmpegservice->concatWithOutro($videoExportPath, $videoExportPathFinal, $temporaryVideoPath);

    }

它并不完美,但它确实有效。