public function jquerycreateVideo($params, $file, $values)
{
if( $file instanceof Storage_Model_File ) {
$params[‘file_id’] = $file->getIdentity();
} else {
// create video item
$video = Engine_Api::_()->getDbtable(‘videos’, ‘video’)->createRow();
$file_ext = $file[‘extension’];
$video->code = $file_ext;
$video->type = 3;
$video->status = 1;
$video->save();
// Store video in temporary storage object for ffmpeg to handle
$storage = Engine_Api::_()->getItemTable(‘storage_file’);
$storageObject = $storage->createFile($file, array(
‘parent_id’ => $video->getIdentity(),
‘parent_type’ => $video->getType(),
‘user_id’ => $video->owner_id,
));
$file_tmp_name = $storageObject->storage_path;
$image = ‘public/’.strtotime(“now”).’.jpg’;
$second = 1;
$ffmpeg = ‘/usr/bin/ffmpeg’;
$command = “ffmpeg -itsoffset -$second -i $file_tmp_name -vcodec mjpeg -vframes 1 -an -f rawvideo $image”;
exec($command);
// Remove temporary file
@unlink($file[‘tmp_name’]);
$video->file_id = $storageObject->file_id;
$video->save();
// Store video in temp directory for ffmpeg to handle
// $tmp_file = APPLICATION_PATH . ‘/temporary/video/’.$video->video_id.”.”.$file_ext;
// $tmp_path = dirname($tmp_file);
// if( !file_exists($tmp_path) ) {
// mkdir($tmp_path, 0777, true);
// }
// $src_fh = fopen($file[‘tmp_name’], ‘r’);
// $tmp_fh = fopen($tmp_file, ‘w’);
// stream_copy_to_stream($src_fh, $tmp_fh);
// Add to jobs
Engine_Api::_()->getDbtable(‘jobs’, ‘core’)->addJob(‘video_encode’, array(
‘video_id’ => $video->getIdentity(),
));
}
//$video->save();
return $video;
}