public function transcodeWithPreset($inFile, $preset, $outFile = false, $conflictMode = self::ONCONFLICT_INCREMENT, $dirMode = self::ONDIR_EXCEPTION, $failMode = self::ONFAIL_DELETE)
    {
        //figure out input file path and preset key, without throwing exceptions
        $inputPath = ($inFile instanceof File) ? $inFile->getRealPath() : $inFile;
        $presetKey = ($preset instanceof Preset) ? $preset->getKey() : $preset;
        $outFilePath = $outFile;

        //validate all inputs before attempting to run the transcode process
        try {

            //get file
            if (!$inFile instanceof File && is_string($inFile)) {
                $inFile = new File($inFile);
            }

            //get preset
            if (!$preset instanceof Preset) {
                $preset = $this->getPreset($preset);
            }

            //have preset validate file
            $preset->validateInputFile($inFile);

            //get adapter
            $adapter = $this->getAdapter($preset->getRequiredAdapter());

            //verify if this adapter can work in the current environment (happens only the first time it's loaded)
            if (!$adapter->verify()) {
                throw new \RuntimeException($adapter->getVerificationError());
            }

            //have adapter verify inputs
            $adapter->validateInputFile($inFile);
            $adapter->validatePreset($preset);

            //generate the final output string
            $outFilePath = $preset->generateOutputPath($inFile, $outFile);

            //make sure the output path is valid, create any directories as necessary
            $outFilePath = $this->processOutputFilepath($outFilePath, $conflictMode, $dirMode);

        } catch (\Exception $e) {

            //notify listeners of failure
            $this->dispatcher->dispatch(TranscodeEvents::ERROR, new TranscodeEvent($inputPath, $presetKey, $outFilePath, null, $e));

            //rethrow for containing environment to handle
            throw $e;
        }

        //attempt to run the actual transcode process
        try {

            //notify listeners of transcode start
            $this->dispatcher->dispatch(TranscodeEvents::BEFORE, new TranscodeEvent($inputPath, $presetKey, $outFilePath));

            //run the transcode
            $return = $adapter->transcodeFile($inFile, $preset, $outFilePath);

            //validate return
            if (!$return instanceof File) {
                throw new Exception\InvalidOutputException("Adapters must return an instance of AC\Transcoding\File, or throw an exception upon error.");
            }
            $preset->validateOutputFile($return);
            $adapter->validateOutputFile($return);
            $this->cleanOutputFile($return);

            $returnPath = $return->getRealPath();

            //notify listeners of completion
            $this->dispatcher->dispatch(TranscodeEvents::AFTER, new TranscodeEvent($inputPath, $presetKey, $returnPath));

            //notify of new file
            $this->dispatcher->dispatch(TranscodeEvents::FILE_CREATED, new FileEvent($returnPath));

            //return newly created file
            return $return;

        } catch (\Exception $e) {

            //clean up files after failure
            $this->cleanFailedTranscode($adapter, $outFilePath, $failMode);

            //notify listeners of failure
            $this->dispatcher->dispatch(TranscodeEvents::ERROR, new TranscodeEvent($inputPath, $presetKey, $outFilePath, null, $e));

            //re-throw exception so environment can handle appropriately
            throw $e;
        }

        return false;
    }
public function transcodeWithPreset($inFile, $preset, $outFile = false, $conflictMode = self::ONCONFLICT_INCREMENT, $dirMode = self::ONDIR_EXCEPTION, $failMode = self::ONFAIL_DELETE)
    {
        //figure out input file path and preset key, without throwing exceptions
        $inputPath = ($inFile instanceof File) ? $inFile->getRealPath() : $inFile;
        $presetKey = ($preset instanceof Preset) ? $preset->getKey() : $preset;
        $outFilePath = $outFile;

        //validate all inputs before attempting to run the transcode process
        try {

            //get file
            if (!$inFile instanceof File && is_string($inFile)) {
                $inFile = new File($inFile);
            }

            //get preset
            if (!$preset instanceof Preset) {
                $preset = $this->getPreset($preset);
            }

            //have preset validate file
            $preset->validateInputFile($inFile);

            //get adapter
            $adapter = $this->getAdapter($preset->getRequiredAdapter());

            //verify if this adapter can work in the current environment (happens only the first time it's loaded)
            if (!$adapter->verify()) {
                throw new \RuntimeException($adapter->getVerificationError());
            }

            //have adapter verify inputs
            $adapter->validateInputFile($inFile);
            $adapter->validatePreset($preset);

            //generate the final output string
            $outFilePath = $preset->generateOutputPath($inFile, $outFile);

            //make sure the output path is valid, create any directories as necessary
            $outFilePath = $this->processOutputFilepath($outFilePath, $conflictMode, $dirMode);

        } catch (\Exception $e) {

            //notify listeners of failure
            $this->dispatcher->dispatch(TranscodeEvents::ERROR, new TranscodeEvent($inputPath, $presetKey, $outFilePath, null, $e));

            //rethrow for containing environment to handle
            throw $e;
        }

        //attempt to run the actual transcode process
        try {

            //notify listeners of transcode start
            $this->dispatcher->dispatch(TranscodeEvents::BEFORE, new TranscodeEvent($inputPath, $presetKey, $outFilePath));

            //run the transcode
            $return = $adapter->transcodeFile($inFile, $preset, $outFilePath);

            //validate return
            if (!$return instanceof File) {
                throw new Exception\InvalidOutputException("Adapters must return an instance of AC\Transcoding\File, or throw an exception upon error.");
            }
            $preset->validateOutputFile($return);
            $adapter->validateOutputFile($return);
            $this->cleanOutputFile($return);

            $returnPath = $return->getRealPath();

            //notify listeners of completion
            $this->dispatcher->dispatch(TranscodeEvents::AFTER, new TranscodeEvent($inputPath, $presetKey, $returnPath));

            //notify of new file
            $this->dispatcher->dispatch(TranscodeEvents::FILE_CREATED, new FileEvent($returnPath));

            //return newly created file
            return $return;

        } catch (\Exception $e) {

            //clean up files after failure
            $this->cleanFailedTranscode($adapter, $outFilePath, $failMode);

            //notify listeners of failure
            $this->dispatcher->dispatch(TranscodeEvents::ERROR, new TranscodeEvent($inputPath, $presetKey, $outFilePath, null, $e));

            //re-throw exception so environment can handle appropriately
            throw $e;
        }

        return false;
    }
public function transcodeWithPreset ( $ inFile , $ preset , $ outFile = false , $ conflictMode = self :: ONCONFLICT_INCREMENT , $ dirMode = self :: ONDIR_EXCEPTION , $ failMode = self :: ONFAIL_DELETE ) { //figure out input file path and preset key, without throwing exceptions $ inputPath = ( $ inFile instanceof File ) ? $ inFile -> getRealPath ( ) : $ inFile ; $ presetKey = ( $ preset instanceof Preset ) ? $ preset -> getKey ( ) : $ preset ; $ outFilePath = $ outFile ; //validate all inputs before attempting to run the transcode process try { //get file if ( ! $ inFile instanceof File && is_string ( $ inFile ) ) { $ inFile = new File ( $ inFile ) ; } //get preset if ( ! $ preset instanceof Preset ) { $ preset = $ this -> getPreset ( $ preset ) ; } //have preset validate file $ preset -> validateInputFile ( $ inFile ) ; //get adapter $ adapter = $ this -> getAdapter ( $ preset -> getRequiredAdapter ( ) ) ; //verify if this adapter can work in the current environment (happens only the first time it's loaded) if ( ! $ adapter -> verify ( ) ) { throw new \ RuntimeException ( $ adapter -> getVerificationError ( ) ) ; } //have adapter verify inputs $ adapter -> validateInputFile ( $ inFile ) ; $ adapter -> validatePreset ( $ preset ) ; //generate the final output string $ outFilePath = $ preset -> generateOutputPath ( $ inFile , $ outFile ) ; //make sure the output path is valid, create any directories as necessary $ outFilePath = $ this -> processOutputFilepath ( $ outFilePath , $ conflictMode , $ dirMode ) ; } catch ( \ Exception $ e ) { //notify listeners of failure $ this -> dispatcher -> dispatch ( TranscodeEvents :: ERROR , new TranscodeEvent ( $ inputPath , $ presetKey , $ outFilePath , null , $ e ) ) ; //rethrow for containing environment to handle throw $ e ; } //attempt to run the actual transcode process try { //notify listeners of transcode start $ this -> dispatcher -> dispatch ( TranscodeEvents :: BEFORE , new TranscodeEvent ( $ inputPath , $ presetKey , $ outFilePath ) ) ; //run the transcode $ return = $ adapter -> transcodeFile ( $ inFile , $ preset , $ outFilePath ) ; //validate return if ( ! $ return instanceof File ) { throw new Exception \ InvalidOutputException ( "Adapters must return an instance of AC\Transcoding\File, or throw an exception upon error." ) ; } $ preset -> validateOutputFile ( $ return ) ; $ adapter -> validateOutputFile ( $ return ) ; $ this -> cleanOutputFile ( $ return ) ; $ returnPath = $ return -> getRealPath ( ) ; //notify listeners of completion $ this -> dispatcher -> dispatch ( TranscodeEvents :: AFTER , new TranscodeEvent ( $ inputPath , $ presetKey , $ returnPath ) ) ; //notify of new file $ this -> dispatcher -> dispatch ( TranscodeEvents :: FILE_CREATED , new FileEvent ( $ returnPath ) ) ; //return newly created file return $ return ; } catch ( \ Exception $ e ) { //clean up files after failure $ this -> cleanFailedTranscode ( $ adapter , $ outFilePath , $ failMode ) ; //notify listeners of failure $ this -> dispatcher -> dispatch ( TranscodeEvents :: ERROR , new TranscodeEvent ( $ inputPath , $ presetKey , $ outFilePath , null , $ e ) ) ; //re-throw exception so environment can handle appropriately throw $ e ; } return false ; }
The core method of the transcode process.  Takes file input, validates, runs a transcode process, validates return, and returns file output.

@param  mixed  $inFile       - if a string filepath is given instead of an instance of \AC\Transcoding\File, then a new File instance will be created automatically
@param  mixed  $preset       - if a string is given instead of an instance of \AC\Transcoding\Preset, then it will look for a Preset with a name matching the received string
@param  string $outFile      - an optional output file path, even if provided explicity, the Transcoder will validate and process it before starting a transcode process
@param  string $conflictMode - flag for what to do if an output file already exists at the given output path
@param  string $failMode     - flag for what to do with the output file(s) on a failed transcode
@return File   - \AC\Transcoding\File instance for newly created file
The core method of the transcode process . Takes file input validates runs a transcode process validates return and returns file output .