protonemedia / laravel-ffmpeg

This package provides an integration with FFmpeg for Laravel. Laravel's Filesystem handles the storage of the files.
https://protone.media/en/blog/how-to-use-ffmpeg-in-your-laravel-projects
MIT License
1.63k stars 194 forks source link

Endless watermark process on 10 sec video #430

Open cod3rshotout opened 2 years ago

cod3rshotout commented 2 years ago

I wrote a Laravel API which allow me to set a watermark on a video previously uploaded with another endpoint. The endpoint that allow the user to set the watermark accept the image file and the video id as parameter. The route call this function:

public function setWatermark(Request $request)
{
    $request->validate([
        'watermark' => 'required|max:1000'
    ]);

    $userId = auth()->user()->id;

     // generate a random name for the watermark
    $watermarkName = Str::random(10) . '.png';

     // this store the watermark image to the user folder
    $watermarkPath = $request->file('watermark')->storeAs($userId, $watermarkName, 'public');

    // get the video (current size is 1kb) - 10 seconds
    $video = Video::where([
        'id' => $request->id,
        'customer_id' => auth()->user()->id,
    ])->firstOrFail();

    $videoUrl = str_replace('/storage/', '', $video->video_url);

    // apply the watermark
    \FFMpeg::fromDisk('public')
        ->open($videoUrl)
        ->addWatermark(function (WatermarkFactory $watermark) use ($watermarkPath) {
            $watermark->fromDisk('public')
                ->open($watermarkPath)
                ->right(25)
                ->bottom(25);
        })
        ->export()
        ->toDisk('public')
        ->inFormat(new \FFMpeg\Format\Video\X264)
        ->save($userId . '/' . 'test.mp4');

    return response()->json(['success' => true]);
}

This is my current configuration:

<?php

return [
    'ffmpeg' => [
        'binaries' => env('FFMPEG_BINARIES', 'ffmpeg'),

        'threads' => 12,   // set to false to disable the default 'threads' filter
    ],

    'ffprobe' => [
        'binaries' => env('FFPROBE_BINARIES', 'ffprobe'),
    ],

    'timeout' => 0,

    'enable_logging' => true,

    'set_command_and_error_output_on_exception' => false,

    'temporary_files_root' => env('FFMPEG_TEMPORARY_FILES_ROOT', sys_get_temp_dir()),
];

The main issue's that to apply the watermark to a video of 10 seconds I should wait 2 minutes at least. Is that something incorrect I did in the configuration or in the code?

cod3rshotout commented 2 years ago

@pascalbaljet bump

MrAlekhin commented 1 year ago

same for me too long processing on server