ILIAS  Release_5_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
ilFFmpeg Class Reference

FFmpeg wrapper. More...

+ Collaboration diagram for ilFFmpeg:

Public Member Functions

 getPossibleTargetMimeTypes ($a_source_mime_type)
 Get possible target formats.
 exec ($args)
 Execute ffmpeg.
 getFileInfo ()
 Get file info.
 getLastReturnValues ()
 Get last return values.

Static Public Member Functions

static enabled ()
 Checks, whether FFmpeg support is enabled (path is set in the setup)
static getTargetMimeTypes ()
 Get target mime types.
static getSourceMimeTypes ()
 Get source mime types.
static supportsImageExtraction ($a_mime)
 Check if mime type supports image extraction.
static getSupportedCodecsInfo ()
 Get all supported codecs.
static getSupportedFormatsInfo ()
 Get all supported formats.
static convert ($a_file, $a_target_mime, $a_target_dir="", $a_target_filename="")
 Convert file to target mime type.
static extractImage ($a_file, $a_target_filename, $a_target_dir="", $a_sec=1)
 Extract image from video file.

Static Public Attributes

static $formats
 Formats handled by ILIAS.
static $last_return = array()

Static Private Member Functions

static getCmd ()
 Get ffmpeg command.

Detailed Description

FFmpeg wrapper.

Author
Alex Killing alex..nosp@m.kill.nosp@m.ing@g.nosp@m.mx.d.nosp@m.e
Version
$Id$ /

Definition at line 12 of file class.ilFFmpeg.php.

Member Function Documentation

static ilFFmpeg::convert (   $a_file,
  $a_target_mime,
  $a_target_dir = "",
  $a_target_filename = "" 
)
static

Convert file to target mime type.

Parameters
string$a_filesource file (full path included)
string$a_target_mimetarget mime type
string$a_target_dirtarget directory (no trailing "/")
string$a_target_filenametarget file name (no path!)
Returns
string new file (full path)

Definition at line 203 of file class.ilFFmpeg.php.

References $cmd, $ret, ilUtil\escapeShellArg(), and exec().

{
return; // currently not supported
if (self::$formats[$a_target_mime]["target"] != true)
{
include_once("./Services/MediaObjects/exceptions/class.ilFFmpegException.php");
throw new ilFFmpegException("Format ".$a_target_mime." is not supported");
}
$pars = self::$formats[$a_target_mime]["parameters"];
$spi = pathinfo($a_file);
// use source directory if no target directory is passed
$target_dir = ($a_target_dir != "")
? $a_target_dir
: $spi['dirname'];
// use source filename if no target filename is passed
$target_filename = ($a_target_filename != "")
? $a_target_filename
: $spi['filename'].".".self::$formats[$a_target_mime]["suffix"];
$target_file = $target_dir."/".$target_filename;
$cmd = "-y -i ".ilUtil::escapeShellArg($a_file)." ".$pars." ".ilUtil::escapeShellArg($target_file);
$ret = self::exec($cmd." 2>&1");
self::$last_return = $ret;
if (is_file($target_file))
{
return $target_file;
}
else
{
include_once("./Services/MediaObjects/exceptions/class.ilFFmpegException.php");
throw new ilFFmpegException("It was not possible to convert file ".basename($a_file).".");
}
//ffmpeg -i MOV012.3gp -vcodec libx264 -strict experimental -acodec aac -sameq -ab 64k -ar 44100 MOV012.mp4
}

+ Here is the call graph for this function:

static ilFFmpeg::enabled ( )
static

Checks, whether FFmpeg support is enabled (path is set in the setup)

Parameters
@return

Definition at line 51 of file class.ilFFmpeg.php.

Referenced by ilObjMediaCastGUI\editCastItemObject().

{
if (defined("PATH_TO_FFMPEG") && PATH_TO_FFMPEG != "")
{
return true;
}
return false;
}

+ Here is the caller graph for this function:

ilFFmpeg::exec (   $args)

Execute ffmpeg.

Parameters
@return

Definition at line 152 of file class.ilFFmpeg.php.

References ilUtil\execQuoted().

Referenced by convert(), extractImage(), getSupportedCodecsInfo(), and getSupportedFormatsInfo().

{
return ilUtil::execQuoted(self::getCmd(), $args);
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static ilFFmpeg::extractImage (   $a_file,
  $a_target_filename,
  $a_target_dir = "",
  $a_sec = 1 
)
static

Extract image from video file.

Parameters
string$a_filesource file (full path included)
string$a_target_dirtarget directory (no trailing "/")
string$a_target_filenametarget file name (no path!)
Returns
string new file (full path)

Definition at line 264 of file class.ilFFmpeg.php.

References $cmd, $ret, ilUtil\escapeShellArg(), and exec().

Referenced by ilObjMediaCastGUI\extractPreviewImageObject(), and ilDataCollectionDatatype\parseValue().

{
//echo "-$a_file-$a_target_filename-$a_target_dir-$a_sec-<br>";
$spi = pathinfo($a_file);
// use source directory if no target directory is passed
$target_dir = ($a_target_dir != "")
? $a_target_dir
: $spi['dirname'];
$target_file = $target_dir."/".$a_target_filename;
$sec = (int) $a_sec;
$cmd = "-y -i ".ilUtil::escapeShellArg($a_file)." -r 1 -f image2 -vframes 1 -ss ".$sec." ".ilUtil::escapeShellArg($target_file);
//echo "-$cmd-"; exit;
$ret = self::exec($cmd." 2>&1");
self::$last_return = $ret;
if (is_file($target_file))
{
return $target_file;
}
else
{
include_once("./Services/MediaObjects/exceptions/class.ilFFmpegException.php");
throw new ilFFmpegException("It was not possible to extract an image from ".basename($a_file).".");
}
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static ilFFmpeg::getCmd ( )
staticprivate

Get ffmpeg command.

Definition at line 141 of file class.ilFFmpeg.php.

{
return PATH_TO_FFMPEG;
}
ilFFmpeg::getFileInfo ( )

Get file info.

Parameters
@return

Definition at line 187 of file class.ilFFmpeg.php.

{
//$info = `ffmpeg -i $path$file 2>&1 /dev/null`;
//@fields = split(/\n/, $info);
}
ilFFmpeg::getLastReturnValues ( )

Get last return values.

Parameters
@return

Definition at line 250 of file class.ilFFmpeg.php.

References $last_return.

Referenced by ilObjMediaCastGUI\convertFileObject(), and ilObjMediaCastGUI\extractPreviewImageObject().

{
}

+ Here is the caller graph for this function:

ilFFmpeg::getPossibleTargetMimeTypes (   $a_source_mime_type)

Get possible target formats.

Parameters
@return

Definition at line 121 of file class.ilFFmpeg.php.

{
$pt = array();
if (in_array($a_source_mime_type, self::getSourceMimeTypes()))
{
foreach (self::getTargetMimeTypes() as $tm)
{
if ($tm != $a_source_mime_type)
{
$pt[$tm] = $tm;
}
}
}
return $pt;
}
static ilFFmpeg::getSourceMimeTypes ( )
static

Get source mime types.

Parameters
@return

Definition at line 88 of file class.ilFFmpeg.php.

{
$ttypes = array();
foreach (self::$formats as $k => $f)
{
if ($f["source"] == true)
{
$ttypes[] = $k;
}
}
return $ttypes;
}
static ilFFmpeg::getSupportedCodecsInfo ( )
static

Get all supported codecs.

Returns

Definition at line 162 of file class.ilFFmpeg.php.

References exec().

{
$codecs = self::exec("-codecs");
return $codecs;
}

+ Here is the call graph for this function:

static ilFFmpeg::getSupportedFormatsInfo ( )
static

Get all supported formats.

Returns

Definition at line 174 of file class.ilFFmpeg.php.

References $formats, and exec().

Referenced by ilObjMediaObjectGUI\showVideoToolObject().

{
$formats = self::exec("-formats");
return $formats;
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static ilFFmpeg::getTargetMimeTypes ( )
static

Get target mime types.

(Please note, that we do not list all possible encoders here, only the ones that are desired for the use in ILIAS)

Parameters
@return

Definition at line 69 of file class.ilFFmpeg.php.

{
$ttypes = array();
foreach (self::$formats as $k => $f)
{
if ($f["target"] == true)
{
$ttypes[] = $k;
}
}
return $ttypes;
}
static ilFFmpeg::supportsImageExtraction (   $a_mime)
static

Check if mime type supports image extraction.

Parameters
string$a_mimemime type

Definition at line 106 of file class.ilFFmpeg.php.

Referenced by ilObjMediaCastGUI\editCastItemObject(), and ilDataCollectionDatatype\parseValue().

{
if (in_array($a_mime, self::getSourceMimeTypes()))
{
return true;
}
return false;
}

+ Here is the caller graph for this function:

Field Documentation

ilFFmpeg::$formats
static
Initial value:
array(
"video/3pgg" => array(
"source" => true,
"target" => false
),
"video/x-flv" => array(
"source" => true,
"target" => false
),
"video/mp4" => array(
"source" => true,
"target" => true,
"parameters" => "-vcodec libx264 -strict experimental -acodec aac -sameq -ab 56k -ar 48000",
"suffix" => "mp4"
),
"video/webm" => array(
"source" => true,
"target" => true,
"parameters" => "-strict experimental -vcodec libvpx -acodec vorbis -ac 2 -sameq -ab 56k -ar 48000",
"suffix" => "webm"
)
)

Formats handled by ILIAS.

Note: In general the mime types do not reflect the complexity of media container/codec variants. For source formats no specification is needed here. For target formats we use fixed parameters that should result in best web media practice.

Definition at line 20 of file class.ilFFmpeg.php.

Referenced by getSupportedFormatsInfo().

ilFFmpeg::$last_return = array()
static

Definition at line 43 of file class.ilFFmpeg.php.

Referenced by getLastReturnValues().


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