ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
ilFFmpeg Class Reference

FFmpeg wrapper. More...

+ Collaboration diagram for ilFFmpeg:

Public Member Functions

 getFileInfo ()
 Get file info. More...
 

Static Public Member Functions

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

Static Public Attributes

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

Static Private Member Functions

static getCmd ()
 Get ffmpeg command. More...
 

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

◆ convert()

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 194 of file class.ilFFmpeg.php.

195 {
196 return; // currently not supported
197
198 if (self::$formats[$a_target_mime]["target"] != true) {
199 include_once("./Services/MediaObjects/exceptions/class.ilFFmpegException.php");
200 throw new ilFFmpegException("Format " . $a_target_mime . " is not supported");
201 }
202 $pars = self::$formats[$a_target_mime]["parameters"];
203 $spi = pathinfo($a_file);
204
205 // use source directory if no target directory is passed
206 $target_dir = ($a_target_dir != "")
207 ? $a_target_dir
208 : $spi['dirname'];
209
210 // use source filename if no target filename is passed
211 $target_filename = ($a_target_filename != "")
212 ? $a_target_filename
213 : $spi['filename'] . "." . self::$formats[$a_target_mime]["suffix"];
214
215 $target_file = $target_dir . "/" . $target_filename;
216
217 $cmd = "-y -i " . ilUtil::escapeShellArg($a_file) . " " . $pars . " " . ilUtil::escapeShellArg($target_file);
218
219 $ret = self::exec($cmd . " 2>&1");
220 self::$last_return = $ret;
221
222 if (is_file($target_file)) {
223 return $target_file;
224 } else {
225 include_once("./Services/MediaObjects/exceptions/class.ilFFmpegException.php");
226 throw new ilFFmpegException("It was not possible to convert file " . basename($a_file) . ".");
227 }
228 //ffmpeg -i MOV012.3gp -vcodec libx264 -strict experimental -acodec aac -sameq -ab 64k -ar 44100 MOV012.mp4
229 }
Class for ffmpeg exception handling in ILIAS.
static exec($args)
Execute ffmpeg.
static escapeShellArg($a_arg)
$formats
Definition: date.php:77
$ret
Definition: parser.php:6

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

Referenced by ilObjMediaCastGUI\convertFileObject().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ enabled()

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.

52 {
53 if (defined("PATH_TO_FFMPEG") && PATH_TO_FFMPEG != "") {
54 return true;
55 }
56 return false;
57 }
defined( 'APPLICATION_ENV')||define( 'APPLICATION_ENV'
Definition: bootstrap.php:27

References defined.

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

+ Here is the caller graph for this function:

◆ exec()

static ilFFmpeg::exec (   $args)
static

Execute ffmpeg.

Parameters

return

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

144 {
145 return ilUtil::execQuoted(self::getCmd(), $args);
146 }
static execQuoted($cmd, $args=null)
exec command and fix spaces on windows

References ilUtil\execQuoted().

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

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ extractImage()

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 251 of file class.ilFFmpeg.php.

256 {
257 //echo "-$a_file-$a_target_filename-$a_target_dir-$a_sec-<br>";
258
259 $spi = pathinfo($a_file);
260
261 // use source directory if no target directory is passed
262 $target_dir = ($a_target_dir != "")
263 ? $a_target_dir
264 : $spi['dirname'];
265
266 $target_file = $target_dir . "/" . $a_target_filename;
267
268 $sec = (int) $a_sec;
269 $cmd = "-y -i " . ilUtil::escapeShellArg($a_file) . " -r 1 -f image2 -vframes 1 -ss " . $sec . " " . ilUtil::escapeShellArg($target_file);
270 //echo "-$cmd-"; exit;
271 $ret = self::exec($cmd . " 2>&1");
272 self::$last_return = $ret;
273
274 if (is_file($target_file)) {
275 return $target_file;
276 } else {
277 include_once("./Services/MediaObjects/exceptions/class.ilFFmpegException.php");
278 throw new ilFFmpegException("It was not possible to extract an image from " . basename($a_file) . ".");
279 }
280 }

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

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

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getCmd()

static ilFFmpeg::getCmd ( )
staticprivate

Get ffmpeg command.

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

133 {
134 return PATH_TO_FFMPEG;
135 }

◆ getFileInfo()

ilFFmpeg::getFileInfo ( )

Get file info.

Parameters

return

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

179 {
180 //$info = `ffmpeg -i $path$file 2>&1 /dev/null`;
181 //@fields = split(/\n/, $info);
182 }

◆ getLastReturnValues()

static ilFFmpeg::getLastReturnValues ( )
static

Get last return values.

Parameters

return

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

238 {
239 return self::$last_return;
240 }
static $last_return

References $last_return.

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

+ Here is the caller graph for this function:

◆ getPossibleTargetMimeTypes()

static ilFFmpeg::getPossibleTargetMimeTypes (   $a_source_mime_type)
static

Get possible target formats.

Parameters

return

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

116 {
117 $pt = array();
118 if (in_array($a_source_mime_type, self::getSourceMimeTypes())) {
119 foreach (self::getTargetMimeTypes() as $tm) {
120 if ($tm != $a_source_mime_type) {
121 $pt[$tm] = $tm;
122 }
123 }
124 }
125 return $pt;
126 }

◆ getSourceMimeTypes()

static ilFFmpeg::getSourceMimeTypes ( )
static

Get source mime types.

Parameters

return

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

86 {
87 $ttypes = array();
88 foreach (self::$formats as $k => $f) {
89 if ($f["source"] == true) {
90 $ttypes[] = $k;
91 }
92 }
93 return $ttypes;
94 }

References $formats.

◆ getSupportedCodecsInfo()

static ilFFmpeg::getSupportedCodecsInfo ( )
static

Get all supported codecs.

Returns

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

154 {
155 $codecs = self::exec("-codecs");
156
157 return $codecs;
158 }

References exec().

+ Here is the call graph for this function:

◆ getSupportedFormatsInfo()

static ilFFmpeg::getSupportedFormatsInfo ( )
static

Get all supported formats.

Returns

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

166 {
167 $formats = self::exec("-formats");
168
169 return $formats;
170 }
static $formats
Formats handled by ILIAS.

References $formats, and exec().

Referenced by ilObjMediaObjectGUI\showVideoToolObject().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getTargetMimeTypes()

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 68 of file class.ilFFmpeg.php.

69 {
70 $ttypes = array();
71 foreach (self::$formats as $k => $f) {
72 if ($f["target"] == true) {
73 $ttypes[] = $k;
74 }
75 }
76 return $ttypes;
77 }

References $formats.

◆ supportsImageExtraction()

static ilFFmpeg::supportsImageExtraction (   $a_mime)
static

Check if mime type supports image extraction.

Parameters
string$a_mimemime type

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

102 {
103 if (in_array($a_mime, self::getSourceMimeTypes())) {
104 return true;
105 }
106 return false;
107 }

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

+ Here is the caller graph for this function:

Field Documentation

◆ $formats

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().

◆ $last_return

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: