I own the website www.goploom.com which similarly to youtube, allows users to upload and view videos. The videos that are uploaded are converted to the mp4 format for compatibility with our site's html5 video player. My problem is that while FFmpeg successfully generates video thumbnails from the uploaded video and stores the image in the proper directory, The video conversion aspect of my code does not produce any output. I have tweaked the code for a couple hours, and I have not been able to resolve this issue, however, I am told that I can perform video conversion with html, php, and ffmpeg.
My path to ffmpeg is correct as the thumbnail generation works perfectly.
**Information collected from the uploaded video upon upload.
$name = $_FILES['video']['name'];
$title = $_POST['videotitle'];
$type = explode('.', $name);
$type = end($type);
$size = $_FILES['video']['size'];
$random_name = rand();
$tmp = $_FILES['video']['tmp_name'];
if($type != 'mp4' && $type != 'MP4' && $type != 'flv' && $type != 'FLV' && $type != 'mov' && $type != 'MOV'){
$message = "Video Format Not Supported<br>";
} else {
$username_query = mysql_query("SELECT `username` FROM `users` WHERE `user_id` = $session_user_id");
$username = mysql_fetch_assoc($username_query);
$username = $username['username'];
**Thumbnail generation that works perfectly.
$ffmpeg = "/usr/local/bin/ffmpeg";
$videoFile = $_FILES['video']['tmp_name'];
$imageFile = "uploads/".$username."/thumbnails/".$random_name.".jpg";
$size = "160x90";
$getFromSecond = 5;
$cmd = "$ffmpeg -i $videoFile -an -ss $getFromSecond -s $size $imageFile";
if(!shell_exec($cmd)){
echo "Thumbnail Created!
";
} else {
echo "Error Creating Thumbnail!";
}
**Moves the uploaded file to its permanent directory for video conversion. $newFileLocation = "uploads/".$username."/temp".$random_name.".".$type; move_uploaded_file($tmp, $newFileLocation);
*Video Conversion code.
$outputFile = "uploads/".$username."/".$random_name.".mp4";
$databaseStoredVideoUrl = "uploads/".$username."/".$random_name.".mp4";
$video_cmd = "$ffmpeg -i $newFileLocation $outputFile";
echo $video_cmd;
if(!shell_exec($video_cmd)){
echo "Video Converted!
";
} else {
echo "Error Creating Thumbnail!";
}
**Properly stores the output src link in the database, but the video cannot be viewed because it does not exist.
// Video Storage into database under correct username and user directory
mysql_query("INSERT INTO videos VALUES('$session_user_id' ,'', '$name', '$outputFile', '$title', '', '$imageFile')");
$message = "Video Upload Successful.
";
Any help or insight would be brilliant. Thanks.
**EDIT: Fixed by using the following line. $video_cmd = "$ffmpeg -i $newFileLocation -vcodec libx264 -vpre normal -acodec libfaac $outputFile";
and then inputting $video_cmd into shell_exec