Esempio n. 1
0
    /**
     * CONVERT VIDEOS TO FLV FORMAT
     * @param database A database connector object
     */
	function extract($path_new, $output)
	{
		defined('DS') ? null : define('DS', DIRECTORY_SEPARATOR);
		defined('CONVERTPATH') ? null : define('CONVERTPATH', dirname(__FILE__));

		if(substr(PHP_OS, 0, 3) == "WIN")
		{
			defined('JPATH_SITE') ? null : define('JPATH_SITE', str_replace("\components\com_hwdvideoshare\converters", "", CONVERTPATH) );
		}
		else
		{
			defined('JPATH_SITE') ? null : define('JPATH_SITE', str_replace("/components/com_hwdvideoshare/converters", "", CONVERTPATH) );
		}

		// get hwdVideoShare general settings
		include_once(JPATH_SITE.DS.'administrator'.DS.'components'.DS.'com_hwdvideoshare'.DS.'config.hwdvideoshare.php');
		$c = hwd_vs_Config::get_instance();

		// get hwdVideoShare server settings
		include_once(JPATH_SITE.DS.'administrator'.DS.'components'.DS.'com_hwdvideoshare'.DS.'serverconfig.hwdvideoshare.php');
		$s = hwd_vs_SConfig::get_instance();

		$result = array();
		$full_sec = '';
		$half_sec = '';

		$extension = "ffmpeg";
		$extension_soname = $extension . "." . PHP_SHLIB_SUFFIX;
		$extension_fullname = PHP_EXTENSION_DIR . "/" . $extension_soname;

		// Try to load extension
		// If extension is not loaded, don't try! Instead, grep for duration from shell output.

		if(extension_loaded($extension))
		{
			$video_info = @new ffmpeg_movie($path_new); //duration of new flv file.
			if ($video_info)
			{
				$full_sec = $video_info->getDuration(); // Gets the duration in secs.
			}
		}

		if(empty($full_sec) && $c->encoder == "MENCODER" && !empty($output))
		{
			if (preg_match('/Video stream:.*bytes..(.*?).sec/', $output, $regs))
			{
				$full_sec = $regs[1];
			}
		}

		if(empty($full_sec))
		{
			$cmd_input_ffmpeg = "$s->ffmpegpath -i $path_new";
			@exec("$sharedlib $cmd_input_ffmpeg 2>&1", $cmd_output_ffmpeg);
			$cmd_output_ffmpeg = implode($cmd_output_ffmpeg);

			if (@preg_match('/Duration:.(.*?),.start/', $cmd_output_ffmpeg, $regs))
			{
				$full_sec = hwd_vs_ConverterTools::hms2sec($regs[1]);
			}
		}

		if ($full_sec == "" || !is_numeric($full_sec)) {
			$full_sec = 2;
		}

		//get the middle of the movie (time; 00:00:00 format) for thumbnail
		$half_sec = $full_sec / 2;
		$half_sec = @round($half_sec);

		$result    = array();
		$result[0] = hwd_vs_ConverterTools::sec2hms($full_sec); // result of full duration
		$result[1] = hwd_vs_ConverterTools::sec2hms($half_sec); // result of mid-point duration
		$result[2] = 0;                                         // status of ffmpeg-php extension
		$result[3] = '';                                        // holder for output text

		if(extension_loaded($extension)) {
		    $result[2] = 1;
		}

		$result = hwd_vs_ExtractDuration::generateOutput($result);
		return $result;
	}