Jump to content

ffmpeg & flv2tools not working, help!


jamesxg1

Recommended Posts

Hiya!

 

I need help! I have this script;

 

<?php session_start();

include 'system/template/template.php';
include 'system/mysql/mysql.php';
include 'system/properties/property.php';

	$mysql = new mysql();
	$mysql->connect();

	$property = new property();


	if(!$property->landlord_loggedin()) {
		header('Location: login.php');
	}

if(isset($_SESSION['N_P_ID']) && !empty($_SESSION['N_P_ID'])) {
	if(isset($_POST['videotitle']) && !empty($_POST['videotitle']) && isset($_FILES['videofile']) && !empty($_FILES['videofile'])) {
		$upload = $bad . '<form id="Upload" action="upload_video.php" enctype="multipart/form-data" method="post">
					<h3>Upload a video of your property</h3>
					<label>Video Title</label>
					<input type="text" name="videotitle"><br />
					<input type="file" name="videofile">

					<label>Submit</label>
					<input type="submit" name="submit" value="Upload"><br />
					<a href="landlord_account.php">Skip</a>
				</form>';

		$extensions = array('mpg', 'avi', 'mpeg');
		define ("MAX_SIZE","10240"); 

		function getExtension($str) {
			$i = strrpos($str,".");
			if (!$i) {
				return "";
			}

			$l = strlen($str) - $i;
			$ext = substr($str,$i+1,$l);

			return $ext;
		}

		if(isset($_FILES['imageone'])) {

			if(!isset($_POST['videotitle'])) {
				$bad = '<p class="bad">Please enter a video title.</p>';
				$form = $upload;
			}

			$filename = stripslashes($_FILES['videofile']['name']);

			$extension = strtolower(getExtension($filename));

			if(!in_array($extension, $extensions)) {

				$bad = '<p class="bad">Video is incorrect format, please make sure your video format is either mpg/mpeg or avi.</p>';
				$form = $upload;

			} else {

				$size = filesize($_FILES['videofile']['tmp_name']);

				if($size > MAX_SIZE*1024) {

					$bad = '<p class="bad">Video too large.</p>';
					$form = $upload;

				}

				$time = time();
				$image_name = $time . '.' . $extension;
				$newname = "uploads/properties/landlord_files/videos/" . $image_name;

				if(move_uploaded_file($_FILES['videofile']['tmp_name'], $newname)) {
					if($property->add_video($time, 'flv', $_POST['videotitle'])) {
						$srcFile = 'uploads/properties/landlord_files/videos/' . $image_name;
						$destFile = 'uploads/properties/landlord_files/videos/' . $time . '.flv';
						$ffmpegPath = "/path/to/ffmpeg";
						$flvtool2Path = "/path/to/flvtool2";

						$ffmpegObj = new ffmpeg_movie($srcFile);
						$srcWidth = makeMultipleTwo($ffmpegObj->getFrameWidth());
						$srcHeight = makeMultipleTwo($ffmpegObj->getFrameHeight());
						$srcFPS = $ffmpegObj->getFrameRate();
						$srcAB = intval($ffmpegObj->getAudioBitRate()/1000);
						$srcAR = $ffmpegObj->getAudioSampleRate();

						$img = $image_name;
						$ff_frame = $ffmpegObj->getFrame(1);

						if($ff_frame) {
							$gd_image = $ff_frame->toGDImage();
							if($gd_image) {
								imagepng($gd_image, $img);
								imagedestroy($gd_image);
								$property->add_image($img, 'png', 'frame_shot');
							}
						} 

						exec($ffmpegPath . " -i " . $srcFile . " -ar " . $srcAR . " -ab " . $srcAB . " -f flv -s " . $srcWidth . "x" . $srcHeight . " " . $destFile . " | " . $flvtool2Path . " -U stdin " . $destFile);
						@unlink($newname);
						function makeMultipleTwo ($value) {
							$sType = gettype($value/2);
							if($sType == "integer") {
								return $value;
							} else {
								return ($value-1);
							}
						}
						$ref = 1;
					} else {
						@unlink($newname);
						$bad = '<p class="bad">Video upload failed.</p>';
						$form = $upload;
					}
				} else {
					$bad = '<p class="bad">Video upload failed.</p>';
					$form = $upload;

				}
			}
		}

		if($ref == 1) {
			header('Location: landlord_account.php?page=3');
		}

	} else {
		$form = '<form id="Upload" action="upload_video.php" enctype="multipart/form-data" method="post">
					<h3>Upload a video of your property</h3>
					<label>Video Title</label>
					<input type="text" name="videotitle"><br />
					<input type="file" name="videofile">

					<label>Submit</label>
					<input type="submit" name="submit" value="Upload"><br />
					<a href="landlord_account.php">Skip</a>
				</form>';
	}

	$template = new template();
	$array = array('TITLE' => 'Upload A Video', 'CONTENT' => $form);

	$template->newTemplate($array, 'add_property');
} else {
	header('Location: landlord_account.php');
}
?>

 

When I click upload, nothing happens. I just get a blank template (from my template system).

 

Is there something I'm doing wrong here?

 

Many thanks,

 

James.

Link to comment
https://forums.phpfreaks.com/topic/214897-ffmpeg-flv2tools-not-working-help/
Share on other sites

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.