如何使用protonemedia/laravel-ffmpeg添加多像素字幕?

mpgws1up  于 2023-01-27  发布在  其他
关注(0)|答案(1)|浏览(92)

目前我使用这个package来使用ffmpeg进行插入。我可以使用这个代码编码1个字幕文件:

$format = new X264();

FFMpeg::openUrl($videoUrl)
    ->addFilter(function (VideoFilters $filters) use ($tmpSubtitleFilePath) {
            $filters->custom("subtitles={$subtitleFilePath}");
    })
    ->export()
    ->inFormat($format)
    ->save($tmpVideoPath);

让我们说我有翻译文件和抄本文件。我想编码的视频为他们两个所以用户可以切换他们之间,因为他喜欢。

deyfvvtc

deyfvvtc1#

You can add multiple subtitles using the addSubtitles method provided by the `protonemedia/laravel-ffmpeg` package. This method accepts an array of subtitle files, where each entry in the array is an instance of the `FFMpeg\Coordinate\Subtitle` class.`

    use FFMpeg\Coordinate\Subtitle;
    use Protonemedia\LaravelFFMpeg\Support\FFMpeg;
    
   $format = new FFMpeg\Format\Video\X264();

    //change this will your path
    $saveVideoPath = 'path/to/output.mp4';
    $ffmpeg = FFMpeg::create();
    
    $video = $ffmpeg->open($videoUrl);
    
    $subtitles = [
        new Subtitle('path/to/subtitle1.srt'),
        new Subtitle('path/to/subtitle2.srt'),
        new Subtitle('path/to/subtitle3.srt')
    ];
    
    $video->addSubtitles($subtitles);
    
    $video->save($format, $saveVideoPath);

//May be it will help you...

相关问题