CInbox (Common-Inbox)  0.1
Common functionality for ingesting files for archiving.
 All Classes Functions Variables
Public Member Functions | Public Attributes | List of all members
TaskFFmpeg Class Reference
Inheritance diagram for TaskFFmpeg:
TaskExec CITask

Public Member Functions

 __construct (&$CIFolder)
 
- Public Member Functions inherited from TaskExec
 __construct (&$CIFolder)
 
- Public Member Functions inherited from CITask
 __construct (&$CIFolder, $label)
 
 getName ()
 
 setLabel ($label)
 
 getLabel ()
 
 setDescription ($description)
 
 getDescription ()
 
 skip ()
 
 skipIt ()
 
 setItemSubDirs ($itemSubDirs)
 
 getStatus ()
 
 statusUndefined ()
 
 statusRunning ()
 
 statusWait ()
 
 statusDone ()
 
 statusPBCT ()
 
 statusPBC ()
 
 statusSkipped ()
 
 statusError ()
 
 statusConfigError ()
 
 init ()
 
 run ()
 
 finalize ()
 

Public Attributes

const TASK_LABEL = 'Execute FFmpeg for media conversion'
 Human readable task name/label.
 
Task Settings

Names of config settings used by this task

const CONF_SOURCES = "FFMPEG_IN"
 Filenames or filemasks to process as input.
 
const CONF_TARGETS = "FFMPEG_OUT"
 Output filenames (may include path).
 
const CONF_RECIPES = "FFMPEG_RECIPE"
 Commandline "recipes" to execute FFmpeg transcoding, etc. This includes path+name of FFmpeg binary.
 
const CONF_VALIDATES = "FFMPEG_VALIDATE"
 Flag to enable content hash validation. Used to confirm lossless codec or container changes.
 
Array keys

Array keys for handling $todoList.

const TODO_RECIPE = 'recipe'
 Array key for recipe in $todoList.
 
const TODO_IN = 'in'
 Array key for input files in $todoList.
 
const TODO_OUT = 'out'
 Array key for output files in $todoList.
 
const TODO_VALIDATE = 'validate'
 Array key for flag "to validate or not".
 
- Public Attributes inherited from TaskExec
const TASK_LABEL = 'Execute external programs (abstract)'
 
const EXIT_STATUS_DONE = 0
 Success! This means the task completed successfully.
 
const EXIT_STATUS_WAIT = 5
 Task decided that Item is not ready yet and shall be moved back to 'to-do'.
 
const EXIT_STATUS_PBCT = 6
 There were problems, but the task may continue.
 
const EXIT_STATUS_PBC = 7
 There were problems, but subsequent task may continue.
 
const EXIT_STATUS_ERROR = 10
 An error occurred. Abort execution as soon as possible.
 
const EXIT_STATUS_CONFIG_ERROR = 11
 If a config option was not valid.
 
const EXIT_STATUS_SKIPPED = 15
 If task was skipped.
 
- Public Attributes inherited from CITask
const STATUS_UNDEFINED = 0
 Undefined. Default unless task changes it.
 
const STATUS_RUNNING = 1
 Undefined, but indicates that the task is in progress.
 
const STATUS_WAIT = 2
 Task decided that Item is not ready yet and shall be moved back to 'to-do'.
 
const STATUS_DONE = 5
 Success! This means the task completed successfully.
 
const STATUS_PBCT = 6
 There were problems, but the task may continue.
 
const STATUS_PBC = 7
 There were problems, but subsequent task may continue.
 
const STATUS_ERROR = 10
 An error occurred. Abort execution as soon as possible.
 
const STATUS_CONFIG_ERROR = 11
 If a config option was not valid.
 
const STATUS_SKIPPED = 15
 If task was skipped.
 
const ONCE_PER_ITEM = false
 True: Run this task only once per item.
 
const IS_RECURSIVE = false
 Default (false): one task = one folder. True: The task performs actions on subfolders too.
 
const CONF_COPY_EXCLUDE = 'COPY_EXCLUDE'
 Patterns which files to exclude from copying.
 
const MASK_TARGET_TEMP = 'temp_%s'
 

Protected Member Functions

Task-specific methods
 checkArrayKeysMatch ($a1, $a2)
 
 convertFile ($recipe, $sourceFile, $targetFile)
 
 getMatchingFiles ($folder, $patterns)
 
 resolveInOut ($source, $target)
 
 checkTargetExists ($targets)
 
 createTodoList ($sources, $targets, $recipes, $validates)
 
- Protected Member Functions inherited from TaskExec
 isCmdValid ($command)
 
 resolveCmd ($command, $arguments=null)
 
 runScript ($script)
 
 setStatusByExitcode ($exitCode)
 
 getCmdLogfile ($prefix=null)
 
 removeCmdLogfile ($logFile=null)
 
 writeToCmdLogfile ($msg, $logFile=null)
 
- Protected Member Functions inherited from CITask
 setName ($name)
 
 exclude ($file, $excludePatterns)
 
 optionIsArray ($option, $optionName)
 
 resolveTargetFolderTemp ($CIFolder=null)
 
 setStatus ($status)
 
 setStatusUndefined ()
 
 setStatusRunning ()
 
 setStatusWait ()
 
 setStatusDone ()
 
 setStatusPBCT ()
 
 setStatusPBC ()
 
 setStatusSkipped ()
 
 setStatusError ()
 
 setStatusConfigError ()
 
 checkTempFolder ()
 
 getTempFolder ()
 
 setTempFolder ($tempFolder=null)
 
 loadSettings ()
 

Private Attributes

Setting variables

For storing settings read from the config file:

 $sources
 
 $targets
 
 $recipes
 
 $validates
 
Prepared "to-do" list

Recipes and their files to process. Files resolved and ready to use with convertFile().

 $todoList
 Array with all information to start transcoding call.
 
 $filesIn
 
 $filesOut
 

Common task functions

 init ()
 
 run ()
 
 finalize ()
 
 loadSettings ()
 

Additional Inherited Members

- Static Public Member Functions inherited from CITask
static isRecursive ()
 
static oncePerItem ()
 
static getTaskByName ($taskName, $CIFolder)
 
static getTaskClassName ($taskName)
 
- Protected Attributes inherited from TaskExec
 $exec
 
 $logFile
 
- Protected Attributes inherited from CITask
 $logger
 Logging handler.
 
 $name
 Class name of this task.
 
 $label
 Human readable Task label.
 
 $description
 Human readable description of Task's purpose/actions.
 
 $CIFolder
 CIFolder object that provides all information needed for this task.
 
 $sourceFolder
 Source folder of this task.
 
 $targetFolder
 Target folder of this task (read from config).
 
 $targetFolderTemp
 Temporary name of Target folder of this task. Used until inbox processing completed successfully.
 
 $itemSubDirs
 Array of Item subfolders: key=foldername, value=CIFolder (initialized with its config).
 
 $tempFolder
 Path of the temp folder for this task.
 
 $copyExclude
 Contains the value of CONF_COPY_EXCLUDE.
 
 $skip = false
 True: Skip execution. Default=false (=normal execution).
 
 $status
 Status of this task (=for current item subfolder).
 
- Static Protected Attributes inherited from CITask
static $statusGlobal
 Status of the sum of tasks of this type. // TODO! Implement and use this.
 

Detailed Description

Task for executing FFmpeg to convert media files. Simple version.

Allows: 1 input, 1 output file per recipe. For more complex FFmpeg-foo, it's probably better to create a separate task type.

TODO:

Author
Peter Bubestinger-Steindl (pb@av.nosp@m.-rd..nosp@m.com)
See also

Member Function Documentation

TaskFFmpeg::checkArrayKeysMatch (   $a1,
  $a2 
)
protected

Checks if the given arrays have matching keys - in identical order!

Exceptions
ExceptionIf keys/count does /not/ match.
TaskFFmpeg::checkTargetExists (   $targets)
protected

Checks if any of the files listed in $targets exists and sets the task status to "problem but continue task".

TaskFFmpeg::convertFile (   $recipe,
  $sourceFile,
  $targetFile 
)
protected

Converts a single media file from A to B. Uses external command to do this.

Parameters
$recipe[string] Commandline recipe with placeholders.
$sourceFile[string] Source (input) media file to be read.
$targetFile[string] Target (output) media file to be created.
Return values
integer/boolExit code (integer) of executed FFmpeg command (derived from recipe). 'False' if any other error occurred.
TaskFFmpeg::createTodoList (   $sources,
  $targets,
  $recipes,
  $validates 
)
protected

Aligns recipes with resolved sources and targets (

See also
resolveInOut() ). Output is a 'to-do list' where each recipe has its list of files to read and generate in a ready-to-use way for passing it to convertFile().
TaskFFmpeg::finalize ( )

Actions to be performed after run() finished successfully;

Return values
booleanTrue if everything went fine, False if an error occurred.
TaskFFmpeg::getMatchingFiles (   $folder,
  $patterns 
)
protected

Returns array with files/folders within the folder that match the glob patterns in '$patterns'. Relative paths are resolved to their absolute equivalents.

This function is copied from 'TaskFilesMatch' class, but improved here since then. TODO: Move common part to Helper class?

TaskFFmpeg::init ( )

Prepare everything so it's ready for processing.

Return values
booleanTrue if task shall proceed. False if not.
TaskFFmpeg::loadSettings ( )
protected

Load settings from config that are relevant for this task.

Return values
booleanTrue if everything went fine, False if an error occurred.
TaskFFmpeg::resolveInOut (   $source,
  $target 
)
protected

Iterates through options set in '$sources' and resolves it to a single array, where each entry is a single file.

This is used to resolve filemasks (e.g. *.avi, *.mkv, etc), but compatible to setting wildcard-free filenames explicitely in '$sources'.

At the same time, it Iterates through options set in '$targets' and resolves it to a single array, where each entry is also a single filename.

$sources and $targets /must/ always have the same number of entries in matching order, as each IN will be matched to its corresponding OUT setting.

TaskFFmpeg::run ( )

Perform the actual steps of this task.

Return values
booleanTrue if task shall proceed. False if not.

Member Data Documentation

TaskFFmpeg::$filesIn
private
See also
resolveInOut()
TaskFFmpeg::$filesOut
private
See also
resolveInOut()
TaskFFmpeg::$recipes
private
See also
CONF_RECIPES
TaskFFmpeg::$sources
private
See also
CONF_SOURCES
TaskFFmpeg::$targets
private
See also
CONF_TARGETS
TaskFFmpeg::$validates
private
See also
CONF_VALIDATES

The documentation for this class was generated from the following file: