Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 20 of 79 FirstFirst ... 1018192021223070 ... LastLast
Results 286 to 300 of 1174
Like Tree5Likes

Thread: YouTube-to-MP3 conversion - PHP class and script

  1. #286
    Senior Coder chump2877's Avatar
    Join Date
    Dec 2004
    Location
    the U.S. of freakin' A.
    Posts
    2,778
    Thanks
    19
    Thanked 155 Times in 146 Posts
    Quote Originally Posted by cana888 View Post
    finaly script working: http://zaap.ch
    only problem are converting taking to long time...

    Any ide why?

    My server:
    Dualcore 2.93GHz
    2GB Ram
    Paste here the log file that is generated....it's like your FFMPEG command (file conversion) is moving in slow motion...very odd
    Regards, R.J.

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

    Help spread the word! Like my YouTube-to-Mp3 Conversion Script on Facebook !! :)
    [Related videos and tutorials are also available at my YouTube channel and on Dailymotion]
    Get free updates about new software version releases, features, and bug fixes!

  2. #287
    New Coder
    Join Date
    Feb 2012
    Posts
    26
    Thanks
    9
    Thanked 0 Times in 0 Posts
    Everybody's asking help, nobody's providing linux console based guide.

  3. #288
    New Coder
    Join Date
    Feb 2012
    Posts
    15
    Thanks
    4
    Thanked 0 Times in 0 Posts

  4. #289
    Senior Coder chump2877's Avatar
    Join Date
    Dec 2004
    Location
    the U.S. of freakin' A.
    Posts
    2,778
    Thanks
    19
    Thanked 155 Times in 146 Posts
    Quote Originally Posted by cana888 View Post
    For reasons unknown to me, your FFMPEG command is outputing video as well as audio...so you are converting the FLV to both MP3 and to some video format (vp8 or png?)...FFMPEG is putting the newly-encoded audio data into the MP3 file, and the newly-encoded video data is going into the same MP3 file or nowhere at all...So I'd guess that the reason your conversion is taking so long is because you are encoding the input FLV into both audio and video formats...

    Have you modified the FFMPEG command in some way to output video as well as audio? Have you modified the command in any way? If so, can you paste the command here?

    If you haven't modified the command, then I'd guess (again) that you have somehow managed to install/configure ffmpeg-php, ffmpeg, or any relevant codecs incorrectly.
    Regards, R.J.

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

    Help spread the word! Like my YouTube-to-Mp3 Conversion Script on Facebook !! :)
    [Related videos and tutorials are also available at my YouTube channel and on Dailymotion]
    Get free updates about new software version releases, features, and bug fixes!

  5. #290
    Senior Coder chump2877's Avatar
    Join Date
    Dec 2004
    Location
    the U.S. of freakin' A.
    Posts
    2,778
    Thanks
    19
    Thanked 155 Times in 146 Posts
    Quote Originally Posted by zemaitis View Post
    Everybody's asking help, nobody's providing linux console based guide.
    I think that (or something like that) would eliminate the majority of these strange problems that people are having...
    Regards, R.J.

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

    Help spread the word! Like my YouTube-to-Mp3 Conversion Script on Facebook !! :)
    [Related videos and tutorials are also available at my YouTube channel and on Dailymotion]
    Get free updates about new software version releases, features, and bug fixes!

  6. #291
    New Coder
    Join Date
    Feb 2012
    Posts
    24
    Thanks
    0
    Thanked 3 Times in 3 Posts
    Quote Originally Posted by cana888 View Post
    finaly script working: http://zaap.ch
    only problem are converting taking to long time...

    Any ide why?

    My server:
    Dualcore 2.93GHz
    2GB Ram
    looking good... it may be the amount of ram.. cpu should be good. my servers are all at minimum 8 cores 2.6+ with 16 gig ram. I check a home server later and see what i get for conversion speed. but other than that unsure off hand.

  7. #292
    New Coder
    Join Date
    Feb 2012
    Posts
    15
    Thanks
    4
    Thanked 0 Times in 0 Posts
    i have modified just ffmpeg_progress.php using: YouTube-to-MP3 conversion - PHP class and script
    post from: bedo1975

    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 ) {
                                 $count=count($times[0]);
                                 for($i=0;$i<$count;$i++)
                                 { 
                                 $numTimes = $times[0][$i];
                                 $parse_numTimes =  list($hours,$minutes,$seconds,$mili) = split(':',$numTimes);
                                 $seconds_numTimes  = $hours * 3600 + $minutes * 60 + $seconds;
                                 $progress = round(($seconds_numTimes / $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;
    
    ?>

  8. #293
    New Coder
    Join Date
    Feb 2012
    Posts
    24
    Thanks
    0
    Thanked 3 Times in 3 Posts
    Quote Originally Posted by zemaitis View Post
    Everybody's asking help, nobody's providing linux console based guide.
    All work i do is in linux counsel

  9. #294
    New Coder
    Join Date
    Feb 2012
    Posts
    24
    Thanks
    0
    Thanked 3 Times in 3 Posts
    Quote Originally Posted by cana888 View Post
    i have modified just ffmpeg_progress.php using: YouTube-to-MP3 conversion - PHP class and script
    post from: bedo1975

    [CODE]
    post your YouTubeToMp3Converter.class.php file

    the ffmpeg conversion is in there

    also what distro are you using

  10. #295
    New Coder
    Join Date
    Feb 2012
    Posts
    24
    Thanks
    0
    Thanked 3 Times in 3 Posts
    added a switch to the ffmpeg command to output the sound a little louder.

    take this line in the YouTubeToMp3Converter.class.php

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

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

    256 is normal
    512 is rougly 1.5x louder 768 is 2x 1024 is 2.5x

  11. Users who have thanked drakus for this post:

    chump2877 (03-04-2012)

  12. #296
    Senior Coder chump2877's Avatar
    Join Date
    Dec 2004
    Location
    the U.S. of freakin' A.
    Posts
    2,778
    Thanks
    19
    Thanked 155 Times in 146 Posts
    Quote Originally Posted by drakus View Post
    added a switch to the ffmpeg command to output the sound a little louder.

    the -vol switch works like this

    256 is normal
    512 is rougly 1.5x louder 768 is 2x 1024 is 2.5x
    Neat! Thanks for the tip

    I'm going to add this option to the config class and it will be a part of the next release...

    Just curious: Have you noticed any distortion in the sound when increasing the volume this way?
    Regards, R.J.

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

    Help spread the word! Like my YouTube-to-Mp3 Conversion Script on Facebook !! :)
    [Related videos and tutorials are also available at my YouTube channel and on Dailymotion]
    Get free updates about new software version releases, features, and bug fixes!

  13. #297
    New Coder
    Join Date
    Feb 2012
    Posts
    24
    Thanks
    0
    Thanked 3 Times in 3 Posts
    Quote Originally Posted by chump2877 View Post
    Neat! Thanks for the tip

    I'm going to add this option to the config class and it will be a part of the next release...

    Just curious: Have you noticed any distortion in the sound when increasing the volume this way?
    none what so ever. i have been using the 768 option and they have been sounding good on anything i play them on. my djs have said the same thing. so i guess it is all good

    If you are going to add it.

    use 256 (normal) & 768 (2x) options only no real dif in the 512 (1.5x)or 1024 2.5x

    also the vol option is basically undocumented.

  14. #298
    Senior Coder chump2877's Avatar
    Join Date
    Dec 2004
    Location
    the U.S. of freakin' A.
    Posts
    2,778
    Thanks
    19
    Thanked 155 Times in 146 Posts
    Quote Originally Posted by drakus View Post
    none what so ever. i have been using the 768 option and they have been sounding good on anything i play them on. my djs have said the same thing. so i guess it is all good

    If you are going to add it.

    use 256 (normal) & 768 (2x) options only no real dif in the 512 (1.5x)or 1024 2.5x

    also the vol option is basically undocumented.
    I have it set at 256 by default with the option to increase it to whatever the user wants...

    And lots of ffmpeg documentation is hard to find, for sure! So I appreciate the tip...
    Regards, R.J.

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

    Help spread the word! Like my YouTube-to-Mp3 Conversion Script on Facebook !! :)
    [Related videos and tutorials are also available at my YouTube channel and on Dailymotion]
    Get free updates about new software version releases, features, and bug fixes!

  15. #299
    New Coder
    Join Date
    Feb 2012
    Posts
    24
    Thanks
    0
    Thanked 3 Times in 3 Posts
    Quote Originally Posted by chump2877 View Post
    I have it set at 256 by default with the option to increase it to whatever the user wants...

    And lots of ffmpeg documentation is hard to find, for sure! So I appreciate the tip...
    anytime. back to work on the install script

  16. #300
    New Coder
    Join Date
    Feb 2012
    Posts
    15
    Thanks
    4
    Thanked 0 Times in 0 Posts
    drakus here is my YouTubeToMp3Converter.class.php file

    PHP 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().' -vol 768 -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($chCURLOPT_URL$ffmpegExecUrl);
                
    curl_setopt($chCURLOPT_POSTTRUE);
                
    curl_setopt($chCURLOPT_POSTFIELDS$postData);
                
    curl_setopt($chCURLOPT_RETURNTRANSFERTRUE);
                
    curl_setopt($chCURLOPT_TIMEOUT1);
                
    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/$downloadSize2) * 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($chCURLOPT_FILE$file);
                
    curl_setopt($chCURLOPT_HEADER0);
                
    curl_setopt($chCURLOPT_URL$url);
                
    curl_setopt($chCURLOPT_FOLLOWLOCATION1);
                
    curl_setopt($chCURLOPT_NOPROGRESSfalse);
                
    curl_setopt($chCURLOPT_PROGRESSFUNCTION, array($this'UpdateVideoDownloadProgress'));
                
    curl_setopt($chCURLOPT_BUFFERSIZE4096000);
                
    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
        
    }

    ?>


 
Page 20 of 79 FirstFirst ... 1018192021223070 ... LastLast

LinkBacks (?)

  1. 07-21-2014, 05:32 PM
  2. 07-12-2014, 05:59 PM
  3. 06-26-2014, 03:39 PM
  4. 05-31-2014, 09:13 PM
  5. 04-24-2014, 07:53 PM
  6. 04-19-2014, 10:22 AM
  7. 04-04-2014, 08:33 PM
  8. 04-04-2014, 01:58 AM
  9. 03-28-2014, 06:03 AM
  10. 03-20-2014, 06:11 PM
  11. 03-16-2014, 01:22 AM
  12. 03-08-2014, 04:56 PM
  13. 03-07-2014, 06:21 PM
  14. 03-01-2014, 12:48 PM
  15. 02-22-2014, 08:40 PM
  16. 02-22-2014, 12:02 AM
  17. 02-21-2014, 08:15 PM
  18. 02-21-2014, 12:00 AM
  19. 02-20-2014, 08:37 PM
  20. 02-20-2014, 06:53 PM
  21. 02-20-2014, 03:21 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •