0

I have installed FFmpeg video converter in XAMMP server, when i upload the video the video is not changed.it is not changed to webm format. check my code and guide me write way. the video is moving to video directory but it is not changing to webm.

    <html>
        <head>
        <title>Video Uploader</title>
        <link rel="stylesheet" type="text/css" href="../css/fluid_grid.css" />
        </head>
        <body>
        <div class="container_12">
        <div>&nbsp</div>
        <div class="grid_12"><h1>Upload Videos</h1></div>
        <div>&nbsp</div>
        <div class="grid_3"><a href="display.php">Display Video</a></div>
        <div class="grid_6">
         <?php
         if(isset($file_uploaded))
         {
             if($done)
             {
             echo '<font color="green">'.$done.'</font>';
             }
             else if($error)
             {
             echo '<font color="red">'.$error.'</font>';
             }
             echo '<br /><br />';
         }
         ?>
        <form name="form1" enctype="multipart/form-data" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" onSubmit="return submitForm();">
            <input name="uploadedfile" type="file" />
            <input type="submit" name="submit" value="Submit">
        </form></div>
        <div class="grid_3">&nbsp</div>
        </div>
        </body>
        </html>
                <?php
                function checkfile($input)
                {
                $ext = array('mpg', 'wma', 'mov', 'flv', 'mp4', 'avi', 'qt', 'wmv', 'rm');
                $extfile = substr($input['name'],-4); 
                $extfile = explode('.',$extfile);
                $good = array();
                $extfile = $extfile[1];
                if(in_array($extfile, $ext))
                {
                $good['safe'] = true;
                $good['ext'] = $extfile;
                }
                else
                {
                $good['safe'] = false;
                }
                return $good;
                }

    if($_POST && array_key_exists("uploadedfile", $_FILES))
    {
    $error = '';
    $upload_dir = "uploads/videos/";
    $img_dir = "uploads/images/";
    $webm_dir = "uploads/webm_files/";
    $target=basename($_FILES['uploadedfile']['name']);
    $target_path = $upload_dir . $target;
    $safe_file = checkfile($_FILES['uploadedfile']);
    if($safe_file['safe'] == 1)
    {
    if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path))
    {
    $base = basename($target_path, $safe_file['ext']);
    $new_webm=$base.'webm';
    $new_webm=$webm_dir.$new_webm;
    $new_image = $base.'jpg';
    $new_image_path = $img_dir.$new_image;
    exec('ffmpeg -i '.$target_path.' -acodec libvorbis -ac 2 -ab 96k -ar 44100 -b 345k -s 640x360 '.$new_webm.'');
    exec('ffmpeg  -i '.$target_path.' -f mjpeg -vframes 1 -s 150x150 -an '.$new_image_path.'');
    $done = 'File uploaded successfully'; 
    } 
    else 
    {
     $error.= "Possible file upload attack!\n";
        $error.=print_r($_FILES);
    }
    }
    else
    {
    $error.= 'Invalid File Type Please Try Again. You file must be of type .mpg, .wma, .mov, .flv, .mp4, .avi, .qt, .wmv, .rm'; 
    }
    $file_uploaded = true;
    }
    ?>

Here is display.php

    <html>
    <head>
    <title>Video Uploader</title>
    <link rel="stylesheet" type="text/css" href="../css/fluid_grid.css" />
    </head>
    <body>
    <div class="container_12">
    <div>&nbsp</div>
    <div class="grid_12"><h1>Upload Videos</h1></div>
    <div>&nbsp</div>
    <div class="grid_3"><a href="index.php">Upload Video</a></div>
    <div class="grid_6">
    <?php
    $directory = "uploads/webm_files/";
    get all image files with a .jpg extension.
    $webm = glob($directory . "*.webm");
    foreach($webm as $webm)
    { 
    ?>
    <video width="320" height="240" controls>
      <source src="<?php echo $webm;?>" type="video/webm" />
    </video>    
    <div>&nbsp</div>
    <?php 
    }
    ?>
    </div>
    <div class="grid_3">&nbsp</div>
    </div>
    </body>
    </html>
igauravsehrawat
  • 3,696
  • 3
  • 33
  • 46
  • You really should be logging errors. There could be a number of errors here: PHP can't find the path to the ffmpeg binary, your missing codecs for the type of video your trying to encode, file permissions, etc. At the end of the command try appending >> /path/to/log/file.log and testing again. Also, its generally a good idea to include the full path to the ffmpeg binary. Do `which ffmpeg` to find the path and update your code. – cdr Sep 21 '14 at 20:07
  • can you give me the link for ffmpeg because i am going to re-isntalled the xxamp in local server, i could not install the ffmpeg converter properly it is telling php4ts.dll is missing I don't know I am right way or not, because i am using html5 viode tag to display my vidoes, – Rangarajakrishnan Sep 22 '14 at 05:50

0 Answers0