Adding watermark to a video by using ffmpeg in php

前端 未结 4 826
心在旅途
心在旅途 2020-12-18 16:10

I created a video with group of images and mp3. But i want to add a watermark text to that video .i am using the below code to add the text.

exec(\'/usr/loca         


        
4条回答
  •  [愿得一人]
    2020-12-18 16:36

    I am using php-ffmpeg [Below : Composer Json]:

    {
        "require": {
            "php-ffmpeg/php-ffmpeg": "^0.6.1"
        }
    }
    

    and Using this php-ffmpeg library you can add watermark's using the following codes:

    open($videoSource);
    
        $format = new FFMpeg\Format\Video\X264('libmp3lame', 'libx264');
    
        if (!empty($watermark))
        {
            $video  ->filters()
                    ->watermark($watermark, array(
                        'position' => 'relative',
                        'top' => 25,
                        'right' => 50,
                    ));
        }
    
        $format
        -> setKiloBitrate(1000)
        -> setAudioChannels(2)
        -> setAudioKiloBitrate(256);
    
        $randomFileName = rand().".$reqExtension";
        $saveLocation = getcwd(). '/video/'.$randomFileName;
        $video->save($format, $saveLocation);
    
        if (file_exists($saveLocation))
            return "http://localhost/test/video/$randomFileName";
        else
            return "http://localhost/test/thumb/404.png";
    
    }
    
    echo $videoLocation =  processVideo("sample.mp4","mp4","favicon.png");
    
    ?>
    

    [Please, update the location according to your need.]

提交回复
热议问题