Hi friends,
This is the program we can upload the video file in any format and it will convert it into the flv format and also it will take the snapshot of video for displaying the video in the player before it's going to be done.
For that here we need to configure the ffmpeg into the local server.This ffmpeg will conver the video file into the flv format and also it will take the snapshot of video and it will store the image.
Here I put the $image_name ie. before we need to store the image we put the name for image.Here I take the name from video and simply append the jpg.
Similarly for the video name and make the video name with the .flv I simply append the video name with .flv.
For storing the image and video I create one folder named 'uploads'.Here I use the Image path and media path for the destination.in this destination its going to be saved after convert the video to flv and took the snapshot.
The source folder is where we upload the video.Once I get the video and snapshot I delete the original video from the source.
< !DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" > < html xmlns="http://www.w3.org/1999/xhtml" > < head > < meta http-equiv="Content-Type" content="text/html; charset=utf-8" / > < title > Video Upload< /title > < /head > < body > < form action="" method="post" enctype="multipart/form-data" > < table width="400" cellpadding="3" > < tr > < td colspan="3" > < /td > < /tr > < tr > < td width="10" rowspan="2" > < /td > < td width="120" > < strong > Choose a file to upload:< /strong > < /td > < td width="242" > < input type="file" name="uploaded_file" / > < /td > < /tr > < tr > < td > < /td > < td > < /td > < /tr > < tr > < td > < /td > < td > < /td > < td > < input type="submit" name="sendForm" value="Upload File" / > < br / > < /td > < /tr > < tr > < td colspan="3" > < /td > < /tr > < /table > < /form > < ?php error_reporting(E_ALL ^ E_NOTICE); // Show all major errors. // Check to see if the button has been pressed if (!empty($_REQUEST['sendForm'])) { // Assign the name to a variable $name = $_FILES['uploaded_file']['name']; /*This is the file name for ex:clock.avi ******************/ // Assign the tmp_name to a variable $tmp_name = $_FILES['uploaded_file']['tmp_name']; // Assign the error to a variable $error = $_FILES['uploaded_file']['error']; // Assign the size to a variable $size = $_FILES['uploaded_file']['size']; // No trailing slash $uploadFilesTo = 'uploads'; // Create safe filename $name = ereg_replace('[^A-Za-z0-9.]', '-', $name); // Disallowed file extensions //what files you don't want upoad... leave this alone and you should be fine but you could add more $naughtyFileExtension = array("php", "php3", "asp", "inc", "txt", "wma","js", "exe", "jsp", "map", "obj", " ", "", "html", "mp3", "mpu", "wav", "cur", "ani"); // Returns an array that includes the extension $fileInfo = pathinfo($name); // Check extension if (!in_array($fileInfo['extension'], $naughtyFileExtension)) { // Get filename $name = getNonExistingFilename($uploadFilesTo, $name); // Upload the file if (move_uploaded_file($tmp_name, $uploadFilesTo.'/'.$name)) { // Show success message $fileNameLength = strlen($name); $counter = 0; $fileNameTemp = ""; $image_name=substr($name, 0, strrpos( $name, ".")) . ".jpg"; $video_name=substr($name, 0, strrpos( $name, ".")) . ".flv"; $media_path=$uploadFilesTo.'/'.$video_name; $image_path=$uploadFilesTo.'/'.$image_name; $sourcefile=$uploadFilesTo.'/'.$name; $command1 = escapeshellcmd("ffmpeg -i $sourcefile -an -ss 00:00:03 -an -r 1 -vframes 1 -s 100*90 -y $image_path"); $output = shell_exec($command1); $command = escapeshellcmd("ffmpeg -y -i $sourcefile -ar 22050 -f flv $media_path"); $output = shell_exec($command); unlink($sourcefile); echo '< center > < p > Your Video File has uploaded successfully< br / > '.$uploadFilesTo.'/'.$name.'< /p > < /center > '; } else { // Show failure message echo '< center > < p > File failed to upload to /'.$name.'< /p > < /center > '; } } else { // Bad File type echo '< center > < p > The file uses an extension we don\'t allow.< /p > < /center > '; } } // Functions do not need to be inline with the rest of the code function getNonExistingFilename($uploadFilesTo, $name) { if (!file_exists($uploadFilesTo . '/' . $name)) return $name; return getNonExistingFilename($uploadFilesTo, rand(100, 200) . '_' . $name); } ? > < /body > < /html >
Leave the comment to improve us...
0 comments: