protected function processOutputFilepath($outputPath, $conflictMode, $dirMode)
    {
        $outputIsDirectory = $this->pathIsDirectory($outputPath);

        //check for pre-existing file and handle based on conflict mode
        if (file_exists($outputPath)) {
            if ($conflictMode === self::ONCONFLICT_EXCEPTION) {
                throw new Exception\FileAlreadyExistsException(sprintf("File %s already exists.", $outputPath));
            }

            if ($conflictMode === self::ONCONFLICT_DELETE) {
                if ($outputIsDirectory) {
                    $this->removeDirectory($outputPath);
                } else {
                    @unlink($outputPath);
                }
            }

            if ($conflictMode === self::ONCONFLICT_INCREMENT) {
                $outputPath = $this->incrementConflictingPath($outputPath);
            }
        }

        //check for necessary containing directory creation, handle based on directory mode
        $outputDirectory = dirname($outputPath);

        if (!file_exists($outputDirectory)) {
            if ($dirMode === self::ONDIR_EXCEPTION) {
                throw new Exception\InvalidModeException("The Transcoder is not permitted to create new directories if needed.");
            }

            //try creating the necessary containing directories recursively
            if (!mkdir($outputDirectory, $this->getDirectoryCreationMode(), true)) {
                throw new Exception\FilePermissionException("The required containing directories could not be created.");
            }

            $this->dispatcher->dispatch(TranscodeEvents::DIR_CREATED, new FileEvent($outputDirectory));
        }

        //check for write permissions
        if (!is_writable($outputDirectory)) {
            throw new Exception\FilePermissionException(sprintf("Cannot transcode because the directory %s is not writable.", $outputDirectory));
        }

        //if the output is a directory, make sure the actual required directory is created
        if ($outputIsDirectory) {
            if (!mkdir($outputPath, $this->getDirectoryCreationMode())) {
                throw new Exception\FilePermissionException(sprintf("Could not properly create the required output directory %s.", $outputPath));
            }

            $this->dispatcher->dispatch(TranscodeEvents::DIR_CREATED, new FileEvent($outputDirectory));
        }

        return $outputPath;
    }