我不知道视频的位置
我的PHP代码:
$video = $_FILES["video"]["name"];
$image = $_FILES["image"]["name"];
$command = "ffmpeg -i ".$image." -s 128x128 output.jpeg";
shell_exec($command);
echo "Overlay has been resized";
$command = "ffmpeg -i ".$video." -i output.jpeg";
$command .= " -filter_complex \"[0:v][1:v]";
$command .= " overlay=25:25\""; // closing double quotes
$command .= " -c:a copy output.mp4";
system($command);
echo "Overlay has been added";
如果我将视频和图像与代码放在同一个文件夹中,则效果很好但我想从任何地方选择
最佳答案
你必须使用绝对路径,所以我认为你必须在你的主机中获取文件,当文件在主机中时,你可以使用ffmpeg,例如上传文件
<?php
$dir_subida = '/var/www/uploads/';
$fichero_subido = $dir_subida . basename($_FILES['fichero_usuario']['name']);
echo '<pre>';
if (move_uploaded_file($_FILES['fichero_usuario']['tmp_name'], $fichero_subido)) {
echo "El fichero es válido y se subió con éxito.\n";
} else {
echo "¡Posible ataque de subida de ficheros!\n";
}
echo 'Más información de depuración:';
print_r($_FILES);
//when upload file, redirect to script2.php
//in this script you can show the message "your video is uploading"
print "</pre>";
//DO NOT RUN FFMPEG CODE IN THIS CODE
//GET THE NAME FILE AND PATH WITH $fichero_subido, and send it to script2.php;
//YOU CAN REDIRECT to "script2.php"
?>
script2.php <?php
//$video = $_FILES["video"]["name"];
//$image = $_FILES["image"]["name"];
$video = $POST[fichero_subido];
//$video will be a path with the file absolut, this is the only way secure to work with php
$command = "ffmpeg -i ".$image." -s 128x128 output.jpeg";
shell_exec($command);
echo "Overlay has been resized";
$command = "ffmpeg -i ".$video." -i output.jpeg";
$command .= " -filter_complex \"[0:v][1:v]";
$command .= " overlay=25:25\""; // closing double quotes
$command .= " -c:a copy output.mp4";
system($command);
echo "Overlay has been added";
?>
关于php - 如何使用ffmpeg从任何地方传递视频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70347759/