0

I am trying to add watermark in videos of 15-35 seconds duration with 8-10 MB size. The process is taking more than expected time ranging from 30-40 seconds. Here is my code :

$ffmpeg = FFMpeg\FFMpeg::create(array(
            'ffmpeg.binaries'  => ffmpeg_lib,
            'ffprobe.binaries' => ffprobe_lib,
            'timeout'          => 3600, // The timeout for the underlying process
            'ffmpeg.threads'   => 12,   // The number of threads that FFMpeg should use
        ), null);
        $ffmpeg_string = ffprobe_lib;
        
        
        $tempFile=rand().time();
        $outputFile='tmp/'.$tempFile.'.mp4';
       
        $video = $ffmpeg->open($videoURL);
            
        $watermarkPath = watermark_Path;
        $video
            ->filters()
            ->watermark($watermarkPath, array(
                'position' => 'absolute',
                'x' => 20,
                'y' => 10,
            ));
        $text="@".$username;
        $command = "text='$text': fontcolor=white:fontfile=OpenSans-Bold.ttf: fontsize=18: x=20: y=70:";
        $format = new FFMpeg\Format\Video\X264();
        $format->setAudioCodec("aac");
        
        try
        {
                
                $video->filters()->custom("drawtext=$command");
                $video->save($format, $outputFile);
                
                $array_out = array();
                $array_out[] = 
                array(
                    "download_url" => checkVideoUrl($outputFile)
                );
                
                $output=array( "code" => "200", "msg" => $array_out);
                print_r(json_encode($output, true));
                
        }

Is I am doing anything wrong with the code? How speed can be increased? Any help would be appreciable.

Wewillgrow
  • 31
  • 8
  • [Stream copy](https://ffmpeg.org/ffmpeg.html#Stream-copy) the audio instead of re-encoding it if the input audio is already AAC. Use a faster [x264 encoding preset](https://trac.ffmpeg.org/wiki/Encode/H.264#Preset). However, I don't know how to do this using the ffmpeg-php wrapper. – llogan Sep 09 '20 at 18:58
  • Done the stream copy part as the audio was already in acc format. Unable to find info about preset part in ffmpeg php docs. – Wewillgrow Sep 09 '20 at 19:53

0 Answers0