Esempio n. 1
0
   /**
	* start converter
	*/
	function ajaxRecalculateDuration()
	{
		global $limit, $limitstart;
  		$db =& JFactory::getDBO();

		$video_id = Jrequest::getInt( 'cid', '' );

        $db->SetQuery( 'SELECT id, video_id, thumb_snap FROM #__hwdvidsvideos WHERE id = '.$video_id );
        $row = $db->loadObject();

		include_once(JPATH_SITE."/components/com_hwdvideoshare/converters/__ConversionTools.php");
		include_once(JPATH_SITE."/components/com_hwdvideoshare/converters/__ExtractDuration.php");

		if (file_exists(JPATH_SITE.DS."hwdvideos".DS."uploads".DS.$row->video_id.".flv"))
		{
			$path = JPATH_SITE.DS."hwdvideos".DS."uploads".DS.$row->video_id.".flv";
		}
		else
		{
			$path = JPATH_SITE.DS."hwdvideos".DS."uploads".DS.$row->video_id.".mp4";
		}

		$ExtractDuration = hwd_vs_ExtractDuration::extract($path, '');

		if (!empty($ExtractDuration[0]))
		{
			$db->SetQuery("UPDATE #__hwdvidsvideos SET video_length='".$ExtractDuration[0]."' WHERE id = ".$row->id);
			if ( !$db->query() )
			{
				echo $db->getErrorMsg();
				echo "<script type=\"text/javascript\"> alert('".$db->getErrorMsg()."'); window.history.go(-1); </script>\n";
				exit();
			}

			if ($row->thumb_snap == "0:00:00" || $row->thumb_snap == "0:00:01" || $row->thumb_snap == "0:00:02")
			{
				$db->SetQuery("UPDATE #__hwdvidsvideos SET thumb_snap='".$ExtractDuration[1]."' WHERE id = ".$row->id);
				if ( !$db->query() )
				{
					echo "<script type=\"text/javascript\"> alert('".$db->getErrorMsg()."'); window.history.go(-1); </script>\n";
					exit();
				}
			}
		}
		print $ExtractDuration[3];
		exit;
	}
Esempio n. 2
0
		* Process each video file
		**/
		$n = 1;
		while ($result = @mysql_fetch_array($selectBatch)) {

			$filename_noext = $result['video_id'];
			$id = intval($result['id']);

			hwd_vs_ConverterTools::set($row, null, $id);

			$output.= "<div class=\"box\"><div><h2>Re-calculating Duration (File ".$n." of ".$count.")</h2></div>";

				if ($result['video_type'] == "local" || $result['video_type'] == "mp4") {

					$path_new = $path_base . "/uploads/" . $filename_noext . ".flv";
					$ExtractDuration = hwd_vs_ExtractDuration::extract($path_new, '');


				} else if ($result['video_type'] == "swf") {

					$ExtractDuration[0] = "0:00:02";
					$ExtractDuration[1] = "0:00:01";

				} else {

					$ExtractDuration[0] = "0:00:02";
					$ExtractDuration[1] = "0:00:01";

				}

				if ($result['video_length'] == "0:00:02" || $ExtractDuration[0] !== "0:00:02")
Esempio n. 3
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;
	}