Home > Software design >  how to pass video from anywhere using ffmpeg
how to pass video from anywhere using ffmpeg

Time:12-15

i don't know the location of the video my php code :

$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";

if i put the video and the image in the same folder with the code it works well but i want to choose from anywhere

CodePudding user response:

you have to use absolute path, so I think that you have to get the file in your host, and when the file is in the host, you can use ffmpeg, example for upload file

<?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";
?>
  • Related