public static function getTranscodeRows( $file ){
		global $wgUser;
		$o='';
		$transcodeRows = WebVideoTranscode::getTranscodeState( $file->getTitle()->getDbKey() );
		
		foreach( $transcodeRows as $transcodeKey => $state ){
			$o.='<tr>';
			// Status: 
			$o.='<td>' . self::getStatusMsg( $file, $state ) . '</td>';						
			
			// Encode info:
			$o.='<td>' . wfMsgHtml('timedmedia-derivative-desc-' . $transcodeKey ) . '</td>';

			// Download file
			$o.='<td>';
			$o.= ( !is_null( $state['time_success'] ) ) ? 				
				'<a href="'.self::getSourceUrl( $file, $transcodeKey ) .'" title="'.wfMsg('timedmedia-download' ) .'"><div class="download-btn"></div></a></td>' :
				wfMsgHtml('timedmedia-not-ready' );
			$o.='</td>';
			
			// Check if we should include actions: 
			if( $wgUser->isAllowed( 'transcode-reset' ) ){
				// include reset transcode action buttons
				$o.='<td class="transcodereset"><a href="#" data-transcodekey="' . htmlspecialchars( $transcodeKey ). '">' . wfMsg('timedmedia-reset') . '</a></td>';
			}
			$o.='</tr>';
		}
		return $o;
	}
Пример #2
0
 public function execute()
 {
     $pageIds = $this->getPageSet()->getAllTitlesByNamespace();
     // Make sure we have files in the title set:
     if (!empty($pageIds[NS_FILE])) {
         $titles = array_keys($pageIds[NS_FILE]);
         asort($titles);
         // Ensure the order is always the same
         $result = $this->getResult();
         $images = RepoGroup::singleton()->findFiles($titles);
         foreach ($images as $img) {
             // if its a "transcode" add the transcode status table output
             if (TimedMediaHandlerHooks::isTranscodableTitle($img->getTitle())) {
                 $transcodeStatus = WebVideoTranscode::getTranscodeState($img->getTitle()->getDBKey());
                 // remove useless properties
                 foreach ($transcodeStatus as $key => &$val) {
                     unset($val['id']);
                     unset($val['image_name']);
                     unset($val['key']);
                 }
                 $result->addValue(array('query', 'pages', $img->getTitle()->getArticleID()), 'transcodestatus', $transcodeStatus);
             }
         }
     }
 }
	static function getInfo( $file, $prop, $result, $thumbParams = null, $version = 'latest' ) {
		$vals = parent::getInfo( $file, $prop, $result, $thumbParams = null );
		if( isset( $prop['derivatives'] ) ){
			$vals['derivatives'] = WebVideoTranscode::getSources( $file, array( 'nodata', 'fullurl') );
		}	
		return $vals;
	}
	static public function checkTimeSinceLastRest( $fileName, $transcodeKey ){
		global $wgWaitTimeForTranscodeReset;
		$transcodeStates = WebVideoTranscode::getTranscodeState( $fileName );
		if( $transcodeKey ){
			if( ! $transcodeStates[$transcodeKey] ){
				// transcode key not found 
				return $wgWaitTimeForTranscodeReset + 1;
			} 
			return self::getStateResetTime( $transcodeStates[$transcodeKey] );
		}
		// least wait is set to reset time:
		$leastWait = $wgWaitTimeForTranscodeReset + 1;
		// else check for lowest reset time
		foreach($transcodeStates as $tk => $state ){
			$ctime = self::getStateResetTime( $state );
			if( $ctime < $leastWait){
				$leastWait = $ctime;
			}
		}
		return $leastWait;
	}
	public static function checkArticleDeleteComplete( &$article, &$user, $reason, $id  ){
		// Check if the article is a file and remove transcode files:
		if( $article->getTitle()->getNamespace() == NS_FILE ) {
			$file = wfFindFile( $article->getTitle() );
			if( self::isTranscodableFile( $file ) ){
				WebVideoTranscode::removeTranscodes( $file );
			}
		} 
		return true;
	}
	/**
	 * Get derivative "source" attributes
	 */
	static public function getDerivativeSourceAttributes($file, $transcodeKey, $options = array() ){
		$dataPrefix = in_array( 'nodata', $options )? '': 'data-';


		$fileName = $file->getTitle()->getDbKey();

		$thumbName = $file->thumbName( array() );
		$thumbUrl = $file->getThumbUrl( $thumbName );
		$thumbUrlDir = dirname( $thumbUrl );

		list( $width, $height ) = WebVideoTranscode::getMaxSizeTransform(
			$file,
			self::$derivativeSettings[$transcodeKey]['maxSize']
		);

		$framerate = ( isset( self::$derivativeSettings[$transcodeKey]['framerate'] ) )?
						self::$derivativeSettings[$transcodeKey]['framerate'] :
						$file->getHandler()->getFramerate( $file );
		// Setup the url src:
		$src = $thumbUrlDir . '/' .$file->getName() . '.' . $transcodeKey;
		$src = in_array( 'fullurl', $options)?  wfExpandUrl( $src ) : $src;
		return array(
				'src' => $src,
				'title' => wfMsg('timedmedia-derivative-desc-' . $transcodeKey ),
				"{$dataPrefix}shorttitle" => wfMsg('timedmedia-derivative-' . $transcodeKey),

				// Add data attributes per emerging DASH / webTV adaptive streaming attributes
				// eventually we will define a manifest xml entry point.
				"{$dataPrefix}width" => $width,
				"{$dataPrefix}height" => $height,
				// a "ready" transcode should have a bitrate:
				"{$dataPrefix}bandwidth" => self::$transcodeState[$fileName][ $transcodeKey ]['final_bitrate'],
				"{$dataPrefix}framerate" => $framerate,
			);
	}
	/**
	 * ffmpeg2Theora mapping is much simpler since it is the basis of the the firefogg API
	 */
	function ffmpeg2TheoraEncode( $options){
		global $wgFFmpeg2theoraLocation;

		// Set up the base command
		$cmd = wfEscapeShellArg( $wgFFmpeg2theoraLocation ) . ' ' . wfEscapeShellArg( $this->getSourceFilePath() );

		$file = wfLocalFile( $this->title );

		if( isset( $options['maxSize'] ) ){
			list( $width, $height ) = WebVideoTranscode::getMaxSizeTransform( $file, $options['maxSize'] );
			$options['width'] = $width;
			$options['height'] = $height;
			$options['aspect'] = $width . ':' . $height;
			unset( $options['maxSize'] );
		}

		// Add in the encode settings
		foreach( $options as $key => $val ){
			if( isset( self::$foggMap[$key] ) ){
				if( is_array(  self::$foggMap[$key] ) ){
					$cmd.= ' '. implode(' ', WebVideoTranscode::$foggMap[$key] );
				} elseif ($val == 'true' || $val === true){
			 		$cmd.= ' '. self::$foggMap[$key];
				} elseif ( $val === false){
					//ignore "false" flags
				} else {
					//normal get/set value
					$cmd.= ' '. self::$foggMap[$key] . ' ' . wfEscapeShellArg( $val );
				}
			}
		}

		// Add the output target:
		$cmd.= ' -o ' . wfEscapeShellArg ( $this->getTargetEncodePath() );

		$this->output( "Running cmd: \n\n" .$cmd . "\n" );

		wfProfileIn( 'ffmpeg2theora_encode' );
		$retval = 0;
		$shellOutput = $this->runShellExec( $cmd, $retval );
		wfProfileOut( 'ffmpeg2theora_encode' );
		if( $retval != 0 ){
			return $cmd . "\n\n" . $shellOutput;
		}
		return true;
	}
	function getMediaSources(){
		if( !$this->sources ){
			// Generate transcode jobs ( and get sources that area already transcoded)
			// At a minimum this should return the source video file. 
			$this->sources = WebVideoTranscode::getSources( $this->file );	
			// Check if we have "start or end" times and append the temporal url fragment hash
			foreach( $this->sources as &$source ){
				$source['src'].= $this->getTemporalUrlHash();
			}			
		}
		return $this->sources;
	}