【问题标题】:Encoding failed during converting and saving video using php-ffmpeg in laravel在 laravel 中使用 php-ffmpeg 转换和保存视频时编码失败
【发布时间】:2020-09-27 08:01:22
【问题描述】:

我正在使用https://github.com/PHP-FFMpeg/PHP-FFMpeg 包将用户视频上传转换为mp4 格式,请注意我使用Laravel 框架 进行开发过程。
但是我正面临这个错误,我不确定我做错了什么,因为它所说的只是编码失败。我附上了下面的错误图片,您可以在底部看到。

这是我处理用户上传的函数:

public function upload()
    {
        $this->putVideoIntoStorage();
        $this->ffmpeg->saveVideo($this->storageManager->getAbsolutePathOf($this->video->getClientOriginalName()));

        return $this->saveVideoIntoDatabase();
    }

这是使用php-ffmpeg处理将视频保存和转换为mp4的函数

 public function saveVideo(String $path)
    {

        $ffmpeg = FFMpeg::create([
            'ffmpeg.binaries' => config('services.ffmpeg.ffmpeg_path'),
            'ffprobe.binaries' => config('services.ffmpeg.ffprobe_path'),
            'timeout'          => 3600, // The timeout for the underlying process
            'ffmpeg.threads'   => 12,   // The number of threads that FFMpeg should use
        ]);


        $video = $ffmpeg->open($path);

        $video->save(new X264(), 'video.mp4');
    }

这是我得到的错误:Errors Image
如果您需要问我,我可以提供更多详细信息,如果有人可以帮助我解决这个问题,我将非常高兴。

【问题讨论】:

  • 打开debug mode,然后您应该可以访问包含有用错误的堆栈跟踪。
  • 提示:将长时间运行的进程移至Job,这样您就可以快速向用户返回响应,然后开始处理代码。您也可以尝试在 tinker session php artisan tinker 中使用已上传的文件运行上述代码并检查错误。

标签: php laravel ffmpeg ffmpeg-php


【解决方案1】:

以下是正确的做法:

$format = new FFMpeg\Format\Video\X264();
$format->setAudioCodec("libmp3lame");

$video->save($format, '/path/to/new/file');

【讨论】:

    猜你喜欢
    • 2010-12-26
    • 2015-10-07
    • 2011-06-29
    • 2017-02-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-12-25
    相关资源
    最近更新 更多