public function PHPVideoToolkit::prepareImagesForConversionToVideo in Video 7
Same name and namespace in other branches
- 7.2 libraries/phpvideotoolkit/phpvideotoolkit.php5.php \PHPVideoToolkit::prepareImagesForConversionToVideo()
* Compiles an array of images into a video. This sets the input file (setInputFile) so you do not need to set it. * The images should be a full absolute path to the actual image file. * NOTE 1; This copies and renames all the supplied images into a temporary folder so the images don't have to be specifically named. However, when * creating the ffmpeg instance you will need to set the absolute path to the temporary folder. The default path is '/tmp/'. * NOTE 2; Please make sure all of the images are all of the same type. * * @access public *
Parameters
array $images An array of images that are to be joined and converted into a video: * @param integer $input_frame_rate An integer that will specify the input frame rate for the images. * @return boolean Returns false on encountering an error
File
- libraries/
phpvideotoolkit/ phpvideotoolkit.php5.php, line 1554
Class
Code
public function prepareImagesForConversionToVideo($images, $input_frame_rate) {
// http://ffmpeg.mplayerhq.hu/faq.html#TOC3
// ffmpeg -f image2 -i img%d.jpg /tmp/a.mpg
if (empty($images)) {
return $this
->_raiseError('prepareImagesForConversionToVideo_one_img');
//<- exits
}
// loop through and validate existence first before making a temporary copy
foreach ($images as $key => $img) {
if (!is_file($img)) {
return $this
->_raiseError('prepareImagesForConversionToVideo_img_404', array(
'img' => $img,
));
//<- exits
}
}
if (!is_dir($this->_tmp_directory)) {
return $this
->_raiseError('generic_temp_404');
//<- exits
}
if (!is_writable($this->_tmp_directory)) {
return $this
->_raiseError('generic_temp_writable');
//<- exits
}
// get the number of preceding places for the files based on how many files there are to copy
$total = count($images);
// create a temp dir in the temp dir
$uniqid = $this
->unique();
mkdir($this->_tmp_directory . $uniqid, 0777);
// loop through, copy and rename specified images to the temp dir
$ext = false;
foreach ($images as $key => $img) {
$file_ext = array_pop(explode('.', $img));
if ($ext !== false && $ext !== $file_ext) {
return $this
->_raiseError('prepareImagesForConversionToVideo_img_type');
//<- exits
}
$ext = $file_ext;
$tmp_file = $this->_tmp_directory . $uniqid . DS . $this->_tmp_file_prefix . $key . '.' . $ext;
if (!@copy($img, $tmp_file)) {
return $this
->_raiseError('prepareImagesForConversionToVideo_img_copy', array(
'img' => $img,
'tmpfile' => $tmp_file,
));
//<- exits
}
// push the tmp file name into the unlinks so they can be deleted on class destruction
array_push($this->_unlink_files, $tmp_file);
}
// the inputr is a hack for -r to come before the input
$this
->addCommand('-inputr', $input_frame_rate);
// exit;
// add the directory to the unlinks
array_push($this->_unlink_dirs, $this->_tmp_directory . $uniqid);
// get the input file format
$file_iteration = $this->_tmp_file_prefix . '%d.' . $ext;
// set the input filename
return $this
->setInputFile($this->_tmp_directory . $uniqid . DS . $file_iteration);
}