V 3.5 RC 1

This commit is contained in:
Romain Neutron
2011-12-05 00:23:28 +01:00
parent 6f1ee368aa
commit 4c5b7eb658
5563 changed files with 466984 additions and 985416 deletions

View File

@@ -0,0 +1,31 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2010 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
/**
* Gif from video generator adpater for binaryAdapter package
*
* @package binaryAdapter
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
class binaryAdapter_video_gif extends binaryAdapter_adapterAbstract
{
protected $processors = array(
'binaryAdapter_video_gif_ffmpeg'
);
public function get_name()
{
return 'Binary adapter video to gif animation';
}
}

View File

@@ -0,0 +1,124 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2010 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
/**
* FFMPEG video to processor for binaryAdapter package
*
* @package binaryAdapter
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
class binaryAdapter_video_gif_ffmpeg extends binaryAdapter_video_processorAbstract implements binaryAdapter_processorInterface
{
/**
*
* @var array
*/
protected $options = array(
'size' => null
);
/**
*
* @var string
*/
protected $binary_name = 'GV_ffmpeg';
/**
*
* @param system_file $origine
* @param string $dest
* @return system_file
*/
protected function process(system_file $origine, $dest)
{
$this->log('GENERATING anim gif');
$tmpDir = $this->registry->get('GV_RootPath') . 'tmp/' . 'tmp' . time();
system_file::mkdir($tmpDir);
$tmpDir = p4string::addEndSlash($tmpDir);
$dimensions = $this->get_dimensions($origine, $this->options['size']);
$newHeight = $dimensions['height'];
$newWidth = $dimensions['width'];
$system = system_server::get_platform();
if ($system == 'WINDOWS')
{
$cmd = $this->registry->get('GV_ffmpeg')
. ' -i ' . $this->escapeshellargs($origine->getPathname())
. ' -s ' . $newWidth . 'x' . $newHeight
. ' -r 1 -f image2 '
. $tmpDir . 'images%05d.jpg';
}
else
{
$cmd = $this->binary
. ' -i ' . $this->escapeshellargs($origine->getPathname())
. ' -s ' . $newWidth . 'x' . $newHeight
. ' -r 1 -f image2 '
. $this->escapeshellargs($tmpDir) . 'images%05d.jpg';
}
$this->shell_cmd($cmd);
$files = array();
foreach (new RecursiveIteratorIterator(
new RecursiveDirectoryIterator($tmpDir),
RecursiveIteratorIterator::LEAVES_ONLY
) as $file)
{
if ($file->isDir() || strpos($file->getPathname(), '/.svn/') !== false)
{
continue;
}
if ($file->isFile())
{
$filename = $file->getFilename();
$files[$filename] = $file->getPathname();
}
}
ksort($files);
$n = count($files);
$inter = round(count($files) / 10);
$i = 0;
foreach ($files as $k => $file)
{
if ($i % $inter !== 0)
{
if (unlink($file))
unset($files[$k]);
}
$i++;
}
$cmd = $this->registry->get('GV_imagick')
. ' -delay 100 -loop 0 ' . $tmpDir . '*.jpg ' . $dest;
$this->shell_cmd($cmd);
foreach ($files as $file)
unlink($file);
rmdir($tmpDir);
return $this;
}
}

View File

@@ -0,0 +1,101 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2010 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
/**
* Abstract video adapter object for binaryAdapter
*
* @package binaryAdapter
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
abstract class binaryAdapter_video_processorAbstract extends binaryAdapter_processorAbstract
{
/**
*
* @param int $value
* @param int $multiple
* @param string $bound
* @return int
*/
protected function get_multiple($value, $multiple, $bound='nearest')
{
$modulo = $value % $multiple;
$ret = 0;
if ($bound == 'nearest')
{
$half_distance = $multiple / 2;
if ($modulo <= $half_distance)
$bound = 'bottom';
else
$bound = 'top';
}
switch ($bound)
{
default:
case 'top':
$ret = $value + $multiple - $modulo;
break;
case 'bottom':
$ret = $value - $modulo;
break;
}
if ($ret < $multiple)
$ret = $multiple;
return (int) $ret;
}
/**
*
* @param system_file $origine
* @param int $size
* @return array
*/
protected function get_dimensions(system_file $origine, $size)
{
$tech_datas = $origine->get_technical_datas();
$maxSize = $this->get_multiple($size, 16, 'bottom');
$srcWidth = $tech_datas[system_file::TC_DATAS_WIDTH];
$srcHeight = $tech_datas[system_file::TC_DATAS_HEIGHT];
if ($srcWidth > $maxSize || $srcHeight > $maxSize)
{
if ($srcWidth >= $srcHeight)
{
$newWidth = (int) $maxSize;
$height = round($newWidth * $srcHeight / $srcWidth);
$newHeight = $this->get_multiple($height, 16);
}
else
{
$newHeight = (int) $maxSize;
$width = round($newHeight * $srcWidth / $srcHeight);
$newWidth = $this->get_multiple($width, 16);
}
}
else
{
$newHeight = $this->get_multiple($srcHeight, 16);
$newWidth = $this->get_multiple($srcWidth, 16);
}
return array('width' => $newWidth, 'height' => $newHeight);
}
}

View File

@@ -0,0 +1,32 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2010 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
/**
* MP4 Progressive adpater for binaryAdapter package
*
* @package binaryAdapter
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
class binaryAdapter_video_progressive extends binaryAdapter_adapterAbstract
{
protected $processors = array(
'binaryAdapter_video_progressive_mp4box',
'binaryAdapter_video_progressive_moovRelocator'
);
public function get_name()
{
return 'Binary adapter video progressive download';
}
}

View File

@@ -0,0 +1,70 @@
<?php
require_once dirname(__FILE__) . '/../../../../vendor/moov/relocator.class.php';
/*
* This file is part of Phraseanet
*
* (c) 2005-2010 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
/**
* moovRelocator progressive mp4 processor for binaryAdapter package
*
* @package binaryAdapter
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
class binaryAdapter_video_progressive_moovRelocator extends binaryAdapter_video_processorAbstract implements binaryAdapter_processorInterface
{
/**
*
* @var array
*/
protected $options = array(
'size' => null
);
/**
*
* @var string
*/
protected $binary_name = 'MoovRelocator';
/**
*
* @var string
*/
protected $binary = '/usr/bin/php';
/**
*
* @param system_file $origine
* @param string $dest
* @return system_file
*/
protected function process(system_file $origine, $dest)
{
$mp4_file = $origine->getPathname();
$moovrelocator = moov_relocator::getInstance();
$ret = $moovrelocator->setInput($mp4_file);
if ($ret !== true)
throw new Exception('File format not ok');
$ret = $moovrelocator->setOutput($dest);
if ($ret !== true)
throw new Exception('File output error');
$ret = $moovrelocator->fix();
if ($ret !== true)
throw new Exception('Error while fixing');
return $this;
}
}

View File

@@ -0,0 +1,51 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2010 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
/**
* MP4Box progressive mp4 processor for binaryAdapter package
*
* @package binaryAdapter
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
class binaryAdapter_video_progressive_mp4box extends binaryAdapter_video_processorAbstract implements binaryAdapter_processorInterface
{
/**
*
* @var array
*/
protected $options = array();
/**
*
* @var string
*/
protected $binary_name = 'GV_mp4box';
/**
*
* @param system_file $origine
* @param string $dest
* @return system_file
*/
protected function process(system_file $origine, $dest)
{
$cmd = sprintf("%s -inter 0.5 %s -out %s"
, $this->binary
, $this->escapeshellargs($origine->getPathname())
, $this->escapeshellargs($dest));
$this->shell_cmd($cmd);
return $this;
}
}

View File

@@ -0,0 +1,31 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2010 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
/**
* Video resizer adpater for binaryAdapter package
*
* @package binaryAdapter
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
class binaryAdapter_video_resize extends binaryAdapter_adapterAbstract
{
protected $processors = array(
'binaryAdapter_video_resize_ffmpeg'
);
public function get_name()
{
return 'Binary adapter video resizer';
}
}

View File

@@ -0,0 +1,235 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2010 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
/**
* FFMPEG video resize processor for binaryAdapter package
*
* @package binaryAdapter
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
class binaryAdapter_video_resize_ffmpeg extends binaryAdapter_video_processorAbstract implements binaryAdapter_processorInterface
{
/**
*
* @var array
*/
protected $options = array(
'size' => 400,
'fps' => 25,
'threads' => 1,
'bitrate' => 1000,
'v_codec' => 'libx264',
'a_codec' => 'libfaac'
);
/**
*
* @var string
*/
protected $binary_name = 'GV_ffmpeg';
/**
*
* @param string $name
* @param string $value
* @return binaryAdapter_video_resize_ffmpeg
*/
protected function set_option($name, $value)
{
switch ($name)
{
case 'fps':
$value = (int) $value;
$value = ($value <= 1 || $value > 200) ? 25 : $value;
break;
case 'threads':
$value = (int) $value;
$value = ($value <= 1 || $value > 32) ? 1 : $value;
break;
case 'bitrate':
$value = (int) $value;
$value = ($value <= 100 || $value > 50000) ? 1000 : $value;
break;
case 'v_codec':
$v_codecs = array(
'x264' => 'libx264',
'h264' => 'libx264',
'libx264' => 'libx264',
'libh264' => 'h264',
'flv' => 'flv',
'flash' => 'flv'
);
$value = array_key_exists($value, $v_codecs) ? $v_codecs[$value] : 'libx264';
break;
case 'a_codec':
$a_codecs = array(
'faac' => 'libfaac',
'libfaac' => 'libfaac',
'mp3' => 'libmp3lame'
);
$value = array_key_exists($value, $a_codecs) ? $a_codecs[$value] : 'libfaac';
break;
}
parent::set_option($name, $value);
return $this;
}
/**
*
* @param system_file $origine
* @param string $dest
* @return system_file
*/
protected function process(system_file $origine, $dest)
{
$tech_datas = $origine->get_technical_datas();
$srcWidth = $tech_datas[system_file::TC_DATAS_WIDTH];
$srcHeight = $tech_datas[system_file::TC_DATAS_HEIGHT];
$srcFPS = $tech_datas[system_file::TC_DATAS_FRAMERATE];
$srcAR = isset($tech_datas[system_file::TC_DATAS_AUDIOSAMPLERATE]) ?
$tech_datas[system_file::TC_DATAS_AUDIOSAMPLERATE] : null;
$srcAB = isset($tech_datas[system_file::TC_DATAS_AUDIOBITRATE]) ?
intval($tech_datas[system_file::TC_DATAS_AUDIOBITRATE] / 1000) : null;
$dimensions = $this->get_dimensions($origine, $this->options['size']);
$newHeight = $dimensions['height'];
$newWidth = $dimensions['width'];
$cwd = getcwd();
chdir($this->registry->get('GV_RootPath') . 'tmp/');
if ($this->debug)
$this->log("GENERATING video ");
if ($this->options['v_codec'] == 'flv')
$dest = $this->set_extension($dest, 'flv');
else
$dest = $this->set_extension($dest, 'mp4');
$dest_pass1 = $dest . '-tmp.mp4';
$system = system_server::get_platform();
if ($system == 'WINDOWS')
{
$cmd_part1 = $this->binary->getPathname()
. ' -y -i \''
. str_replace('/', "\\", $origine->getPathname()) . '\' ';
}
else
{
$cmd_part1 = $this->binary->getPathname()
. ' -y -i '
. $this->escapeshellargs($origine->getPathname()) . ' ';
}
if (in_array($this->options['v_codec'], array('libx264', 'h264')))
{
$cmd_part2 = ' -s ' . $newWidth . 'x' . $newHeight
. ' -r ' . $this->options['fps']
. ' -vcodec ' . trim($this->options['v_codec'])
. ' -b ' . trim($this->options['bitrate']) . 'k -g 25 -bf 3'
. ' -threads ' . $this->options['threads']
. ' -refs 6 -b_strategy 1 -coder 1 -qmin 10 -qmax 51 '
. ' -sc_threshold 40 -flags +loop -cmp +chroma'
. ' -me_range 16 -subq 7 -i_qfactor 0.71 -qcomp 0.6 -qdiff 4 '
. ' -directpred 3 -flags2 +dct8x8+wpred+bpyramid+mixed_refs'
. ' -trellis 1 '
. ' -partitions +parti8x8+parti4x4+partp8x8+partp4x4+partb8x8 '
. '-acodec ' . trim($this->options['a_codec']) . ' -ab 92k ';
$cmd_pass1 = $cmd_part1 . ' -pass 1 ' . $cmd_part2
. ' -an ' . $this->escapeshellargs($dest_pass1);
$cmd_pass2 = $cmd_part1 . ' -pass 2 ' . $cmd_part2
. ' -ac 2 -ar 44100 ' . $this->escapeshellargs($dest);
if (is_file($dest))
unlink($dest);
$this->shell_cmd($cmd_pass1);
$this->shell_cmd($cmd_pass2);
$files = array(
'ffmpeg2pass-0.log',
'x264_2pass.log',
'x264_2pass.log.mbtree'
);
foreach ($files as $file)
{
if (is_file($file))
unlink($file);
}
if (is_file($dest_pass1))
unlink($dest_pass1);
}
else
{
$audioEnc = '';
if (trim($srcAB) != '' && trim($srcAB) != '')
{
$okMp3BR = array('44100' => true, '22050' => true, '11025' => true);
if (!isset($srcAR)
|| trim($srcAR) == ''
|| !array_key_exists($srcAR, $okMp3BR))
{
$srcAR = '44100';
}
if ($srcAB == '0' || trim($srcAB) == '')
$srcAB = '0';
$audioEnc = ' -ar ' . $srcAR
. ' -ab ' . $srcAB . 'k -acodec libmp3lame ';
}
if ($system == 'WINDOWS')
{
$cmd = $this->binary->getPathname()
. ' -y -i \''
. str_replace('/', "\\", $origine->getPathname()) . '\' ';
}
else
{
$cmd = $this->binary->getPathname()
. ' -y -i '
. $this->escapeshellargs($origine->getPathname()) . ' ';
}
$cmd .= $audioEnc .
' -f flv -nr 500 -s ' . $newWidth . 'x' . $newHeight . '' .
' -r ' . $this->options['fps'] .
' -b 270k -me_range ' . $srcFPS
. ' -i_qfactor 0.71 -g 500 ' . $this->escapeshellargs($dest);
if ($this->debug)
$this->log("execution commande : " . $cmd_pass2);
$this->shell_cmd($cmd);
}
chdir($cwd);
return $this;
}
}

View File

@@ -0,0 +1,31 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2010 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
/**
* Video image extractor adpater for binaryAdapter package
*
* @package binaryAdapter
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
class binaryAdapter_video_toimage extends binaryAdapter_adapterAbstract
{
protected $processors = array(
'binaryAdapter_video_toimage_ffmpeg'
);
public function get_name()
{
return 'Binary adapter video to image';
}
}

View File

@@ -0,0 +1,106 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2010 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
/**
* FFMPEG image from video extractor processor for binaryAdapter package
*
* @package binaryAdapter
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
class binaryAdapter_video_toimage_ffmpeg extends binaryAdapter_video_processorAbstract implements binaryAdapter_processorInterface
{
/**
*
* @var array
*/
protected $options = array(
'size' => null
);
/**
*
* @var string
*/
protected $binary_name = 'GV_ffmpeg';
/**
*
* @param system_file $origine
* @param string $dest
* @return system_file
*/
protected function process(system_file $origine, $dest)
{
$tmpDir = $this->registry->get('GV_RootPath')
. 'tmp/' . 'tmp' . time() . '/';
system_file::mkdir($tmpDir);
$tmpFile = $tmpDir . 'extract-tmp.jpg';
$tech_datas = $origine->get_technical_datas();
$time_tot = $tech_datas[system_file::TC_DATAS_DURATION];
$time_cut = max(round($tech_datas[system_file::TC_DATAS_DURATION] * 0.6), 1);
$system = system_server::get_platform();
if ($this->debug)
$this->log("Duree totale : " . $tech_datas[system_file::TC_DATAS_DURATION]);
$dimensions = $this->get_dimensions($origine, $this->options['size']);
$newHeight = $dimensions['height'];
$newWidth = $dimensions['width'];
$system = system_server::get_platform();
if ($system == 'WINDOWS')
{
$cmd = $this->binary
. ' -i ' . $this->escapeshellargs($origine->getPathname())
. ' -s ' . $newWidth . 'x' . $newHeight
. ' -vframes 1 -ss ' . $time_cut
. ' -f image2 ' . $this->escapeshellargs($tmpFile);
}
else
{
$cmd = $this->binary
. ' -i ' . $this->escapeshellargs($origine->getPathname())
. ' -s ' . $newWidth . 'x' . $newHeight
. ' -vframes 1 -ss ' . $time_cut
. ' -f image2 ' . $this->escapeshellargs($tmpFile);
}
$this->shell_cmd($cmd);
if ($this->debug)
$this->log("Commande executee : $cmd \n");
if (!file_exists($tmpFile))
throw new Exception('Unable to extract image');
$cmd = $this->registry->get('GV_pathcomposite')
. ' -gravity SouthEast -quiet -compose over "'
. $this->registry->get('GV_RootPath') . 'www/skins/icons/play.png"'
. ' ' . $this->escapeshellargs($tmpFile)
. ' ' . $this->escapeshellargs($dest);
$this->shell_cmd($cmd);
unlink($tmpFile);
rmdir($tmpDir);
return $this;
}
}