Jump to content

Video uploading script with conversion to multiple file types?


jbonnett

Recommended Posts

Anyone know of a script that will allow you to upload a file and converts it to a specified file format?

 

Folder layout:

script/

script/videos/mp4/                                      }

script/videos/ogg/                                        }    folders for converted files from uploaded files

script/videos/webm/                                    }

script/videos/swf/                                        }

 

Video player:

<video width="320" height="240" controls="controls">
  <source src="script/videos/mp4/<? echo $movie; ?>.mp4" type="video/mp4" />
  <source src="script/videos/ogg/ <? echo $movie; ?> .ogg" type="video/ogg" />
  <source src="script/videos/webm/ <? echo $movie; ?> .webm" type="video/webm" />
<object data="script/videos/mp4/ <? echo $movie; ?> .mp4" width="320" height="240">
<embed src="script/videos/swf/ <? echo $movie; ?> .swf" width="320" height="240">
Your browser does not support video
</embed>
</object> 
</video>

 

I have searched and searched the web for an answer and cannot find one pleas help?

Keep in mind that doing this is pretty resource intensive. So if you are trying to encode multiple files at once you are going to hog a lot of resources. If you're on a shared host, they are going to get mad very quickly. For anything that has anywhere near decent traffic and lots of uploaded videos, you're going to need some serious resources to keep up with demand.

 

 

Heres a quick attempt

 

<?
$folderName = $_POST["album_name"];
$end = '/';


//Path to where the users are
$path = "video/";


//Complete path to new folder

$dir = $path . $folderName . $end;

if ((($_FILES["file"]["type"] == "mp3")
|| ($_FILES["file"]["type"] == "video/mp4")
&& ($_FILES["file"]["size"] < 20000000000))
  {
  if ($_FILES["file"]["error"] > 0)
    {
    echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
    }
  else
    {
    echo "Uploaded: " . $_FILES["file"]["name"] . "<br />";
    echo "Type: " . $_FILES["file"]["type"] . "<br />";
    echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
    
    if (file_exists("$dir" . $_FILES["file"]["name"]))
      {
      echo $_FILES["file"]["name"] . " already exists. ";
      }
    else
      {
      move_uploaded_file($_FILES["file"]["tmp_name"],
      "$dir" . $_FILES["file"]["name"]);
      echo "Stored in: $folderName's User Folder";

      }
    }
  }
else
  {
  echo "Invalid file";
  }
// ffmpeg
// Set our source file
$file = $dir . $_FILES["file"]["name"];

$srcFile = $file;
$destFile = "/path/to/file.flv";
$ffmpegPath = "/path/to/ffmpeg";
$flvtool2Path = "/path/to/flvtool2";
// Create our FFMPEG-PHP class
$ffmpegObj = new ffmpeg_movie($srcFile);
// Save our needed variables
$srcWidth = makeMultipleTwo($ffmpegObj->getFrameWidth());
$srcHeight = makeMultipleTwo($ffmpegObj->getFrameHeight());
$srcFPS = $ffmpegObj->getFrameRate();
$srcAB = intval($ffmpegObj->getAudioBitRate()/1000);
$srcAR = $ffmpegObj->getAudioSampleRate();
// Call our convert using exec()
exec($ffmpegPath . " -i " . $srcFile . " -ar " . $srcAR . " -ab " . $srcAB . " -f flv -s " . $srcWidth . "x" . $srcHeight . " " . $destFile . " | " . $flvtool2Path . " -U stdin " . $destFile);
// Make multiples function
function makeMultipleTwo ($value)
{
$sType = gettype($value/2);
if($sType == "integer")
{
return $value;
} else {
return ($value-1);
}
}
?>

 

would i just repeat the FFMPEG process?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.