ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5
ilFFmpeg Class Reference

FFmpeg wrapper. More...

+ Collaboration diagram for ilFFmpeg:

Public Member Functions

 getPossibleTargetMimeTypes ($a_source_mime_type)
 Get possible target formats. More...
 
 exec ($args)
 Execute ffmpeg. More...
 
 getFileInfo ()
 Get file info. More...
 
 getLastReturnValues ()
 Get last return values. 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 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 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 203 of file class.ilFFmpeg.php.

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

Referenced by ilObjMediaCastGUI\convertFileObject().

204  {
205  return; // currently not supported
206 
207  if (self::$formats[$a_target_mime]["target"] != true)
208  {
209  include_once("./Services/MediaObjects/exceptions/class.ilFFmpegException.php");
210  throw new ilFFmpegException("Format ".$a_target_mime." is not supported");
211  }
212  $pars = self::$formats[$a_target_mime]["parameters"];
213  $spi = pathinfo($a_file);
214 
215  // use source directory if no target directory is passed
216  $target_dir = ($a_target_dir != "")
217  ? $a_target_dir
218  : $spi['dirname'];
219 
220  // use source filename if no target filename is passed
221  $target_filename = ($a_target_filename != "")
222  ? $a_target_filename
223  : $spi['filename'].".".self::$formats[$a_target_mime]["suffix"];
224 
225  $target_file = $target_dir."/".$target_filename;
226 
227  $cmd = "-y -i ".ilUtil::escapeShellArg($a_file)." ".$pars." ".ilUtil::escapeShellArg($target_file);
228 
229  $ret = self::exec($cmd." 2>&1");
230  self::$last_return = $ret;
231 
232  if (is_file($target_file))
233  {
234  return $target_file;
235  }
236  else
237  {
238  include_once("./Services/MediaObjects/exceptions/class.ilFFmpegException.php");
239  throw new ilFFmpegException("It was not possible to convert file ".basename($a_file).".");
240  }
241  //ffmpeg -i MOV012.3gp -vcodec libx264 -strict experimental -acodec aac -sameq -ab 64k -ar 44100 MOV012.mp4
242  }
Class for ffmpeg exception handling in ILIAS.
$cmd
Definition: sahs_server.php:35
static escapeShellArg($a_arg)
+ 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

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

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

52  {
53  if (defined("PATH_TO_FFMPEG") && PATH_TO_FFMPEG != "")
54  {
55  return true;
56  }
57  return false;
58  }
+ Here is the caller graph for this function:

◆ exec()

ilFFmpeg::exec (   $args)

Execute ffmpeg.

Parameters

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

References ilUtil\execQuoted().

153  {
154  return ilUtil::execQuoted(self::getCmd(), $args);
155  }
static execQuoted($cmd, $args=NULL)
exec command and fix spaces on windows
+ Here is the call 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 264 of file class.ilFFmpeg.php.

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

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

266  {
267 //echo "-$a_file-$a_target_filename-$a_target_dir-$a_sec-<br>";
268 
269  $spi = pathinfo($a_file);
270 
271  // use source directory if no target directory is passed
272  $target_dir = ($a_target_dir != "")
273  ? $a_target_dir
274  : $spi['dirname'];
275 
276  $target_file = $target_dir."/".$a_target_filename;
277 
278  $sec = (int) $a_sec;
279  $cmd = "-y -i ".ilUtil::escapeShellArg($a_file)." -r 1 -f image2 -vframes 1 -ss ".$sec." ".ilUtil::escapeShellArg($target_file);
280 //echo "-$cmd-"; exit;
281  $ret = self::exec($cmd." 2>&1");
282  self::$last_return = $ret;
283 
284  if (is_file($target_file))
285  {
286  return $target_file;
287  }
288  else
289  {
290  include_once("./Services/MediaObjects/exceptions/class.ilFFmpegException.php");
291  throw new ilFFmpegException("It was not possible to extract an image from ".basename($a_file).".");
292  }
293  }
Class for ffmpeg exception handling in ILIAS.
$cmd
Definition: sahs_server.php:35
static escapeShellArg($a_arg)
+ 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 141 of file class.ilFFmpeg.php.

142  {
143  return PATH_TO_FFMPEG;
144  }

◆ getFileInfo()

ilFFmpeg::getFileInfo ( )

Get file info.

Parameters

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

188  {
189  //$info = `ffmpeg -i $path$file 2>&1 /dev/null`;
190  //@fields = split(/\n/, $info);
191  }

◆ getLastReturnValues()

ilFFmpeg::getLastReturnValues ( )

Get last return values.

Parameters

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

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

251  {
252  return self::$last_return;
253  }
+ Here is the caller graph for this function:

◆ getPossibleTargetMimeTypes()

ilFFmpeg::getPossibleTargetMimeTypes (   $a_source_mime_type)

Get possible target formats.

Parameters

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

122  {
123  $pt = array();
124  if (in_array($a_source_mime_type, self::getSourceMimeTypes()))
125  {
126  foreach (self::getTargetMimeTypes() as $tm)
127  {
128  if ($tm != $a_source_mime_type)
129  {
130  $pt[$tm] = $tm;
131  }
132  }
133  }
134  return $pt;
135  }

◆ getSourceMimeTypes()

static ilFFmpeg::getSourceMimeTypes ( )
static

Get source mime types.

Parameters

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

89  {
90  $ttypes = array();
91  foreach (self::$formats as $k => $f)
92  {
93  if ($f["source"] == true)
94  {
95  $ttypes[] = $k;
96  }
97  }
98  return $ttypes;
99  }

◆ getSupportedCodecsInfo()

static ilFFmpeg::getSupportedCodecsInfo ( )
static

Get all supported codecs.

Returns

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

163  {
164  $codecs = self::exec("-codecs");
165 
166  return $codecs;
167  }

◆ getSupportedFormatsInfo()

static ilFFmpeg::getSupportedFormatsInfo ( )
static

Get all supported formats.

Returns

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

References $formats.

Referenced by ilObjMediaObjectGUI\showVideoToolObject().

175  {
176  $formats = self::exec("-formats");
177 
178  return $formats;
179  }
static $formats
Formats handled by ILIAS.
+ 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

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

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

◆ supportsImageExtraction()

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

107  {
108  if (in_array($a_mime, self::getSourceMimeTypes()))
109  {
110  return true;
111  }
112  return false;
113  }
+ 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.


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