ILIAS  trunk Revision v11.0_alpha-1811-gd2d5443e411
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
ilFFmpeg Class Reference

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V. More...

+ Collaboration diagram for ilFFmpeg:

Static Public Member Functions

static enabled ()
 Checks, whether FFmpeg support is enabled (path is set in the setup) More...
 
static getSourceMimeTypes ()
 
static supportsImageExtraction (string $a_mime)
 Check if mime type supports image extraction. More...
 
static getLastReturnValues ()
 Get last return values. More...
 
static extractImage (string $a_file, string $a_target_filename, string $a_target_dir="", int $a_sec=1)
 Extract image from video file. More...
 
static extractPNGFromVideoInZip (string $zip, string $path, int $sec=1)
 

Static Public Attributes

static array $last_return = array()
 
static array $formats
 

Static Protected Member Functions

static exec (string $args)
 
static escapeShellArg (string $a_arg)
 

Static Private Member Functions

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

Detailed Description

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V.

ILIAS is licensed with the GPL-3.0, see https://www.gnu.org/licenses/gpl-3.0.en.html You should have received a copy of said license along with the source code, too.

If this is not the case or you just want to try ILIAS, you'll find us at: https://www.ilias.de https://github.com/ILIAS-eLearning FFmpeg wrapper

Author
Alexander Killing killi.nosp@m.ng@l.nosp@m.eifos.nosp@m..de

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

Member Function Documentation

◆ enabled()

static ilFFmpeg::enabled ( )
static

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

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

Referenced by ILIAS\ResourceStorage\Flavour\Machine\DefaultMachines\Extract\Video\GUIService\addPreviewExtractionToToolbar(), and ilDclMobRecordFieldModel\parseValue().

61  : bool
62  {
63  if (defined("PATH_TO_FFMPEG") && PATH_TO_FFMPEG != "") {
64  return true;
65  }
66  return false;
67  }
+ Here is the caller graph for this function:

◆ escapeShellArg()

static ilFFmpeg::escapeShellArg ( string  $a_arg)
staticprotected

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

121  : string
122  {
123  setlocale(
124  LC_CTYPE,
125  "UTF8",
126  "en_US.UTF-8"
127  ); // fix for PHP escapeshellcmd bug. See: http://bugs.php.net/bug.php?id=45132
128  // see also ilias bug 5630
129  return escapeshellarg($a_arg);
130  }

◆ exec()

static ilFFmpeg::exec ( string  $args)
staticprotected

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

104  : array
105  {
106  $win = (stripos(php_uname(), "win") === 0);
107  $cmd = self::getCmd();
108  if ($win && str_contains($cmd, " ") && $cmd[0] !== '"') {
109  $cmd = '"' . $cmd . '"';
110  if ($args) {
111  $cmd .= " " . $args;
112  }
113  } elseif ($args) {
114  $cmd .= " " . $args;
115  }
116  $arr = [];
117  exec($cmd, $arr);
118  return $arr;
119  }
static exec(string $args)

◆ extractImage()

static ilFFmpeg::extractImage ( string  $a_file,
string  $a_target_filename,
string  $a_target_dir = "",
int  $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!)
int$a_sec
Returns
string new file (full path)
Exceptions
ilFFmpegException

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

References ilShellUtil\escapeShellArg().

Referenced by ilDclMobRecordFieldModel\parseValue().

156  : string {
157  $spi = pathinfo($a_file);
158 
159  // use source directory if no target directory is passed
160  $target_dir = ($a_target_dir != "")
161  ? $a_target_dir
162  : $spi['dirname'];
163 
164  $target_file = $target_dir . "/" . $a_target_filename;
165 
166  $sec = $a_sec;
167  $cmd = "-y -i " . ilShellUtil::escapeShellArg(
168  $a_file
169  ) . " -r 1 -f image2 -vframes 1 -ss " . $sec . " " . ilShellUtil::escapeShellArg($target_file);
170  $ret = self::exec($cmd . " 2>&1");
171  self::$last_return = $ret;
172 
173  if (is_file($target_file)) {
174  return $target_file;
175  } else {
176  throw new ilFFmpegException("It was not possible to extract an image from " . basename($a_file) . ".");
177  }
178  }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static escapeShellArg(string $a_arg)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ extractPNGFromVideoInZip()

static ilFFmpeg::extractPNGFromVideoInZip ( string  $zip,
string  $path,
int  $sec = 1 
)
static

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

References ilFileUtils\ilTempnam().

Referenced by ILIAS\MediaObjects\MediaObjectManager\generatePreview().

184  : string {
185  $zip = self::escapeShellArg($zip);
186  $path = self::escapeShellArg("/" . $path);
187  $tfile = ilFileUtils::ilTempnam();
188  $tmp_file = self::escapeShellArg($tfile);
189 
190  $command1 = "unzip -p $zip $path > $tmp_file";
191  shell_exec($command1);
192  $command2 = "ffmpeg -i $tmp_file -f image2 -vframes 1 -ss $sec -vcodec png pipe:1";
193 
194  $ret = (string) shell_exec($command2);
195  unlink($tfile);
196  return $ret;
197  }
$path
Definition: ltiservices.php:29
static ilTempnam(?string $a_temp_path=null)
Returns a unique and non existing Path for e temporary file or directory.
+ 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 99 of file class.ilFFmpeg.php.

99  : string
100  {
101  return PATH_TO_FFMPEG;
102  }

◆ getLastReturnValues()

static ilFFmpeg::getLastReturnValues ( )
static

Get last return values.

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

Referenced by ILIAS\ResourceStorage\Flavour\Machine\DefaultMachines\Extract\Video\GUIService\handleExtractionRequest().

136  : ?array
137  {
138  return self::$last_return;
139  }
+ Here is the caller graph for this function:

◆ getSourceMimeTypes()

static ilFFmpeg::getSourceMimeTypes ( )
static
Returns
string[]

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

References Vendor\Package\$f.

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

◆ supportsImageExtraction()

static ilFFmpeg::supportsImageExtraction ( string  $a_mime)
static

Check if mime type supports image extraction.

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

Referenced by ILIAS\ResourceStorage\Flavour\Machine\DefaultMachines\Extract\Video\GUIService\addPreviewExtractionToToolbar(), ILIAS\ResourceStorage\Flavour\Machine\DefaultMachines\Extract\Video\GUIService\checkPreviewPossible(), and ilDclMobRecordFieldModel\parseValue().

88  : bool {
89  if (in_array($a_mime, self::getSourceMimeTypes(), true)) {
90  return true;
91  }
92  return false;
93  }
+ Here is the caller graph for this function:

Field Documentation

◆ $formats

array 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"
)
)

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

◆ $last_return

array ilFFmpeg::$last_return = array()
static

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


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