How to use a PHP-generated image inside the FFMPEG?
I have a PHP file that generates an image. So the result of the following code would be an image shown in the browser:
<?php
require_once('generateImg.php');`
Now I need to use that generated image instead of img.jpeg
in the following command:
// This command successfully generates `output.mp4` file
exec('ffmpeg -loop 1 -t 1 -i img.jpeg -i audio.mp3 -f flv -vf scale=640:ih*640/iw -shortest output.mp4');
Here is what I’ve tried:
ob_start();
require_once('generateImg.php');
$img = ob_get_clean();
exec("ffmpeg -loop 1 -t 1 -i $img -i audio.mp3 -f flv -vf scale=640:ih*640/iw -shortest output.mp4");
But it doesn’t generate the output.mp4 file. Any idea how can I do that?
Here’s the content of generateImg.php
file:
<?php
$image = imagecreate(500, 300);
$background_color = imagecolorallocate($image, 0, 153, 0);
$text_color = imagecolorallocate($image, 255, 255, 255);
imagestring($image, 5, 180, 100, "GeeksforGeeks", $text_color);
imagestring($image, 3, 160, 120, "A computer science portal", $text_color);
header("Content-Type: image/png");
imagepng($image);
imagedestroy($image);
Read more here: Source link