如何在PHP视频上传中添加ffmpeg水印文本?

时间:2017-11-06 19:24:34

标签: php video ffmpeg

以下是我的视频上传代码

if (isset($_POST) and $_SERVER['REQUEST_METHOD'] == "POST") {


     if (isset($_GET['id']) && $_GET['id'] != "") {
         $id = $_GET['id'];
    }/* else {
        $id = $_SESSION['user_id'];
    }*/
   extract($_POST) ;

    $path = "video/answer_video/"; //set your folder path
    //set the valid file extensions 
   // $valid_formats = array("mp4", "jpg", "png", "gif", "bmp", "jpeg", "GIF", "JPG", "PNG", "doc", "txt", "docx", "pdf", "xls", "xlsx"); //add the formats you want to upload
 $valid_formats = array("mp4"); //add the formats you want to upload

    $name = $_FILES['answer_video']['name']; //get the name of the file

    $size = $_FILES['answer_video']['size']; //get the size of the file

    if (strlen($name)) { //check if the file is selected or cancelled after pressing the browse button.
        list($txt, $ext) = explode(".", $name); //extract the name and extension of the file
        if (in_array($ext, $valid_formats)) { //if the file is valid go on.
            if ($size ) { // check if the file size is more than 2 mb
                $file_name = $_POST['filename']; //get the file name
                $question_id = $_POST['question_id'];  
                // $title = $_POST['title']; 
                $title = strip_tags(trim($_POST['title']));
                //get hashtag from message
                $hashtag = gethashtags($title);

                //$tags = $_POST['tags']; 
                $category = $_POST['category']; 

                $tmp = $_FILES['answer_video']['tmp_name'];


                if (move_uploaded_file($tmp, $path . $name)) { //check if it the file move successfully.
                     $answer_video = $name;
                       $answer_type = "uploaded";

                    $video = $path . $name;
                    $length = 5;

$randomletter = substr(str_shuffle("abcdefghijklmnopqrstuvwxyz"), 0, $length);
                   $rand = rand(1,10000000);
$uniqueName = uniqid($rand);
$thumbnail = "images/thumbnail_{$uniqueName}_{$randomletter}.jpg";

// shell command [highly simplified, please don't run it plain on your script!]
shell_exec("ffmpeg -i $video -deinterlace -an -ss 1 -t 00:00:01 -r 1 -y -vcodec mjpeg -f mjpeg $thumbnail 2>&1");







                    $msg = "Uploaded Successfully!";   

                     echo json_encode(array('msg'=>$msg,'res'=>$question_id));
                      $userid = $_SESSION['user_id'];

如何添加右上角的水印。请帮忙

我尝试了很多次但是没有用.. 感谢您的帮助.. Ffmpeg在服务器上工作正常,但不知道如何执行上述要求。 我不知道如何在此实现ffmpeg脚本。 在将视频保存到文件夹之前,我需要添加水印。

0 个答案:

没有答案