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.