为此,首先在trans.png上添加渐变色和需要用php写在视频上的文字。
这里是trans.png:
//for video gradient bg
$name='tmp.png';
$name_count = strlen($vName);
$start = 0;
$stop = $name_count * 20;
$color_trans = '8F7E9B';
// if (isset($start) && isset($stop) && isset($color)) {
$color = hex2rgb($color_trans);
$range = $stop - $start;
// create input image
$input = imagecreatefrompng(PATH . 'trans.png');
// create output image
$height = imagesy($input);
$height = 45;
$width = imagesx($input);
$output = imagecreatetruecolor($width, $height);
// put a transparent background on it
$trans_colour = imagecolorallocatealpha($output, 0, 0, 0, 127);
imagefill($output, 0, 0, $trans_colour);
// create the gradient
for ($x = 0; $x < $width; ++$x) {
$alpha = $x <= $start ? 0 : round(min(($x - $start) / $range, 1) * 127);
$new_color = imagecolorallocatealpha($output, $color[0], $color[1], $color[2], $alpha);
imageline($output, $x, $height, $x, 0, $new_color);
} // copy the gradient onto the input image
imagecopyresampled($input, $output, 0, 0, 0, 0, $width, $height, $width, $height);
// output the result
// header('Content-Type: image/png');
$name = 'trans_' . rand(10, 100) . '.png';
imagepng($input, PATH . 'temp/' . $name);
// }
//--/for video gradient bg
然后将此图像与您的视频合并
ffmpeg -i input.mp4 ' -i ' . PATH . 'temp/' . $name . ' -filter_complex "[0:v][1:v]overlay=0:500:enable=between(t\,4\,t)" -codec:a copy ' . PATH . 'videos/video.mp4