/sites/all/modules/video/libraries/phpvideotoolkit/phpvideotoolkit.php5.php
PHP | 3585 lines | 1847 code | 226 blank | 1512 comment | 363 complexity | 4eb049d3aced0707eddc3f2d885b42de MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1, AGPL-1.0
Large files files are truncated, but you can click here to view the full file
- <?php
- /**
- * @file
- * Libary to access FFmpeg
- */
- /**
- * @author Oliver Lillie (aka buggedcom) <publicmail@buggedcom.co.uk>
- *
- * @license GPL 2.0
- *
- * @package FFMPEG (was called PHPVideoToolkit)
- * @version 0.1.9
- *
- * @abstract This class can be used in conjunction with several server binary libraries to manipulate video and audio
- * through PHP. It is not intended to solve any particular problems, however you may find it useful. This php class
- * is in no way associated with the actual FFmpeg releases. Any mistakes contained in this php class are mine and mine
- * alone.
- *
- * Please Note: There are several prerequisites that are required before this class can be used as an aid to manipulate
- * video and audio. You must at the very least have FFMPEG compiled on your server. If you wish to use this class for FLV
- * manipulation you must compile FFMPEG with LAME and Ruby's FLVTOOL2. I cannot answer questions regarding the install of
- * the server binaries needed by this class. I had too learn the hard way and it isn't easy, however it is a good learning
- * experience. For those of you who do need help read the install.txt file supplied along side this class. It wasn't written
- * by me however I found it useful when installing ffmpeg for the first time. The original source for the install.txt file
- * is located http://www.luar.com.hk/blog/?p=669 and the author is Lunar.
- *
- * @uses ffmpeg http://ffmpeg.org
- */
- if (!defined('DS')) {
- define('DS', DIRECTORY_SEPARATOR);
- }
- /**
- * Set the flvtool2 binary path
- */
- if (!defined('PHPVIDEOTOOLKIT_FLVTOOLS_BINARY')) {
- define('PHPVIDEOTOOLKIT_FLVTOOLS_BINARY', '/usr/bin/flvtool2');
- }
- /**
- * Set the watermark vhook path
- */
- if (!defined('PHPVIDEOTOOLKIT_FFMPEG_WATERMARK_VHOOK')) {
- define('PHPVIDEOTOOLKIT_FFMPEG_WATERMARK_VHOOK', '/usr/local/lib/vhook/watermark.so');
- }
- /**
- * Set the memcoder path
- */
- if (!defined('PHPVIDEOTOOLKIT_MENCODER_BINARY')) {
- define('PHPVIDEOTOOLKIT_MENCODER_BINARY', '/usr/local/bin/mencoder');
- }
- class PHPVideoToolkit {
- public $version = '0.1.9';
- /**
- * Error strings
- */
- protected $_messages = array(
- 'generic_temp_404' => 'The temporary directory does not exist.',
- 'generic_temp_writable' => 'The temporary directory is not write-able by the web server.',
- 'inputFileHasVideo_no_input' => 'Input file does not exist so no information can be retrieved.',
- 'inputFileHasAudio_no_input' => 'Input file does not exist so no information can be retrieved.',
- 'getFileInfo_no_input' => 'Input file does not exist so no information can be retrieved.',
- 'streamFLV_no_input' => 'Input file has not been set so the FLV cannot be streamed.',
- 'streamFLV_passed_eof' => 'You have tried to stream to a point in the file that does not exit.',
- 'setInputFile_file_existence' => 'Input file "#file" does not exist',
- 'extractAudio_valid_format' => 'Value "#format" set from $toolkit->extractAudio, is not a valid audio format. Valid values ffmpeg self::FORMAT_AAC, PHPVideoToolkit::FORMAT_AIFF, PHPVideoToolkit::FORMAT_MP2, PHPVideoToolkit::FORMAT_MP3, PHPVideoToolkit::FORMAT_MP4, PHPVideoToolkit::FORMAT_MPEG4, PHPVideoToolkit::FORMAT_M4A or PHPVideoToolkit::FORMAT_WAV. If you wish to specifically try to set another format you should use the advanced function $toolkit->addCommand. Set $command to "-f" and $argument to your required value.',
- 'extractFrame_video_frame_rate_404' => 'You have attempted to extract a thumbnail from a video while automagically guessing the framerate of the video, but the framerate could not be accessed. You can remove this error by manually setting the frame rate of the video.',
- 'extractFrame_video_info_404' => 'You have attempted to extract a thumbnail from a video and check to see if the thumbnail exists, however it was not possible to access the video information. Please check your temporary directory permissions for read/write access by the webserver.',
- 'extractFrame_video_frame_count' => 'You have attempted to extract a thumbnail from a video but the thumbnail you are trying to extract does not exist in the video.',
- 'extractFrames_video_begin_frame_count' => 'You have attempted to extract thumbnails from a video but the thumbnail you are trying to start the extraction from does not exist in the video.',
- 'extractFrames_video_end_frame_count' => 'You have attempted to extract thumbnails from a video but the thumbnail you are trying to end the extraction at does not exist in the video.',
- 'setFormat_valid_format' => 'Value "#format" set from $toolkit->setFormat, is not a valid format. Valid values are PHPVideoToolkit::FORMAT_3GP2, PHPVideoToolkit::FORMAT_3GP, PHPVideoToolkit::FORMAT_AAC, PHPVideoToolkit::FORMAT_AIFF, PHPVideoToolkit::FORMAT_AMR, PHPVideoToolkit::FORMAT_ASF, PHPVideoToolkit::FORMAT_AVI, PHPVideoToolkit::FORMAT_FLV, PHPVideoToolkit::FORMAT_GIF, PHPVideoToolkit::FORMAT_MJ2, PHPVideoToolkit::FORMAT_MP2, PHPVideoToolkit::FORMAT_MP3, PHPVideoToolkit::FORMAT_MP4, PHPVideoToolkit::FORMAT_MPEG4, PHPVideoToolkit::FORMAT_M4A, PHPVideoToolkit::FORMAT_MPEG, PHPVideoToolkit::FORMAT_MPEG1, PHPVideoToolkit::FORMAT_MPEG2, PHPVideoToolkit::FORMAT_MPEGVIDEO, PHPVideoToolkit::FORMAT_PSP, PHPVideoToolkit::FORMAT_RM, PHPVideoToolkit::FORMAT_SWF, PHPVideoToolkit::FORMAT_VOB, PHPVideoToolkit::FORMAT_WAV, PHPVideoToolkit::FORMAT_JPG. If you wish to specifically try to set another format you should use the advanced function $toolkit->addCommand. Set $command to "-f" and $argument to your required value.',
- 'setAudioChannels_valid_channels' => 'Value "#channels" set from $toolkit->setAudioChannels, is not a valid integer. Valid values are 1, or 2. If you wish to specifically try to set another channels value you should use the advanced function $toolkit->addCommand. Set $command to "-ac" and $argument to your required value.',
- 'setAudioSampleFrequency_valid_frequency' => 'Value "#frequency" set from $toolkit->setAudioSampleFrequency, is not a valid integer. Valid values are 11025, 22050, 44100. If you wish to specifically try to set another frequency you should use the advanced function $toolkit->addCommand. Set $command to "-ar" and $argument to your required value.',
- 'setAudioFormat_valid_format' => 'Value "#format" set from $toolkit->setAudioCodec, is not a valid format. Valid values are PHPVideoToolkit::FORMAT_AAC, PHPVideoToolkit::FORMAT_AIFF, PHPVideoToolkit::FORMAT_AMR, PHPVideoToolkit::FORMAT_ASF, PHPVideoToolkit::FORMAT_MP2, PHPVideoToolkit::FORMAT_MP3, PHPVideoToolkit::FORMAT_MP4, PHPVideoToolkit::FORMAT_MPEG2, PHPVideoToolkit::FORMAT_RM, PHPVideoToolkit::FORMAT_WAV. If you wish to specifically try to set another format you should use the advanced function $toolkit->addCommand. Set $command to "-acodec" and $argument to your required value.',
- 'setAudioFormat_cannnot_encode' => 'Value "#codec" set from $toolkit->setAudioCodec, can not be used to encode the output as the version of FFmpeg that you are using does not have the capability to encode audio with this codec.',
- 'setVideoFormat_valid_format' => 'Value "#format" set from $toolkit->setVideoCodec, is not a valid format. Valid values are PHPVideoToolkit::FORMAT_3GP2, PHPVideoToolkit::FORMAT_3GP, PHPVideoToolkit::FORMAT_AVI, PHPVideoToolkit::FORMAT_FLV, PHPVideoToolkit::FORMAT_GIF, PHPVideoToolkit::FORMAT_MJ2, PHPVideoToolkit::FORMAT_MP4, PHPVideoToolkit::FORMAT_MPEG4, PHPVideoToolkit::FORMAT_M4A, PHPVideoToolkit::FORMAT_MPEG, PHPVideoToolkit::FORMAT_MPEG1, PHPVideoToolkit::FORMAT_MPEG2, PHPVideoToolkit::FORMAT_MPEGVIDEO. If you wish to specifically try to set another format you should use the advanced function $toolkit->addCommand. Set $command to "-vcodec" and $argument to your required value.',
- 'setVideoFormat_cannnot_encode' => 'Value "#codec" set from $toolkit->setVideoCodec, can not be used to encode the output as the version of FFmpeg that you are using does not have the capability to encode video with this codec.',
- 'setAudioBitRate_valid_bitrate' => 'Value "#bitrate" set from $toolkit->setAudioBitRate, is not a valid integer. Valid values are 16, 32, 64, 128. If you wish to specifically try to set another bitrate you should use the advanced function $toolkit->addCommand. Set $command to "-ab" and $argument to your required value.',
- 'prepareImagesForConversionToVideo_one_img' => 'When compiling a movie from a series of images, you must include at least one image.',
- 'prepareImagesForConversionToVideo_img_404' => '"#img" does not exist.',
- 'prepareImagesForConversionToVideo_img_copy' => '"#img" can not be copied to "#tmpfile"',
- 'prepareImagesForConversionToVideo_img_type' => 'The images can not be prepared for conversion to video. Please make sure all images are of the same type, ie gif, png, jpeg and then try again.',
- 'setVideoOutputDimensions_valid_format' => 'Value "#format" set from $toolkit->setVideoOutputDimensions, is not a valid preset dimension. Valid values are PHPVideoToolkit::SIZE_SQCIF, PHPVideoToolkit::SIZE_SAS, PHPVideoToolkit::SIZE_QCIF, PHPVideoToolkit::SIZE_CIF, PHPVideoToolkit::SIZE_4CIF, PHPVideoToolkit::SIZE_QQVGA, PHPVideoToolkit::SIZE_QVGA, PHPVideoToolkit::SIZE_VGA, PHPVideoToolkit::SIZE_SVGA, PHPVideoToolkit::SIZE_XGA, PHPVideoToolkit::SIZE_UXGA, PHPVideoToolkit::SIZE_QXGA, PHPVideoToolkit::SIZE_SXGA, PHPVideoToolkit::SIZE_QSXGA, PHPVideoToolkit::SIZE_HSXGA, PHPVideoToolkit::SIZE_WVGA, PHPVideoToolkit::SIZE_WXGA, PHPVideoToolkit::SIZE_WSXGA, PHPVideoToolkit::SIZE_WUXGA, PHPVideoToolkit::SIZE_WOXGA, PHPVideoToolkit::SIZE_WQSXGA, PHPVideoToolkit::SIZE_WQUXGA, PHPVideoToolkit::SIZE_WHSXGA, PHPVideoToolkit::SIZE_WHUXGA, PHPVideoToolkit::SIZE_CGA, PHPVideoToolkit::SIZE_EGA, PHPVideoToolkit::SIZE_HD480, PHPVideoToolkit::SIZE_HD720, PHPVideoToolkit::SIZE_HD1080. You can also manually set the width and height.',
- 'setVideoOutputDimensions_sas_dim' => 'It was not possible to determine the input video dimensions so it was not possible to continue. If you wish to override this error please change the call to setVideoOutputDimensions and add a TRUE argument to the arguments list... setVideoOutputDimensions(PHPVideoToolkit::SIZE_SAS, TRUE);',
- 'setVideoOutputDimensions_valid_integer' => 'You tried to set the video output dimensions to an odd number. FFmpeg requires that the video output dimensions are of event value and divisible by 2. ie 2, 4, 6,... etc',
- 'setVideoAspectRatio_valid_ratio' => 'Value "#ratio" set from $toolkit->setVideoOutputDimensions, is not a valid preset dimension. Valid values are PHPVideoToolkit::RATIO_STANDARD, PHPVideoToolkit::RATIO_WIDE, PHPVideoToolkit::RATIO_CINEMATIC. If you wish to specifically try to set another video aspect ratio you should use the advanced function $toolkit->addCommand. Set $command to "-aspect" and $argument to your required value.',
- 'addWatermark_img_404' => 'Watermark file "#watermark" does not exist.',
- 'addWatermark_vhook_disabled' => 'Vhooking is not enabled in your FFmpeg binary. In order to allow video watermarking you must have FFmpeg compiled with --enable-vhook set. You can however watermark any extracted images using GD. To enable frame watermarking, call $toolkit->addGDWatermark($file) before you execute the extraction.',
- 'addVideo_file_404' => 'File "#file" does not exist.',
- 'setOutput_output_dir_404' => 'Output directory "#dir" does not exist!',
- 'setOutput_output_dir_writable' => 'Output directory "#dir" is not writable!',
- 'setOutput_%_missing' => 'The output of this command will be images yet you have not included the "%index" or "%timecode" in the $output_name.',
- 'setOutput_%d_depreciated' => 'The use of %d in the output file name is now depreciated. Please use %index. Number padding is still supported. You may also use %timecode instead to add a timecode to the filename.',
- 'execute_input_404' => 'Execute error. Input file missing.',
- 'execute_output_not_set' => 'Execute error. Output not set.',
- 'execute_temp_unwritable' => 'Execute error. The tmp directory supplied is not writable.',
- 'execute_overwrite_process' => 'Execute error. A file exists in the temp directory and is of the same name as this process file. It will conflict with this conversion. Conversion stopped.',
- 'execute_overwrite_fail' => 'Execute error. Output file exists. Process halted. If you wish to automatically overwrite files set the third argument in "PHPVideoToolkit::setOutput();" to "PHPVideoToolkit::OVERWRITE_EXISTING".',
- 'execute_ffmpeg_return_error' => 'Execute error. It was not possible to encode "#input" as FFmpeg returned an error. The error #stream of the input file. FFmpeg reports the error to be "#message".',
- 'execute_ffmpeg_return_error_multipass' => 'Execute error. It was not possible to encode "#input" as FFmpeg returned an error. Note, however the error was encountered on the second pass of the encoding process and the first pass appear to go fine. The error #stream of the input file. FFmpeg reports the error to be "#message".',
- 'execute_partial_error' => 'Execute error. Output for file "#input" encountered a partial error. Files were generated, however one or more of them were empty.',
- 'execute_image_error' => 'Execute error. Output for file "#input" was not found. No images were generated.',
- 'execute_output_404' => 'Execute error. Output for file "#input" was not found. Please check server write permissions and/or available codecs compiled with FFmpeg. You can check the encode decode availability by inspecting the output array from PHPVideoToolkit::getFFmpegInfo().',
- 'execute_output_empty' => 'Execute error. Output for file "#input" was found, but the file contained no data. Please check the available codecs compiled with FFmpeg can support this type of conversion. You can check the encode decode availability by inspecting the output array from PHPVideoToolkit::getFFmpegInfo().',
- 'execute_image_file_exists' => 'Execute error. There is a file name conflict. The file "#file" already exists in the filesystem. If you wish to automatically overwrite files set the third argument in "PHPVideoToolkit::setOutput();" to "PHPVideoToolkit::OVERWRITE_EXISTING".',
- 'execute_result_ok_but_unwritable' => 'Process Partially Completed. The process successfully completed however it was not possible to output to "#output". The output was left in the temp directory "#process" for a manual file movement.',
- 'execute_result_ok' => 'Process Completed. The process successfully completed. Output was generated to "#output".',
- 'ffmpeg_log_ffmpeg_output' => 'OUTPUT',
- 'ffmpeg_log_ffmpeg_result' => 'RESULT',
- 'ffmpeg_log_ffmpeg_command' => 'COMMAND',
- 'ffmpeg_log_ffmpeg_join_gunk' => 'FFMPEG JOIN OUTPUT',
- 'ffmpeg_log_ffmpeg_gunk' => 'FFMPEG OUTPUT',
- 'ffmpeg_log_separator' => '-------------------------------'
- );
- /**
- * Process Results from PHPVideoToolkit::execute
- */
- // any return value with this means everything is ok
- const RESULT_OK = TRUE;
- // any return value with this means the file has been processed/converted ok however it was
- // not able to be written to the output address. If this occurs you will need to move the
- // processed file manually from the temp location
- const RESULT_OK_BUT_UNWRITABLE = -1;
- /**
- * Codec support constants
- */
- const ENCODE = 'encode';
- const DECODE = 'decode';
- /**
- * Overwrite constants used in setOutput
- */
- const OVERWRITE_FAIL = 'fail';
- const OVERWRITE_PRESERVE = 'preserve';
- const OVERWRITE_EXISTING = 'existing';
- const OVERWRITE_UNIQUE = 'unique';
- /**
- * Formats supported
- * 3g2 3gp2 format
- * 3gp 3gp format
- * aac ADTS AAC
- * aiff Audio IFF
- * amr 3gpp amr file format
- * asf asf format
- * avi avi format
- * flv flv format
- * gif GIF Animation
- * mov mov format
- * mov,mp4,m4a,3gp,3g2,mj2 QuickTime/MPEG4/Motion JPEG 2000 format
- * mp2 MPEG audio layer 2
- * mp3 MPEG audio layer 3
- * mp4 mp4 format
- * mpeg MPEG1 System format
- * mpeg1video MPEG video
- * mpeg2video MPEG2 video
- * mpegvideo MPEG video
- * psp psp mp4 format
- * rm rm format
- * swf Flash format
- * vob MPEG2 PS format (VOB)
- * wav wav format
- * jpeg mjpeg format
- * yuv4mpegpipe yuv4mpegpipe format
- */
- const FORMAT_3GP2 = '3g2';
- const FORMAT_3GP = '3gp';
- const FORMAT_AAC = 'aac';
- const FORMAT_AIFF = 'aiff';
- const FORMAT_AMR = 'amr';
- const FORMAT_ASF = 'asf';
- const FORMAT_AVI = 'avi';
- const FORMAT_FLV = 'flv';
- const FORMAT_GIF = 'gif';
- const FORMAT_MJ2 = 'mj2';
- const FORMAT_MP2 = 'mp2';
- const FORMAT_MP3 = 'mp3';
- const FORMAT_MP4 = 'mp4';
- const FORMAT_MPEG4 = 'mpeg4';
- const FORMAT_M4A = 'm4a';
- const FORMAT_MPEG = 'mpeg';
- const FORMAT_MPEG1 = 'mpeg1video';
- const FORMAT_MPEG2 = 'mpeg2video';
- const FORMAT_MPEGVIDEO = 'mpegvideo';
- const FORMAT_PSP = 'psp';
- const FORMAT_RM = 'rm';
- const FORMAT_SWF = 'swf';
- const FORMAT_VOB = 'vob';
- const FORMAT_WAV = 'wav';
- const FORMAT_JPG = 'mjpeg';
- const FORMAT_Y4MP = 'yuv4mpegpipe';
- /**
- * Size Presets
- */
- const SIZE_SAS = 'SameAsSource';
- const SIZE_SQCIF = '128x96';
- const SIZE_QCIF = '176x144';
- const SIZE_CIF = '352x288';
- const SIZE_4CIF = '704x576';
- const SIZE_QQVGA = '160x120';
- const SIZE_QVGA = '320x240';
- const SIZE_VGA = '640x480';
- const SIZE_SVGA = '800x600';
- const SIZE_XGA = '1024x768';
- const SIZE_UXGA = '1600x1200';
- const SIZE_QXGA = '2048x1536';
- const SIZE_SXGA = '1280x1024';
- const SIZE_QSXGA = '2560x2048';
- const SIZE_HSXGA = '5120x4096';
- const SIZE_WVGA = '852x480';
- const SIZE_WXGA = '1366x768';
- const SIZE_WSXGA = '1600x1024';
- const SIZE_WUXGA = '1920x1200';
- const SIZE_WOXGA = '2560x1600';
- const SIZE_WQSXGA = '3200x2048';
- const SIZE_WQUXGA = '3840x2400';
- const SIZE_WHSXGA = '6400x4096';
- const SIZE_WHUXGA = '7680x4800';
- const SIZE_CGA = '320x200';
- const SIZE_EGA = '640x350';
- const SIZE_HD480 = '852x480';
- const SIZE_HD720 = '1280x720';
- const SIZE_HD1080 = '1920x1080';
- /**
- * Ratio Presets
- */
- const RATIO_STANDARD = '4:3';
- const RATIO_WIDE = '16:9';
- const RATIO_CINEMATIC = '1.85';
- /**
- * Audio Channel Presets
- */
- const AUDIO_STEREO = 2;
- const AUDIO_MONO = 1;
- /**
- * A public var that is to the information available about
- * the current ffmpeg compiled binary.
- * @var mixed
- * @access public
- */
- public static $ffmpeg_info = FALSE;
- /**
- * A public var that determines if the ffmpeg binary has been found. The default value
- * is NULL unless getFFmpegInfo is called whereby depending on the results it is set to
- * TRUE or FALSE
- * @var mixed
- * @access public
- */
- public static $ffmpeg_found = NULL;
- /**
- * A protected var that contains the info of any file that is accessed by PHPVideoToolkit::getFileInfo();
- * @var array
- * @access protected
- */
- protected static $_file_info = array();
- /**
- * Determines what happens when an error occurs
- * @var boolean If TRUE then the script will die, if not FALSE is return by the error
- * @access public
- */
- public $on_error_die = FALSE;
- /**
- * Holds the log file name
- * @var string
- * @access protected
- */
- protected $_log_file = NULL;
- /**
- * Determines if when outputting image frames if the outputted files should have the %d number
- * replaced with the frames timecode.
- * @var boolean If TRUE then the files will be renamed.
- * @access public
- */
- public $image_output_timecode = TRUE;
- /**
- * Holds the timecode separator for when using $image_output_timecode = TRUE
- * Not all systems allow ':' in filenames.
- * @var string
- * @access public
- */
- public $timecode_seperator_output = '-';
- /**
- * Holds the starting time code when outputting image frames.
- * @var string The timecode hh(n):mm:ss:ff
- * @access protected
- */
- protected $_image_output_timecode_start = '00:00:00.00';
- /**
- * The format in which the image %timecode placeholder string is outputted.
- * - %hh (hours) representative of hours
- * - %mm (minutes) representative of minutes
- * - %ss (seconds) representative of seconds
- * - %fn (frame number) representative of frames (of the current second, not total frames)
- * - %ms (milliseconds) representative of milliseconds (of the current second, not total milliseconds) (rounded to 3 decimal places)
- * - %ft (frames total) representative of total frames (ie frame number)
- * - %st (seconds total) representative of total seconds (rounded).
- * - %sf (seconds floored) representative of total seconds (floored).
- * - %mt (milliseconds total) representative of total milliseconds. (rounded to 3 decimal places)
- * NOTE; there are special characters that will be replace by PHPVideoToolkit::$timecode_seperator_output, these characters are
- * - :
- * - .
- * @var string
- * @access public
- */
- protected $image_output_timecode_format = '%hh-%mm-%ss-%fn';
- /**
- * Holds the fps of image extracts
- * @var integer
- * @access protected
- */
- protected $_image_output_timecode_fps = 1;
- /**
- * Holds the current execute commands that will need to be combined
- * @var array
- * @access protected
- */
- protected $_commands = array();
- /**
- * Holds the commands executed
- * @var array
- * @access protected
- */
- protected $_processed = array();
- /**
- * Holds the file references to those that have been processed
- * @var array
- * @access protected
- */
- protected $_files = array();
- /**
- * Holds the errors encountered
- * @access protected
- * @var array
- */
- protected $_errors = array();
- /**
- * Holds the input file / input file sequence
- * @access protected
- * @var string
- */
- protected $_input_file = NULL;
- /**
- * Holds the output file / output file sequence
- * @access protected
- * @var string
- */
- protected $_output_address = NULL;
- /**
- * Holds the process file / process file sequence
- * @access protected
- * @var string
- */
- protected $_process_address = NULL;
- /**
- * Temporary filename prefix
- * @access protected
- * @var string
- */
- protected $_tmp_file_prefix = 'tmp_';
- /**
- * Holds the temporary directory name
- * @access protected
- * @var string
- */
- protected $_tmp_directory = NULL;
- /**
- * Holds the directory paths that need to be removed by the ___destruct function
- * @access protected
- * @var array
- */
- protected $_unlink_dirs = array();
- /**
- * Holds the file paths that need to be deleted by the ___destruct function
- * @access protected
- * @var array
- */
- protected $_unlink_files = array();
- /**
- * Holds the timer start micro-float.
- * @access protected
- * @var integer
- */
- protected $_timer_start = 0;
- /**
- * Holds the times taken to process each file.
- * @access protected
- * @var array
- */
- protected $_timers = array();
- /**
- * Holds the times taken to process each file.
- * @access protected
- * @var constant
- */
- protected $_overwrite_mode = NULL;
- /**
- * Holds a integer value that flags if the image extraction is just a single frame.
- * @access protected
- * @var integer
- */
- protected $_single_frame_extraction = NULL;
- /**
- * Holds the watermark file that is used to watermark any outputted images via GD.
- * @access protected
- * @var string
- */
- protected $_watermark_url = NULL;
- /**
- * Holds the watermark options used to watermark any outputted images via GD.
- * @access protected
- * @var array
- */
- protected $_watermark_options = NULL;
- /**
- * Holds the number of files processed per run.
- * @access protected
- * @var integer
- */
- protected $_process_file_count = 0;
- /**
- * Holds the times taken to process each file.
- * @access protected
- * @var array
- */
- protected $_post_processes = array();
- /**
- * Stores command output
- * @var array
- */
- protected $_command_output = array();
- // Stores the FFMPEG Binary Path
- protected $_ffmpeg_binary;
- /**
- * Constructs the class and sets the temporary directory.
- *
- * @access protected
- * @param string $tmp_directory A full absolute path to you temporary directory
- */
- function __construct($ffmpeg_binary = '/usr/bin/ffmpeg', $tmp_dir='/tmp/') {
- // print_r(array(debug_backtrace(), $tmp_dir));
- $this->_ffmpeg_binary = $ffmpeg_binary;
- $this->_tmp_directory = $tmp_dir;
- }
- public static function microtimeFloat() {
- list($usec, $sec) = explode(" ", microtime());
- return ((float) $usec + (float) $sec);
- }
- /**
- * Resets the class
- *
- * @access public
- * @param boolean $keep_input_file Determines whether or not to reset the input file currently set.
- */
- public function reset($keep_input_file=FALSE, $keep_processes=FALSE) {
- if ($keep_input_file === FALSE) {
- $this->_input_file = NULL;
- }
- if ($keep_processes === FALSE) {
- $this->_post_processes = array();
- }
- $this->_single_frame_extraction = NULL;
- $this->_output_address = NULL;
- $this->_process_address = NULL;
- $this->_log_file = NULL;
- $this->_commands = array();
- $this->_command_output = array();
- $this->_timer_start = 0;
- $this->_process_file_count = 0;
- $this->__destruct();
- }
- private function _captureExecBufferFallback() {
- $commands = func_get_args();
- foreach ($commands as $command) {
- $buffer = array();
- $err = 0;
- exec($command . ' 2>&1', $buffer, $err);
- if ($err === 0) {
- return $buffer;
- }
- }
- return array();
- }
- private function _captureExecBuffer($command) {
- $buffer = array();
- $err = 0;
- exec($command . ' 2>&1', $buffer, $err);
- if ($err !== 127) {
- if (isset($buffer[0]) === FALSE) {
- $tmp_file = $this->_tmp_directory . '_temp_' . uniqid(time() . '-') . '.txt';
- exec($command . ' &>' . $tmp_file, $buffer, $err);
- if ($handle = fopen($tmp_file, 'r')) {
- $buffer = array();
- while (!feof($handle)) {
- array_push($buffer, fgets($handle, 4096));
- }
- fclose($handle);
- }
- @unlink($tmp_file);
- }
- }
- $this->_command_output[] = array(
- 'command' => $command,
- 'output' => implode("\n", $buffer),
- );
- return $buffer;
- }
- /**
- * Returns information about the specified file without having to use ffmpeg-php
- * as it consults the ffmpeg binary directly.
- * NOTE: calling this statically for caching to work you must set the temp directory.
- *
- * @access public
- * @return mixed FALSE on error encountered, TRUE otherwise
- * */
- public function getFFmpegInfo($read_from_cache = TRUE) {
- // check to see if the info has already been cached
- if ($read_from_cache && PHPVideoToolkit::$ffmpeg_info !== FALSE) {
- return PHPVideoToolkit::$ffmpeg_info;
- }
- $data = array();
- $formats = $this->_captureExecBuffer($this->_ffmpeg_binary . ' -formats');
- $codecs = $this->_captureExecBuffer($this->_ffmpeg_binary . ' -codecs');
- $filters = $this->_captureExecBuffer($this->_ffmpeg_binary . ' -bsfs');
- $protocols = $this->_captureExecBuffer($this->_ffmpeg_binary . ' -protocols');
- $pixformats = $this->_captureExecBufferFallback($this->_ffmpeg_binary . ' -pix_fmts', $this->_ffmpeg_binary . ' -pix_fmt list');
- $help = $this->_captureExecBuffer($this->_ffmpeg_binary . ' -h');
- self::$ffmpeg_found = $data['ffmpeg-found'] = !empty($formats) && strpos($formats[0], 'not found') === FALSE && strpos($formats[0], 'No such file or directory') === FALSE;
- $data['compiler'] = array();
- $data['binary'] = array();
- $data['ffmpeg-php-support'] = self::hasFFmpegPHPSupport();
- // FFmpeg 0.5 and lower don't support -codecs, -bsfs or -protocols, but the info is in -formats
- if (strpos(end($codecs), 'missing argument for option')) {
- $formats = implode("\n", $formats);
- $codecs = $formats;
- $filters = $formats;
- $protocols = $formats;
- $pixformats = implode("\n", $pixformats);
- $help = implode("\n", $help);
- $data['raw'] = $formats . $pixformats;
- }
- else {
- $formats = implode("\n", $formats);
- $codecs = implode("\n", $codecs);
- $filters = implode("\n", $filters);
- $protocols = implode("\n", $protocols);
- $pixformats = implode("\n", $pixformats);
- $help = implode("\n", $help);
- $data['raw'] = $formats . "\n" . $codecs . "\n" . $filters . "\n" . $protocols . "\n" . $pixformats;
- }
- if (!self::$ffmpeg_found) {
- self::$ffmpeg_info = $data;
- return $data;
- }
- // grab the versions
- $data['binary']['versions'] = self::getVersion($data['raw']);
- // grab the ffmpeg configuration flags
- $config_flags = array();
- if (preg_match_all('/--[a-zA-Z0-9\-]+/', $formats, $config_flags)) {
- $data['binary']['configuration'] = $config_flags[0];
- $data['binary']['vhook-support'] = in_array('--enable-vhook', $config_flags[0]) || !in_array('--disable-vhook', $config_flags[0]);
- // grab the ffmpeg compile info
- preg_match('/built on (.*), gcc: (.*)/', $formats, $conf);
- if (count($conf) > 0) {
- $data['compiler']['gcc'] = $conf[2];
- $data['compiler']['build_date'] = $conf[1];
- $data['compiler']['build_date_timestamp'] = strtotime($conf[1]);
- }
- }
- // grab the file formats available to ffmpeg
- $formatmatches = array();
- $data['formats'] = array();
- if (preg_match_all('/ (DE|D|E) (.*) {1,} (.*)/', $formats, $formatmatches)) {
- // loop and clean
- // Formats:
- // D. = Demuxing supported
- // .E = Muxing supported
- for ($i = 0, $a = count($formatmatches[0]); $i < $a; $i++) {
- $data['formats'][strtolower(trim($formatmatches[2][$i]))] = array(
- 'mux' => $formatmatches[1][$i] == 'DE' || $formatmatches[1][$i] == 'E',
- 'demux' => $formatmatches[1][$i] == 'DE' || $formatmatches[1][$i] == 'D',
- 'fullname' => $formatmatches[3][$i]
- );
- }
- }
- // grab the codecs available
- $codecsmatches = array();
- $data['codecs'] = array('video' => array(), 'audio' => array(), 'subtitle' => array());
- if (preg_match_all('/ ((?:[DEVAST ]{6})|(?:[DEVASTFB ]{8})|(?:[DEVASIL\.]{6})) ([A-Za-z0-9\_]+) (.+)/', $codecs, $codecsmatches)) {
- // FFmpeg 0.12+
- // D..... = Decoding supported
- // .E.... = Encoding supported
- // ..V... = Video codec
- // ..A... = Audio codec
- // ..S... = Subtitle codec
- // ...I.. = Intra frame-only codec
- // ....L. = Lossy compression
- // .....S = Lossless compression
- // FFmpeg other
- // D..... = Decoding supported
- // .E.... = Encoding supported
- // ..V... = Video codec
- // ..A... = Audio codec
- // ..S... = Subtitle codec
- // ...S.. = Supports draw_horiz_band
- // ....D. = Supports direct rendering method 1
- // .....T = Supports weird frame truncation
- for ($i = 0, $a = count($codecsmatches[0]); $i < $a; $i++) {
- $options = preg_split('//', $codecsmatches[1][$i], -1, PREG_SPLIT_NO_EMPTY);
- if ($options) {
- $id = trim($codecsmatches[2][$i]);
- $type = $options[2] === 'V' ? 'video' : ($options[2] === 'A' ? 'audio' : 'subtitle');
- switch ($options[2]) {
- // video
- case 'V' :
- $data['codecs'][$type][$id] = array(
- 'encode' => isset($options[1]) === TRUE && $options[1] === 'E',
- 'decode' => isset($options[0]) === TRUE && $options[0] === 'D',
- 'draw_horizontal_band' => isset($options[3]) === TRUE && $options[3] === 'S',
- 'direct_rendering_method_1' => isset($options[4]) === TRUE && $options[4] === 'D',
- 'weird_frame_truncation' => isset($options[5]) === TRUE && $options[5] === 'T',
- 'fullname' => trim($codecsmatches[3][$i])
- );
- break;
- // audio
- case 'A' :
- // subtitle
- case 'S' :
- $data['codecs'][$type][$id] = array(
- 'encode' => isset($options[1]) === TRUE && $options[1] === 'E',
- 'decode' => isset($options[0]) === TRUE && $options[0] === 'D',
- 'fullname' => trim($codecsmatches[3][$i])
- );
- break;
- }
- }
- }
- }
- // grab the bitstream filters available to ffmpeg
- $data['filters'] = array();
- $locate = 'Bitstream filters:';
- if (!empty($filters) && ($pos = strpos($filters, $locate)) !== FALSE) {
- $filters = trim(substr($filters, $pos + strlen($locate)));
- $data['filters'] = explode("\n", $filters);
- }
- // grab the file protocols available to ffmpeg
- $data['protocols'] = array();
- $locate = 'Supported file protocols:';
- if (!empty($protocols) && ($pos = strpos($protocols, $locate)) !== FALSE) {
- $protocols = trim(substr($filters, $pos + strlen($locate)));
- $data['protocols'] = explode("\n", $protocols);
- }
- // grab the pixel formats available to ffmpeg
- $data['pixelformats'] = array();
- // Separate code for FFmpeg 0.5
- if (strpos($pixformats, 'Pixel formats') === FALSE) {
- // Format:
- // name nb_channels depth is_alpha
- // yuv420p 3 8 n
- // yuyv422 1 8 n
- $matches = array();
- preg_match_all('#(\w+)\s+(\d+)\s+(\d+)\s+(y|n)#', $pixformats, $matches, PREG_SET_ORDER);
- foreach ($matches as $match) {
- $data['pixelformats'][$match[1]] = array(
- 'encode' => TRUE, // Assume true
- 'decode' => TRUE, // Assume true
- 'components' => intval($match[2]),
- 'bpp' => intval($match[3]),
- );
- }
- }
- else {
- // Format:
- // Pixel formats:
- // I.... = Supported Input format for conversion
- // .O... = Supported Output format for conversion
- // ..H.. = Hardware accelerated format
- // ...P. = Paletted format
- // ....B = Bitstream format
- // FLAGS NAME NB_COMPONENTS BITS_PER_PIXEL
- // -----
- // IO... yuv420p 3 12
- $matches = array();
- preg_match_all('#(I|\.)(O|\.)(H|\.)(P|\.)(B|\.)\s+(\w+)\s+(\d+)\s+(\d+)#', $pixformats, $matches, PREG_SET_ORDER);
- foreach ($matches as $match) {
- $data['pixelformats'][$match[6]] = array(
- 'encode' => $match[1] == 'I',
- 'decode' => $match[2] == 'O',
- 'components' => intval($match[7]),
- 'bpp' => intval($match[8]),
- );
- }
- }
- // grab the command line options available to ffmpeg
- $data['commandoptions'] = array();
- $matches = array();
- preg_match_all('#\n-(\w+)(?:\s+<(int|string|binary|flags|int64|float|rational)>)?#', $help, $matches, PREG_SET_ORDER);
- foreach ($matches as $match) {
- $data['commandoptions'][$match[1]] = array(
- 'datatype' => isset($match[2]) ? $match[2] : NULL,
- );
- }
- PHPVideoToolkit::$ffmpeg_info = $data;
- return $data;
- }
- /**
- * Returns the installed version of FFmpeg
- * @param $format
- * one of raw, version
- * @return $version
- * String, FFmpeg version
- */
- protected function getVersion($output) {
- // Search for SVN string
- // FFmpeg version SVN-r20438, Copyright (c) 2000-2009 Fabrice Bellard, et al.
- $pattern = "/(?:ffmpeg|avconv) version SVN-r([0-9.]*)/i";
- if (preg_match($pattern, $output, $matches)) {
- return $matches[1];
- }
- // Some OSX versions are built from a very early CVS
- // I do not know what to do with this version- using 1 for now
- $pattern = "/(?:ffmpeg|avconv) version.*CVS.*Mac OSX universal/msUi";
- if (preg_match($pattern, $output, $matches)) {
- return 0;
- }
- // Search for git string
- // FFmpeg version git-N-29240-gefb5fa7, Copyright (c) 2000-2011 the FFmpeg developers.
- // ffmpeg version N-31145-g59bd0fe, Copyright (c) 2000-2011 the FFmpeg developers
- $pattern = "/(?:ffmpeg|avconv) version.*N-([0-9.]*)/i";
- if (preg_match($pattern, $output, $matches)) {
- // Versions above this seem to be ok
- if ($matches[1] >= 29240) {
- return array(
- 'svn' => (int) $matches[1],
- 'version' => NULL, // Return NULL as there appears to be no version number.
- );
- }
- }
- // Do we have a release?
- // ffmpeg version 0.4.9-pre1, build 4736, Copyright (c) 2000-2004 Fabrice Bellard
- $pattern = "/(?:ffmpeg|avconv) version ([0-9.]*)/i";
- if (preg_match($pattern, $output, $matches)) {
- return $matches[1];
- }
- // Do we have a build version?
- // ffmpeg version 0.4.9-pre1, build 4736, Copyright (c) 2000-2004 Fabrice Bellard
- $pattern = "/(?:ffmpeg|avconv) version.*, build ([0-9]*)/i";
- if (preg_match($pattern, $output, $matches)) {
- return $matches[1];
- }
- return FALSE;
- }
- /**
- * Determines if your ffmpeg has particular codec support for encode or decode.
- *
- * @access public
- * @param $codec
- * The name of the codec you are checking for.
- * @param $support
- * PHPVideoToolkit::ENCODE or PHPVideoToolkit::DECODE, depending on which functionality is desired.
- * @return
- * Boolean FALSE if there is no support, TRUE if there is support.
- */
- public function hasCodecSupport($codec, $support=PHPVideoToolkit::ENCODE) {
- $codec = strtolower($codec);
- $data = $this->getFFmpegInfo();
- return isset($data['formats'][$codec]) === TRUE ? $data['formats'][$codec][$support] : FALSE;
- }
- /**
- * Determines the type of support that exists for the FFmpeg-PHP module.
- *
- * @access public
- * @return mixed. Boolean FALSE if there is no support, String 'module' if the actuall
- * FFmpeg-PHP module is loaded, or String 'emulated' if the FFmpeg-PHP classes
- * can be emulated through the adapter classes.
- */
- public function hasFFmpegPHPSupport() {
- return self::$ffmpeg_found === FALSE ? FALSE : (extension_loaded('ffmpeg') ? 'module' : (is_file(dirname(__FILE__) . DS . 'adapters' . DS . 'ffmpeg-php' . DS . 'ffmpeg_movie.php') && is_file(dirname(__FILE__) . DS . 'adapters' . DS . 'ffmpeg-php' . DS . 'ffmpeg_frame.php') && is_file(dirname(__FILE__) . DS . 'adapters' . DS . 'ffmpeg-php' . DS . 'ffmpeg_animated_gif.php') ? 'emulated' : FALSE));
- }
- /**
- * Determines if the ffmpeg binary has been compiled with vhook support.
- *
- * @access public
- * @return mixed. Boolean FALSE if there is no support, TRUE there is support.
- */
- public function hasVHookSupport() {
- $info = $this->getFFmpegInfo();
- return $info['binary']['vhook-support'];
- }
- /**
- * Returns information about the specified file without having to use ffmpeg-php
- * as it consults the ffmpeg binary directly. This idea for this function has been borrowed from
- * a French ffmpeg class located: http://www.phpcs.com/codesource.aspx?ID=45279
- *
- * @param $file
- * The absolute path of the file that is required to be manipulated.
- * @return
- * FALSE on error encountered, TRUE otherwise
- */
- public function getFileInfo($file = FALSE) {
- // if the file has not been specified check to see if an input file has been specified
- if ($file === FALSE) {
- if (!$this->_input_file) {
- return $this->_raiseError('getFileInfo_no_input');
- }
- $file = $this->_input_file;
- }
- $file = escapeshellarg($file);
- // create a hash of the filename
- $hash = md5($file);
- // check to see if the info has already been generated
- if (isset(self::$_file_info[$hash]) === TRUE) {
- return self::$_file_info[$hash];
- }
- // execute the ffmpeg lookup
- $buffer = $this->_captureExecBuffer($this->_ffmpeg_binary . ' -i ' . $file);
- $buffer = implode("\r\n", $buffer);
- $data = $this->parseFileInfo($buffer);
- // check that some data has been obtained
- if (empty($data)) {
- $data = FALSE;
- }
- else {
- $data['_raw_info'] = $buffer;
- }
- // cache info and return
- return self::$_file_info[$hash] = $data;
- }
- /**
- * Parses file information returned by ffmpeg -i
- *
- * @param $raw
- * Return text of ffmpeg -i
- * @return
- * Array containing various data about the file
- */
- public function parseFileInfo($raw) {
- $data = array();
- $matches = array();
- // grab the duration and bitrate data
- preg_match_all('/Duration: (.*)/', $raw, $matches);
- if (!empty($matches)) {
- $line = trim($matches[0][0]);
- // capture any data
- preg_match_all('/(Duration|start|bitrate): ([^,]*)/', $line, $matches);
- // setup the default data
- $data['duration'] = array(
- 'timecode' => array(
- 'seconds' => array(
- 'exact' => -1,
- 'excess' => -1
- ),
- 'rounded' => -1,
- )
- );
- // get the data
- foreach ($matches[1] as $key => $detail) {
- $value = $matches[2][$key];
- switch (strtolower($detail)) {
- case 'duration' :
- $data['duration']['timecode']['rounded'] = substr($value, 0, 8);
- $data['duration']['timecode']['frames'] = array();
- $data['duration']['timecode']['frames']['exact'] = $value;
- $data['duration']['timecode']['frames']['excess'] = intval(substr($value, 9));
- break;
- case 'bitrate' :
- $data['bitrate'] = strtoupper($value) === 'N/A' ? -1 : intval($value);
- break;
- case 'start' :
- $data['duration']['start'] = $value;
- break;
- }
- }
- }
- // match the video stream info
- preg_match('/Stream(.*): Video: (.*)/', $raw, $matches);
- if (count($matches) > 0) {
- $data['video'] = array();
- // get the dimension parts
- preg_match('/([1-9][0-9]*)x([1-9][0-9]*)/', $matches[2], $dimensions_matches);
- $dimensions_value = $dimensions_matches[0];
- $data['video']['dimensions'] = array(
- 'width' => floatval($dimensions_matches[1]),
- 'height' => floatval($dimensions_matches[2])
- );
- // get the timebases
- $data['video']['time_bases'] = array();
- preg_match_all('/([0-9\.k]+) (fps|tbr|tbc|tbn)/', $matches[0], $fps_matches);
- if (count($fps_matches[0]) > 0) {
- foreach ($fps_matches[2] as $key => $abrv) {
- $data['video']['time_bases'][$abrv] = $fps_matches[1][$key];
- }
- }
- // get the video frames per second
- $data['duration']['timecode']['seconds']['total'] = $data['duration']['seconds'] = (float)$this->formatTimecode($data['duration']['timecode']['frames']['exact'], '%hh:%mm:%ss.%ms', '%ss.%ms');
- $fps = isset($data['video']['time_bases']['fps']) === TRUE ? $data['video']['time_bases']['fps'] : (isset($data['video']['time_bases']['tbr']) === TRUE ? $data['video']['time_bases']['tbr'] : FALSE);
- if ($fps !== FALSE) {
- $fps = floatval($fps);
- $data['duration']['timecode']['frames']['frame_rate'] = $data['video']['frame_rate'] = $fps;
- // set the total frame count for the video
- $data['video']['frame_count'] = ceil($data['duration']['seconds'] * $data['video']['frame_rate']);
- $data['duration']['timecode']['frames']['exact'] = $this->formatTimecode($data['video']['frame_count'], '%ft', '%hh:%mm:%ss.%fn', $fps);
- $data['duration']['timecode']['frames']['total'] = $data['video']['frame_count'];
- }
- $fps_value = $fps_matches[0];
- // get the ratios
- preg_match('/\[PAR ([0-9\:\.]+) DAR ([0-9\:\.]+)\]/', $matches[0], $ratio_matches);
- if (count($ratio_matches)) {
- $data['video']['pixel_aspect_ratio'] = $ratio_matches[1];
- $data['video']['display_aspect_ratio'] = $ratio_matches[2];
- }
- // work out the number of frames
- if (isset($data['duration']) === TRUE && isset($data['video']) === TRUE) {
- // set the framecode
- $data['duration']['timecode']['seconds']['excess'] = floatval($data['duration']['seconds']) - floor($data['duration']['seconds']);
- $data['duration']['timecode']['seconds']['exact'] = $this->formatSeconds($data['duration']['seconds'], '%hh:%mm:%ss.%ms');
- }
- // formats should be anything left over, let me know if anything else exists
- $parts = explode(',', $matches[2]);
- $other_parts = array($dimensions_value, $fps_value);
- $formats = array();
- foreach ($parts as $key => $part) {
- $part = trim($part);
- if (!in_array($part, $other_parts)) {
- array_push($formats, $part);
- }
- }
- $data['video']['pixel_format'] = $formats[1];
- $data['video']['codec'] = $formats[0];
- }
- // match the audio stream info
- preg_match('/Stream(.*): Audio: (.*)/', $raw, $matches);
- if (count($matches) > 0) {
- // setup audio values
- $data['audio'] = array(
- 'stereo' => -1,
- 'sample_rate' => -1,
- 'sample_rate' => -1
- );
- $other_parts = array();
- // get the stereo value
- preg_match('/(stereo|mono)/i', $matches[0], $stereo_matches);
- if (count($stereo_matches)) {
- $data['audio']['stereo'] = $stereo_matches[0];
- array_push($other_parts, $stereo_matches[0]);
- }
- // get the sample_rate
- preg_match('/([0-9]{3,6}) Hz/', $matches[0], $sample_matches);
- if (count($sample_matches)) {
- $data['audio']['sample_rate'] = count($sample_matches) ? floatval($sample_matches[1]) : -1;
- array_push($other_parts, $sample_matches[0]);
- }
- // get the bit rate
- preg_match('/([0-9]{1,3}) kb\/s/', $matches[0], $bitrate_matches);
- if (count($bitrate_matches)) {
- $data['audio']['bitrate'] = count($bitrate_matches) ? floatval($bitrate_matches[1]) : -1;
- array_push($other_parts, $bitrate_matches[0]);
- }
- // formats should be anything left over, let me know if anything else exists
- $parts = explode(',', $matches[2]);
- $formats = array();
- foreach ($parts as $key => $part) {
- $part = trim($part);
- if (!in_array($part, $other_parts)) {
- array_push($formats, $part);
- }
- }
- $data['audio']['codec'] = $formats[0];
- // if no video is set then no audio frame rate is set
- if ($data['duration']['timecode']['seconds']['exact'] === -1) {
- $exact_timecode = $this->formatTimecode($data['duration']['timecode']['frames']['exact'], '%hh:%mm:%ss.%fn', '%hh:%mm:%ss.%ms', 1000);
- $data['duration']['timecode']['seconds'] = array(
- 'exact' => $exact_timecode,
- 'excess' => intval(substr($exact_timecode, 8)),
- 'total' => $this->formatTimecode($data['duration']['timecode']['frames']['exact'], '%hh:%mm:%ss.%fn', '%ss.%ms', 1000)
- );
- $data['duration']['timecode']['frames']['frame_rate'] = 1000;
- $data['duration']['seconds'] = $data['duration']['timecode']['seconds']['total'];
- }
- }
- return $data;
- }
- /**
- * Determines if the input media has a video stream.
- *
- * @access public
- * @param string $file The absolute path of the file that is required to be manipulated.
- * @return bool
- * */
- public function fileHasVideo($file=FALSE) {
- // check to see if this is a static call
- if ($file !== FALSE && isset($this) === FALSE) {
- $toolkit = new PHPVideoToolkit();
- $data = $toolkit->getFileInfo($file);
- }
- // if the file has not been specified check to see if an input file has been specified
- elseif ($file === FALSE) {
- if (!$this->_input_file) {
- // input file not valid
- return $this->_raiseError('inputFileHasVideo_no_input');
- // <- exits
- }
- $file = $this->_input_file;
- $data = $this->getFileInfo($file);
- }
- return isset($data['video']);
- }
- /**
- * Determines if the input media has an audio stream.
- *
- * @access public
- * @param string $file The absolute path of the file that is required to be manipulated.
- * @return bool
- * */
- public function fileHasAudio($file=FALSE) {
- // check to see if this is a static call
- if ($file !== FALSE && isset($this) === FALSE) {
- $toolkit = new PHPVideoToolkit();
- $data = $toolkit->getFileInfo($file);
- }
- // if the file has not been specified check to see if an input file has been specified
- elseif ($file === FALSE) {
- if (!$this->_input_file) {
- // input file not valid
- return $this->_raiseError('inputFileHasAudio_no_input');
- // <- exits
- }
- $file = $this->_input_file;
- $data = $this->getFileInfo($file);
- }
- return isset($data['audio']);
- }
- /**
- * Sets the input file that is going to be manipulated.
- *
- * @access public
- * @param string $file The absolute path of the file that is required to be manipulated.
- * @param mixed $input_frame_rate If 0 (default) then no input frame rate is set, if FALSE it is automatically retrieved, otherwise
- * any other integer will be set as the incoming frame rate.
- * @return boolean FALSE on error encountered, TRUE otherwise
- */
- public function setInputFile($file, $input_frame_rate=0, $validate_decode_codecs=TRUE) {
- $files_length = count($file);
- // if the total number of files entered is 1 then only one file is being processed
- if ($files_length == 1) {
- // check the input file, if there is a %d in there or a similar %03d then the file inputted is a sequence, if neither of those is found
- // then qheck to see if the file exists
- if (!preg_match('/\%([0-9]+)d/', $file) && strpos($file, '%d') === FALSE && !is_file($file)) {
- // input file not valid
- return $this->_raiseError('setInputFile_file_existence', array('file' => $file));
- // <- exits
- }
- $escaped_name = $file;
- // $escaped_name = escapeshellarg($files[0]);
- $this->_input…
Large files files are truncated, but you can click here to view the full file