0

I am trying to make a video upload system using ajax -ffmpeg . But i have one problem. The problem is my php code everytime said Invailed file video Format. Where i am doing wrong i don't understand.

Anyone can help me here ?

    <?php
    include_once 'includes.php';
    include_once'includes/alphaID.php';
    include_once 'includes/getExtension.php';

    $valid_formats = array("mp4", "MP4");
     if(isset($_POST) and $_SERVER['REQUEST_METHOD'] == "POST")
      {
        $name = $_FILES['videop']['name'];
        $size = $_FILES['videop']['size'];

          if(strlen($name))
           {
             $ext = strtolower(pathinfo($video_numid, PATHINFO_EXTENSION)); 
             $video_numid = alphaID(microtime(true) * 10000);
             if(in_array($ext,$valid_formats))
               {
                if($size<(50024*50024))
                  {
                   $actual_video_name = time().$uid.".".$ext;
                   $tmp = $_FILES['videop']['tmp_name'];
                   $video_numid = $_FILES['file']['name'];          
                   if(move_uploaded_file($tmp, $path.$actual_video_name))
                     {
                      shell_exec("ffmpeg -i $path.$actual_video_name.flv -f flv -s 650x390 $path.$actual_video_name.mp4");
                      shell_exec("ffmpeg -i $path.$actual_video_name.mp4 -vcodec png -ss 00:00:15 -s 650x390 -vframes 1 -an -f rawvideo $path.$actual_video_name.png");
                      $data=$Swamp->Video_Upload($uid,$actual_video_name);
                      $newdata=$Swamp->Get_Upload_Video($uid,$actual_video_name);
                 if($newdata)
                   {
                    echo '<div class="video_prew"><img src="'.$base_url.$path.$actual_video_name.'" width="100%" height="auto" class="preview_video" id="'.$newdata['id'].'"/></div>';

                    }
               }
                else
               {
               echo "Fail upload folder with read access.";
          }
      }
        else
     echo "Video file size max 10 MB";                  
   } else
     echo "Invalid file video format."; 
 } else
   echo "Please select video..!";
   exit;
 }
?>
innovation
  • 1,943
  • 8
  • 29
  • 63

1 Answers1

1

The better approach to validate supported format is to read the file information first and parse it properly. Use ffmpeg -i "filename" and that will give you details about the multimedia file and the you can prepare list of supported video format.

I have done some research and found that we should use ffprobe to get file details. Refer link for more details.

You are referring incorrect variable while reading file extension.

Replace

$ext = strtolower(pathinfo($video_numid, PATHINFO_EXTENSION));

With

$ext = strtolower(pathinfo($name, PATHINFO_EXTENSION));
Community
  • 1
  • 1
Elixir Techne
  • 1,774
  • 14
  • 19