Go Back   CodingForums.com > :: Server side development > PHP > Post a PHP snippet

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rating: Thread Rating: 7 votes, 5.00 average.
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 02-17-2012, 01:56 PM   PM User | #196
chump2877
Senior Coder

 
chump2877's Avatar
 
Join Date: Dec 2004
Location: the U.S. of freakin' A.
Posts: 2,530
Thanks: 15
Thanked 128 Times in 121 Posts
chump2877 is on a distinguished road
sudo apt-get install ffmpeg libavcodec-extra-52

...per the forum post that I linked to...you may need to uninstall ffmpeg and reinstall with that command (which gets you ffmpeg and the codecs)? I don't know --I'm just guessing....
__________________
Regards, R.J.

---------------------------------------------------------

Help spread the word! Like my YouTube-to-Mp3 Web Conversion Software on Facebook !! :)
chump2877 is offline   Reply With Quote
Old 02-17-2012, 02:49 PM   PM User | #197
zemaitis
New Coder

 
Join Date: Feb 2012
Posts: 26
Thanks: 9
Thanked 0 Times in 0 Posts
zemaitis is an unknown quantity at this point
I think that we could buy a commercial Ubuntu VPS for a month from http://solarvps.com/ for paypal $1 and try to install working script, then write a complete guide.
zemaitis is offline   Reply With Quote
Old 02-17-2012, 03:26 PM   PM User | #198
chump2877
Senior Coder

 
chump2877's Avatar
 
Join Date: Dec 2004
Location: the U.S. of freakin' A.
Posts: 2,530
Thanks: 15
Thanked 128 Times in 121 Posts
chump2877 is on a distinguished road
Quote:
Originally Posted by zemaitis View Post
I think that we could buy a commercial Ubuntu VPS for a month from http://solarvps.com/ for paypal $1 and try to install working script, then write a complete guide.
Well, I could just install another copy of Ubuntu into another VM, and this time configure everything via the CLI...maybe I'll do that at some point in the future....I don't have the time for it right now....

But I agree, it would be ideal to have a list of commands for people...It would be easier to install into a commercial VPS as well as other flavors of Linux that way...Any volunteers?
__________________
Regards, R.J.

---------------------------------------------------------

Help spread the word! Like my YouTube-to-Mp3 Web Conversion Software on Facebook !! :)
chump2877 is offline   Reply With Quote
Old 02-18-2012, 06:21 AM   PM User | #199
cana888
New Coder

 
Join Date: Feb 2012
Posts: 15
Thanks: 4
Thanked 0 Times in 0 Posts
cana888 is an unknown quantity at this point
Code:
ffmpeg version git-2012-02-18-c9ac082 Copyright (c) 2000-2012 the FFmpeg developers
  built on Feb 18 2012 07:23:10 with gcc 4.4.3
  configuration: --enable-gpl --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libx264 --enable-nonfree --enable-postproc --enable-version3 --enable-x11grab
  libavutil      51. 39.100 / 51. 39.100
  libavcodec     54.  3.100 / 54.  3.100
  libavformat    54.  1.100 / 54.  1.100
  libavdevice    53.  4.100 / 53.  4.100
  libavfilter     2. 62.101 /  2. 62.101
  libswscale      2.  1.100 /  2.  1.100
  libswresample   0.  6.100 /  0.  6.100
  libpostproc    52.  0.100 / 52.  0.100
Input #0, matroska,webm, from 'videos/1329546532_4f3f452405b650.36877783.flv':
  Duration: 00:07:45.23, start: 0.000000, bitrate: 194 kb/s
    Stream #0:0: Video: vp8, yuv420p, 480x360, SAR 1:1 DAR 4:3, 30 fps, 59.94 tbr, 1k tbn, 1k tbc (default)
    Stream #0:1: Audio: vorbis, 44100 Hz, stereo, s16 (default)
Output #0, mp3, to 'mp3/Autechre_-_Puch.mp3':
  Metadata:
    TSSE            : Lavf54.1.100
    Stream #0:0: Audio: mp3, 44100 Hz, stereo, s16, 128 kb/s (default)
Stream mapping:
  Stream #0:1 -> #0:0 (vorbis -> libmp3lame)
Press [q] to stop, [?] for help
size=     259kB time=00:00:16.56 bitrate= 128.2kbits/s    
size=     523kB time=00:00:33.43 bitrate= 128.1kbits/s    
size=     780kB time=00:00:49.89 bitrate= 128.1kbits/s    
size=    1029kB time=00:01:05.82 bitrate= 128.1kbits/s    
size=    1286kB time=00:01:22.28 bitrate= 128.0kbits/s    
size=    1540kB time=00:01:38.53 bitrate= 128.0kbits/s    
size=    1668kB time=00:01:46.71 bitrate= 128.0kbits/s    
size=    1848kB time=00:01:58.25 bitrate= 128.0kbits/s    
size=    1978kB time=00:02:06.53 bitrate= 128.0kbits/s    
size=    2226kB time=00:02:22.44 bitrate= 128.0kbits/s    
size=    2485kB time=00:02:39.00 bitrate= 128.0kbits/s    
size=    2744kB time=00:02:55.56 bitrate= 128.0kbits/s    
size=    2989kB time=00:03:11.29 bitrate= 128.0kbits/s    
size=    3234kB time=00:03:26.94 bitrate= 128.0kbits/s    
size=    3484kB time=00:03:42.92 bitrate= 128.0kbits/s    
size=    3723kB time=00:03:58.26 bitrate= 128.0kbits/s    
size=    3968kB time=00:04:13.91 bitrate= 128.0kbits/s    
size=    4214kB time=00:04:29.63 bitrate= 128.0kbits/s    
size=    4463kB time=00:04:45.59 bitrate= 128.0kbits/s    
size=    4728kB time=00:05:02.55 bitrate= 128.0kbits/s    
size=    4987kB time=00:05:19.13 bitrate= 128.0kbits/s    
size=    5249kB time=00:05:35.90 bitrate= 128.0kbits/s    
size=    5506kB time=00:05:52.36 bitrate= 128.0kbits/s    
size=    5772kB time=00:06:09.37 bitrate= 128.0kbits/s    
size=    6031kB time=00:06:25.93 bitrate= 128.0kbits/s    
size=    6287kB time=00:06:42.36 bitrate= 128.0kbits/s    
size=    6549kB time=00:06:59.13 bitrate= 128.0kbits/s    
size=    6710kB time=00:07:09.42 bitrate= 128.0kbits/s    
size=    6882kB time=00:07:20.42 bitrate= 128.0kbits/s    
size=    7072kB time=00:07:32.59 bitrate= 128.0kbits/s    
size=    7257kB time=00:07:44.43 bitrate= 128.0kbits/s    
size=    7266kB time=00:07:45.00 bitrate= 128.0kbits/s    
video:0kB audio:7266kB global headers:0kB muxing overhead 0.006062%
Everething looks ok, mp3 files are generated to mp3 folder bat download links not showing, nothing heppend.

Check link: http://uhuuu.com/u2/

I dont know what is problem...!!!
cana888 is offline   Reply With Quote
Old 02-18-2012, 10:52 AM   PM User | #200
chump2877
Senior Coder

 
chump2877's Avatar
 
Join Date: Dec 2004
Location: the U.S. of freakin' A.
Posts: 2,530
Thanks: 15
Thanked 128 Times in 121 Posts
chump2877 is on a distinguished road
cana888, that is very strange and I can't reproduce the issue here.

Try the following:

1) Check that you have at least PHP v5.3

2) You are running this in Ubuntu 11.04 instead of 11.10 (as I am), so you might have an incompatible package installed. Or perhaps a package (or package dependency) is missing?

3) You seem to be experiencing some output buffering issues. Try replacing the following code (in all files except inside YouTubeToMp3Converter::UpdateVideoDownloadProgress()):

PHP Code:
flush(); 
...with...

PHP Code:
ob_end_flush();
ob_flush();
flush(); 
4) Try to debug different PHP variables inside of ffmpeg_progress.php. While your log file size increases, your percent progress never goes above zero.

For example, to debug $totalTime and $currentTime in ffmpeg_progress.php, change the last line of that file to read:

PHP Code:
echo $newLogLength "|" $progress "|" $conversionSuccess "|" $error "|" $totalTime "|" $currentTime
(Additional variables must appear at the end of the echo statement separated by pipe characters.)

Then check the AJAX response text in FireBug (in Firefox) to see what those variables are (and why their division always equals zero).

5) Comment out this line in index.php, like so:

PHP Code:
    // Execution settings 
    
ini_set('max_execution_time',0); 
    
//ini_set('display_errors',0); 
To see what PHP errors (if any) that you are getting?
__________________
Regards, R.J.

---------------------------------------------------------

Help spread the word! Like my YouTube-to-Mp3 Web Conversion Software on Facebook !! :)

Last edited by chump2877; 02-18-2012 at 11:01 AM..
chump2877 is offline   Reply With Quote
Old 02-18-2012, 04:50 PM   PM User | #201
cana888
New Coder

 
Join Date: Feb 2012
Posts: 15
Thanks: 4
Thanked 0 Times in 0 Posts
cana888 is an unknown quantity at this point
Quote:
Originally Posted by chump2877 View Post
cana888, that is very strange and I can't reproduce the issue here.

Try the following:

1) Check that you have at least PHP v5.3

2) You are running this in Ubuntu 11.04 instead of 11.10 (as I am), so you might have an incompatible package installed. Or perhaps a package (or package dependency) is missing?

3) You seem to be experiencing some output buffering issues. Try replacing the following code (in all files except inside YouTubeToMp3Converter::UpdateVideoDownloadProgress()):

PHP Code:
flush(); 
...with...

PHP Code:
ob_end_flush();
ob_flush();
flush(); 
4) Try to debug different PHP variables inside of ffmpeg_progress.php. While your log file size increases, your percent progress never goes above zero.

For example, to debug $totalTime and $currentTime in ffmpeg_progress.php, change the last line of that file to read:

PHP Code:
echo $newLogLength "|" $progress "|" $conversionSuccess "|" $error "|" $totalTime "|" $currentTime
(Additional variables must appear at the end of the echo statement separated by pipe characters.)

Then check the AJAX response text in FireBug (in Firefox) to see what those variables are (and why their division always equals zero).

5) Comment out this line in index.php, like so:

PHP Code:
    // Execution settings 
    
ini_set('max_execution_time',0); 
    
//ini_set('display_errors',0); 
To see what PHP errors (if any) that you are getting?
I have least php: http://uhuuu.com/phpinfo.php
No I'm using: Ubuntu 10.04.4 LTS (11.04 was on my local host)
I have successfull installed ffmpeg from this tutorial: http://ubuntuforums.org/showpost.php...postcount=1289 without any error or missing package.

config.class.php
Code:
<?php

	// Config Class
	class Config
	{
		// Protected Fields
		protected $_audioQualities = array(64, 128, 320);

		// Constants
		const _TEMPVIDDIR = 'videos/';
		const _SONGFILEDIR = 'mp3/';
		const _FFMPEG = '/usr/local/bin/ffmpeg';
		const _LOGSDIR = 'logs/';
	}

?>
ffmpeg_progress.php

Code:
<?php

include 'config.class.php';
$newLogLength = 0;
$progress = 0;
$conversionSuccess = 2;
$error = 2;

if (isset($_POST['uniqueId']) && isset($_POST['logLength']) && isset($_POST['mp3File']))
{
	$uniqueId = $_POST['uniqueId'];
	$logLength = $_POST['logLength'];
	$mp3File = urldecode($_POST['mp3File']);
	$logFile = realpath(Config::_LOGSDIR . $uniqueId .".txt");
	if (is_file($logFile))
	{
		$count = 0;
		while (filesize($logFile) == $logLength && $count < 500)
		{
			$count++;
			clearstatcache();
			time_nanosleep(0, 10000000);
		}
		$log = file_get_contents($logFile);
		$file_size = filesize($logFile);
		if (preg_match('/(Duration: )(\d\d):(\d\d):(\d\d\.\d\d)/i', $log, $matches) == 1)
		{
			$totalTime = ((int)$matches[2] * 60 * 60) + ((int)$matches[3] * 60) + (float)$matches[4];
			$numTimes = preg_match_all('/(time=)(.+?)(\s)/i', $log, $times);
			if ($numTimes > 0)
			{
				$currentTime = (float)end($times[2]);
				$progress = round(($currentTime / $totalTime) * 100);
				if ($progress < 100)
				{
					$newLogLength = $file_size;
				}
				else
				{
					unlink($logFile);
					if (is_file(realpath(Config::_TEMPVIDDIR . $uniqueId .'.flv')))
					{
						unlink(realpath(Config::_TEMPVIDDIR . $uniqueId .'.flv'));
					}
					if (is_file(realpath(Config::_SONGFILEDIR . $mp3File)))
					{
						$conversionSuccess = 1;
					}
				}
			}
			else
			{
				$error = 1;
			}

		}
		else
		{
			$error = 1;
		}
	}
	else
	{
		$error = 1;
	}
}
echo $newLogLength . "|" . $progress . "|" . $conversionSuccess . "|" . $error . "|" . $totalTime . "|" . $currentTime;  

?>
YouTubeToMp3Converter.class

Code:
<?php

	// Conversion Class
	include 'config.class.php';
	class YouTubeToMp3Converter extends Config
	{
		// Private Fields
		private $_songFileName = '';
		private $_flvUrl = '';
		private $_tempVidFileName;
		private $_uniqueID = '';
		private $_vidSrcTypes = array('source_code', 'url');
		private $_percentVidDownloaded = 0;

		#region Public Methods
		function __construct()
		{
			$this->_uniqueID = time() . "_" . uniqid('', true);
		}

		function DownloadVideo($youTubeUrl)
		{
			$file_contents = file_get_contents($youTubeUrl);
			if ($file_contents !== false)
			{
				$this->SetSongFileName($file_contents);
				$this->SetFlvUrl($file_contents);
				if ($this->GetSongFileName() != '' && $this->GetFlvUrl() != '')
				{
					return $this->SaveVideo($this->GetFlvUrl());
				}
			}
			return false;
		}

		function GenerateMP3($audioQuality)
		{
			$qualities = $this->GetAudioQualities();
			$quality = (in_array($audioQuality, $qualities)) ? $audioQuality : $qualities[1];
			$exec_string = parent::_FFMPEG.' -i '.$this->GetTempVidFileName().' -y -acodec libmp3lame -ab '.$quality.'k '.$this->GetSongFileName() . ' 2> logs/' . $this->_uniqueID . '.txt';
			$ffmpegExecUrl = preg_replace('/(([^\/]+?)(\.php))$/', "exec_ffmpeg.php", "http://".$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF']);
			$postData = "cmd=".urlencode($exec_string);
			$ch = curl_init();
			curl_setopt($ch, CURLOPT_URL, $ffmpegExecUrl);
			curl_setopt($ch, CURLOPT_POST, TRUE);
			curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
			curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
			curl_setopt($ch, CURLOPT_TIMEOUT_MS, 10);
			curl_setopt($ch, CURLOPT_TIMEOUT, 1);  
			curl_exec($ch);
			curl_close($ch);
		}

		function DownloadMP3($file)
		{
			$filepath = parent::_SONGFILEDIR . urldecode($file);
			if (is_file($filepath))
			{
				header('Content-Type: audio/mpeg3');
				header('Content-Length: ' . filesize($filepath));
				header('Content-Disposition: attachment; filename="'.urldecode($file).'"');
				ob_clean();
				flush();
				readfile($filepath);
				die();
			}
			else
			{
				$redirect = explode("?", $_SERVER['REQUEST_URI']);
				header('Location: ' . $redirect[0]);
			}
		}

		function ExtractSongTrackName($vidSrc, $srcType)
		{
			$name = '';
			$vidSrcTypes = $this->GetVidSrcTypes();
			if (in_array($srcType, $vidSrcTypes))
			{
				$vidSrc = ($srcType == $vidSrcTypes[1]) ? file_get_contents($vidSrc) : $vidSrc;
				if ($vidSrc !== false && eregi('eow-title',$vidSrc))
				{
					$name = end(explode('eow-title',$vidSrc));
					$name = current(explode('">',$name));
					$name = ereg_replace('[^-_a-zA-Z,"\' :0-9]',"",end(explode('title="',$name)));
				}
			}
			return $name;
		}

		function ExtractVideoId($youTubeUrl)
		{
			$v = '';
			$urlQueryStr = parse_url(trim($youTubeUrl), PHP_URL_QUERY);
			if ($urlQueryStr !== false && !empty($urlQueryStr))
			{
				parse_str($urlQueryStr);
			}
			return $v;
		}

		function UpdateVideoDownloadProgress($downloadSize, $downloaded, $uploadSize, $uploaded)
		{
			$percent = round($downloaded/$downloadSize, 2) * 100;
			if ($percent > $this->_percentVidDownloaded)
			{
				$this->_percentVidDownloaded++;
				echo '<script type="text/javascript">updateVideoDownloadProgress("'. $percent .'");</script>';
				ob_end_flush();
				ob_flush(); 
				flush();
			}
		}
		#endregion

		#region Private "Helper" Methods
		private function SaveVideo($url)
		{
			$this->_percentVidDownloaded = 0;
			$this->SetTempVidFileName();
			$file = fopen($this->GetTempVidFileName(), 'w');
			$ch = curl_init();
			curl_setopt($ch, CURLOPT_FILE, $file);
			curl_setopt($ch, CURLOPT_HEADER, 0);
			curl_setopt($ch, CURLOPT_URL, $url);
			curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
			curl_setopt($ch, CURLOPT_NOPROGRESS, false);
			curl_setopt($ch, CURLOPT_PROGRESSFUNCTION, array($this, 'UpdateVideoDownloadProgress'));
			curl_setopt($ch, CURLOPT_BUFFERSIZE, 4096000);
			curl_exec($ch);
			curl_close($ch);
			fclose($file);
			return is_file($this->GetTempVidFileName());
		}
		#endregion

		#region Properties
		public function GetSongFileName()
		{
			return $this->_songFileName;
		}
		private function SetSongFileName($file_contents)
		{
			$vidSrcTypes = $this->GetVidSrcTypes();
			$trackName = $this->ExtractSongTrackName($file_contents, $vidSrcTypes[0]);
			$this->_songFileName = (!empty($trackName)) ? parent::_SONGFILEDIR . preg_replace('/_{2,}/','_',preg_replace('/ /','_',preg_replace('/[^A-Za-z0-9 _-]/','',$trackName))) . '.mp3' : '';
		}

		public function GetFlvUrl()
		{
			return $this->_flvUrl;
		}
		private function SetFlvUrl($file_contents)
		{
			$vidUrl = '';
			if (eregi('"url_encoded_fmt_stream_map": "url=',$file_contents))
			{
				$vidUrl = end(explode('"url_encoded_fmt_stream_map": "url=',$file_contents));
				$vidUrl = urldecode(urldecode(current(explode('\u0026',$vidUrl))));
			}
			//die($vidUrl);
			$this->_flvUrl = $vidUrl;
		}

		public function GetAudioQualities()
		{
			return $this->_audioQualities;
		}

		private function GetTempVidFileName()
		{
			return $this->_tempVidFileName;
		}
		private function SetTempVidFileName()
		{
			$this->_tempVidFileName = parent::_TEMPVIDDIR . $this->_uniqueID .'.flv';
		}

		public function GetVidSrcTypes()
		{
			return $this->_vidSrcTypes;
		}

		public function GetUniqueID()
		{
			return $this->_uniqueID;
		}
		#endregion
	}

?>
index.php

Code:
<?php
	// Execution settings
	ini_set('max_execution_time',0);
	ini_set('display_errors',0);

	// Instantiate converter class
	include 'YouTubeToMp3Converter.class.php';
	$converter = new YouTubeToMp3Converter();

	// On download of MP3
	if (isset($_GET['mp3']))
	{
		$converter->DownloadMP3($_GET['mp3']);
	}
?>
<?php echo '<?xml version="1.1" encoding="iso-8859-1"?>'; ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
	<title>YouTube-To-Mp3 Converter</title>
	<style type="text/css">
		body
		{
			text-align:center;
			font:13px Verdana,Arial;
			margin-top:50px;
		}

		p
		{
			margin:15px 0;
			font-weight:bold;
		}

		form
		{
			width:450px;
			margin:0 auto;
			padding:15px;
			border:1px solid #ccc;
		}

		form input[type="text"]
		{
			width:385px;
		}

		form p
		{
			margin:10px 0;
			font-weight:normal;
		}

		#progress-bar
		{
			width:200px;
			padding:2px;
			border:2px solid #aaa;
			background:#fff;
			margin:0 auto;
		}

		#progress
		{
			background:#000;
			color:#fff;
			overflow:hidden;
			white-space:nowrap;
			padding:5px 0;
			text-indent:5px;
			width:0%;
		}

		#conversion-status
		{
			width:200px;
			padding:2px;
			margin:0 auto;
			color:#999;
			text-align:center;
		}
	</style>
	<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
	<script type="text/javascript">
		var conversionLogLength = 0;

		function updateVideoDownloadProgress(percentage)
		{
			var progress = document.getElementById('progress');
			progress.style.width = progress.innerHTML = parseInt(percentage) + '%';
		}

		function updateConversionProgress(songFile)
		{
			var progress = document.getElementById('progress');
			document.getElementById('conversion-status').innerHTML = "Converting video. . .";
			$.ajax({
				type : "POST",
				url : "ffmpeg_progress.php",
				data : "uniqueId=<?php echo $converter->GetUniqueID(); ?>&logLength=" + conversionLogLength + "&mp3File=" + encodeURI(songFile),
				success : function(retVal) {
					var retVals = retVal.split('|');
					if (retVals[3] == 2)
					{
						progress.style.width = progress.innerHTML = parseInt(retVals[1]) + '%';
						if (parseInt(retVals[1]) < 100)
						{
							conversionLogLength = parseInt(retVals[0]);
							setTimeout(function(){updateConversionProgress(songFile);}, 10);
						}
						else
						{
							$("#preview").css("display", "none");
							var convertSuccessMsg = (retVals[2] == 1) ? '<p>Success!</p><p><a href="<?php echo $_SERVER['PHP_SELF']; ?>?mp3=' + encodeURI(songFile) + '">Download your MP3 file</a>.</p>' : '<p>Error generating MP3 file!</p>';
							$("#conversionSuccess").html(convertSuccessMsg);
							$("#conversionForm").css("display", "block");
						}
					}
					else
					{
						setTimeout(function(){updateConversionProgress(songFile);}, 1);
					}
				}
			});
		}

		window.onload = function()
		{
			if (!document.getElementById('preview'))
			{
				$("#conversionForm").css("display", "block");
			}
		};
	</script>
</head>
<body>
	<h2>YouTube-To-Mp3 Converter</h2>
	<?php
		// On form submission...
		if ($_POST['submit'])
		{
			// Print "please wait" message and preview image
			echo '<div id="preview" style="display:block"><p>...Please wait while I try to convert:</p>';
			echo '<p><img src="http://img.youtube.com/vi/'.$converter->ExtractVideoId(trim($_POST['youtubeURL'])).'/1.jpg" alt="preview image" /></p>';
			echo '<p>'.$converter->ExtractSongTrackName(trim($_POST['youtubeURL']), 'url').'</p>';
			echo '<div id="progress-bar"><div id="progress">0%</div></div>';
			echo '<div id="conversion-status">Downloading video. . .</div></div>';
			flush();

			// Main Program Execution
			if ($converter->DownloadVideo(trim($_POST['youtubeURL'])))
			{
				echo '<div id="conversionSuccess"></div>';
				echo '<script type="text/javascript">var progressBar = document.getElementById("progress"); progressBar.style.width = progressBar.innerHTML = "0%"; updateConversionProgress("'.trim(strstr($converter->GetSongFileName(), '/'), '/').'");</script>';
				flush();
				$converter->GenerateMP3($_POST['quality']);
			}
			else
			{
				echo '<p>Error downloading video!</p>';
			}
		}
	?>
	<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" id="conversionForm" style="display:none">
		<p>Enter a valid YouTube.com video URL:</p>
		<p><input type="text" name="youtubeURL" /></p>
		<p><i>(i.e., "<span style="color:red">http://www.youtube.com/watch?v=HMpmI2F2cMs</span>")</i></p>
		<p style="margin-top:20px">Choose the audio quality (better quality results in larger files):</p>
		<p style="margin-bottom:25px"><input type="radio" value="64" name="quality" />Low &nbsp; <input type="radio" value="128" name="quality" checked="checked" />Medium &nbsp; <input type="radio" value="320" name="quality" />High</p>
		<p><input type="submit" name="submit" value="Create MP3 File" /></p>
	</form>
</body>
</html>
cana888 is offline   Reply With Quote
Old 02-18-2012, 06:06 PM   PM User | #202
chump2877
Senior Coder

 
chump2877's Avatar
 
Join Date: Dec 2004
Location: the U.S. of freakin' A.
Posts: 2,530
Thanks: 15
Thanked 128 Times in 121 Posts
chump2877 is on a distinguished road
1) It seems ffmpeg-php is not successfully and/or correctly installed with PHP because there is no ffmpeg section in php.ini: http://3.bp.blogspot.com/-j4E4kFLqXI...40/Capture.JPG.

2) Make sure that this is the correct location of FFMPEG:

PHP Code:
const _FFMPEG '/usr/local/bin/ffmpeg'
3) Did you do this??:

Quote:
4) Try to debug different PHP variables inside of ffmpeg_progress.php. While your log file size increases, your percent progress never goes above zero.

For example, to debug $totalTime and $currentTime in ffmpeg_progress.php, change the last line of that file to read:

PHP Code:
echo $newLogLength . "|" . $progress . "|" . $conversionSuccess . "|" . $error . "|" . $totalTime . "|" . $currentTime;
(Additional variables must appear at the end of the echo statement separated by pipe characters.)

Then check the AJAX response text in FireBug (in Firefox) to see what those variables are (and why their division always equals zero).
If you don't know how to use Firebug Console tab, then it's time to learn how:

-- https://www.google.com/search?client...w=1916&bih=915

-- http://stackoverflow.com/questions/5...g-ajax-request

4) Did you do this?:

Quote:
5) Comment out this line in index.php, like so:

PHP Code:
// Execution settings
ini_set('max_execution_time',0);
//ini_set('display_errors',0);
To see what PHP errors (if any) that you are getting?
5) Did you do this??:

Quote:
3) You seem to be experiencing some output buffering issues. Try replacing the following code (in all files except inside YouTubeToMp3Converter::UpdateVideoDownloadProgress()):

PHP Code:
flush();
...with...

PHP Code:
ob_end_flush();
ob_flush();
flush();
It seems to me that you didn't try to do some of the things that I suggested. I can't help you if you don't follow my instructions.
__________________
Regards, R.J.

---------------------------------------------------------

Help spread the word! Like my YouTube-to-Mp3 Web Conversion Software on Facebook !! :)
chump2877 is offline   Reply With Quote
Old 02-22-2012, 01:35 PM   PM User | #203
bedo1975
New Coder

 
Join Date: Feb 2012
Posts: 29
Thanks: 1
Thanked 0 Times in 0 Posts
bedo1975 is an unknown quantity at this point
Nicely job, but I have some bugs.

in fact the script download and encode correctly the flv that I choose but, the progress bar downloading are okay, but the progress bar for converter don't appears. and I have debug this I have this error :

Warning: Division by zero in /home/online/public_html/Dev3/phptube2/YouTubeToMp3Converter.class.php on line 108

Warning: Division by zero in /home/online/public_html/Dev3/phptube2/YouTubeToMp3Converter.class.php on line 108

Warning: Division by zero in /home/online/public_html/Dev3/phptube2/YouTubeToMp3Converter.class.php on line 108

Warning: Division by zero in /home/online/public_html/Dev3/phptube2/YouTubeToMp3Converter.class.php on line 108

Warning: Division by zero in /home/online/public_html/Dev3/phptube2/YouTubeToMp3Converter.class.php on line 108

Warning: Division by zero in /home/online/public_html/Dev3/phptube2/YouTubeToMp3Converter.class.php on line 108

Warning: Division by zero in /home/online/public_html/Dev3/phptube2/YouTubeToMp3Converter.class.php on line 108

Warning: Division by zero in /home/online/public_html/Dev3/phptube2/YouTubeToMp3Converter.class.php on line 108

Warning: Division by zero in /home/online/public_html/Dev3/phptube2/YouTubeToMp3Converter.class.php on line 108

Warning: Division by zero in /home/online/public_html/Dev3/phptube2/YouTubeToMp3Converter.class.php on line 108

Warning: Division by zero in /home/online/public_html/Dev3/phptube2/YouTubeToMp3Converter.class.php on line 108

Warning: Division by zero in /home/online/public_html/Dev3/phptube2/YouTubeToMp3Converter.class.php on line 108


do you know where this bug provide ?

thanks
bedo1975 is offline   Reply With Quote
Old 02-22-2012, 02:01 PM   PM User | #204
chump2877
Senior Coder

 
chump2877's Avatar
 
Join Date: Dec 2004
Location: the U.S. of freakin' A.
Posts: 2,530
Thanks: 15
Thanked 128 Times in 121 Posts
chump2877 is on a distinguished road
That warning message appears to be generated by this line in YouTubeToMp3Converter.class.php:

PHP Code:
$percent round($downloaded/$downloadSize2) * 100
The easiest way to get rid of the warning is by either turning off error reporting (which you should be doing anyway for a production-grade application) or doing the following:

PHP Code:
$percent = @round($downloaded/$downloadSize2) * 100
But that PHP warning should not be causing your code to malfunction. And, in fact, that code has nothing to do with the "conversion" progress bar (instead, it helps build the "download" progress bar).

So you should focus your troubleshooting efforts elsewhere. Perhaps try some of the troubleshooting strategies that I've already outlined in this thread.
__________________
Regards, R.J.

---------------------------------------------------------

Help spread the word! Like my YouTube-to-Mp3 Web Conversion Software on Facebook !! :)
chump2877 is offline   Reply With Quote
Old 02-22-2012, 02:31 PM   PM User | #205
bedo1975
New Coder

 
Join Date: Feb 2012
Posts: 29
Thanks: 1
Thanked 0 Times in 0 Posts
bedo1975 is an unknown quantity at this point
yes I look with firebug, but i don't see any errors.

So in the youtube class if I keep this :

$exec_string = parent::_FFMPEG.' -i '.$this->GetTempVidFileName().' -y -acodec libmp3lame -ab '.$quality.'k '.$this->GetSongFileName() . ' 2> logs/' . $this->_uniqueID . '.txt';


the curl fonction don't work, so if I remplace with :

= 'ffmpeg -i '.$this->GetTempVidFileName().' -y -acodec libmp3lame -ab '.$quality.'k '.$this->GetSongFileName() . ' 2> logs/' . $this->_uniqueID . '.txt';

curl run correctly, but the progress conversion not show too with this modification

I've verify, in config and my contant _FFMPEG are correctly /usr/local/bin/ffmpeg

I search , I search but
bedo1975 is offline   Reply With Quote
Old 02-22-2012, 03:05 PM   PM User | #206
chump2877
Senior Coder

 
chump2877's Avatar
 
Join Date: Dec 2004
Location: the U.S. of freakin' A.
Posts: 2,530
Thanks: 15
Thanked 128 Times in 121 Posts
chump2877 is on a distinguished road
If constant _FFMPEG equals '/usr/local/bin/ffmpeg', then your FFMPEG command should read:

PHP Code:
$exec_string '/usr/local/bin/ffmpeg -i '.$this->GetTempVidFileName().' -y -acodec libmp3lame -ab '.$quality.'k '.$this->GetSongFileName() . ' 2> logs/' $this->_uniqueID '.txt'
__________________
Regards, R.J.

---------------------------------------------------------

Help spread the word! Like my YouTube-to-Mp3 Web Conversion Software on Facebook !! :)
chump2877 is offline   Reply With Quote
Old 02-22-2012, 03:36 PM   PM User | #207
bedo1975
New Coder

 
Join Date: Feb 2012
Posts: 29
Thanks: 1
Thanked 0 Times in 0 Posts
bedo1975 is an unknown quantity at this point
okay chump, with firebug this is that I'm detected :

data : "uniqueId=1329924692_4f450a54152a66.99442542&logLength=" + conversionLogLength + "&mp3File=" + encodeURI(songFile),


as you see, the uniqueId is not empty but the rest converisonLogLength etc ... are empty ! is it normal ?
bedo1975 is offline   Reply With Quote
Old 02-22-2012, 07:10 PM   PM User | #208
bedo1975
New Coder

 
Join Date: Feb 2012
Posts: 29
Thanks: 1
Thanked 0 Times in 0 Posts
bedo1975 is an unknown quantity at this point
sorry chump, but I just see this in firebug :

the AJAX requests in Firebug continue on indefinitely even after the page has stopped loading. Mark : jquery.min.js
bedo1975 is offline   Reply With Quote
Old 02-22-2012, 09:16 PM   PM User | #209
chump2877
Senior Coder

 
chump2877's Avatar
 
Join Date: Dec 2004
Location: the U.S. of freakin' A.
Posts: 2,530
Thanks: 15
Thanked 128 Times in 121 Posts
chump2877 is on a distinguished road
Quote:
Originally Posted by bedo1975 View Post
sorry chump, but I just see this in firebug :

the AJAX requests in Firebug continue on indefinitely even after the page has stopped loading. Mark : jquery.min.js
What is the video you are trying to convert? I can try to convert it here and see if it works.

What kind of server setup do you have?

Can you at least temporarily put your code online, give me the URL, and let me have a look at the AJAX requests?
__________________
Regards, R.J.

---------------------------------------------------------

Help spread the word! Like my YouTube-to-Mp3 Web Conversion Software on Facebook !! :)
chump2877 is offline   Reply With Quote
Old 02-23-2012, 07:11 AM   PM User | #210
bedo1975
New Coder

 
Join Date: Feb 2012
Posts: 29
Thanks: 1
Thanked 0 Times in 0 Posts
bedo1975 is an unknown quantity at this point
hi chump, this is the url, the video that I can to convert is, the url of example.

http://onlinemyclip.com/Dev3/phptube2/

I use a linux server based on centos

ffmpeg-php are correctly enabled is the phpinfo
bedo1975 is offline   Reply With Quote
Reply

Bookmarks

Tags
audio, class, conversion, dailymotion, ffmpeg, mp3, php, script, video, youtube

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 10:55 PM.


Advertisement
Log in to turn off these ads.