Change threads settings
This commit is contained in:
parent
cac8831db2
commit
1ced99fd9a
1 changed files with 26 additions and 14 deletions
|
|
@ -32,6 +32,7 @@ class FFMpeg extends Binary
|
||||||
* @var FFProbe
|
* @var FFProbe
|
||||||
*/
|
*/
|
||||||
protected $prober;
|
protected $prober;
|
||||||
|
protected $threads = 1;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Destructor
|
* Destructor
|
||||||
|
|
@ -42,6 +43,22 @@ class FFMpeg extends Binary
|
||||||
parent::__destruct();
|
parent::__destruct();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function setThreads($threads)
|
||||||
|
{
|
||||||
|
if ($threads > 64 || $threads < 1) {
|
||||||
|
throw new InvalidArgumentException('Invalid `threads` value ; threads must fit in range 1 - 64');
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->threads = (int) $threads;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getThreads()
|
||||||
|
{
|
||||||
|
return $this->threads;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Opens a file in order to be processed
|
* Opens a file in order to be processed
|
||||||
*
|
*
|
||||||
|
|
@ -117,7 +134,7 @@ class FFMpeg extends Binary
|
||||||
try {
|
try {
|
||||||
$process->run();
|
$process->run();
|
||||||
} catch (\RuntimeException $e) {
|
} catch (\RuntimeException $e) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( ! $process->isSuccessful()) {
|
if ( ! $process->isSuccessful()) {
|
||||||
|
|
@ -138,26 +155,23 @@ class FFMpeg extends Binary
|
||||||
*
|
*
|
||||||
* @param Audio $format The output format
|
* @param Audio $format The output format
|
||||||
* @param string $outputPathfile The pathfile where to write
|
* @param string $outputPathfile The pathfile where to write
|
||||||
* @param integer $threads The number of threads to use
|
|
||||||
* @return \FFMpeg\FFMpeg
|
* @return \FFMpeg\FFMpeg
|
||||||
* @throws RuntimeException
|
* @throws RuntimeException
|
||||||
* @throws LogicException
|
* @throws LogicException
|
||||||
*/
|
*/
|
||||||
public function encode(Audio $format, $outputPathfile, $threads = 1)
|
public function encode(Audio $format, $outputPathfile)
|
||||||
{
|
{
|
||||||
if ( ! $this->pathfile) {
|
if ( ! $this->pathfile) {
|
||||||
throw new LogicException('No file open');
|
throw new LogicException('No file open');
|
||||||
}
|
}
|
||||||
|
|
||||||
$threads = max(min($threads, 64), 1);
|
|
||||||
|
|
||||||
switch (true) {
|
switch (true) {
|
||||||
case $format instanceof Video:
|
case $format instanceof Video:
|
||||||
$this->encodeVideo($format, $outputPathfile, $threads);
|
$this->encodeVideo($format, $outputPathfile);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
case $format instanceof Audio:
|
case $format instanceof Audio:
|
||||||
$this->encodeAudio($format, $outputPathfile, $threads);
|
$this->encodeAudio($format, $outputPathfile);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -169,17 +183,16 @@ class FFMpeg extends Binary
|
||||||
*
|
*
|
||||||
* @param Audio $format The output format
|
* @param Audio $format The output format
|
||||||
* @param string $outputPathfile The pathfile where to write
|
* @param string $outputPathfile The pathfile where to write
|
||||||
* @param integer $threads The number of threads to use
|
|
||||||
* @return \FFMpeg\FFMpeg
|
* @return \FFMpeg\FFMpeg
|
||||||
* @throws RuntimeException
|
* @throws RuntimeException
|
||||||
*/
|
*/
|
||||||
protected function encodeAudio(Audio $format, $outputPathfile, $threads)
|
protected function encodeAudio(Audio $format, $outputPathfile)
|
||||||
{
|
{
|
||||||
$cmd = $this->binary
|
$cmd = $this->binary
|
||||||
. ' -y -i '
|
. ' -y -i '
|
||||||
. escapeshellarg($this->pathfile)
|
. escapeshellarg($this->pathfile)
|
||||||
. ' ' . $format->getExtraParams()
|
. ' ' . $format->getExtraParams()
|
||||||
. ' -threads ' . $threads
|
. ' -threads ' . $this->threads
|
||||||
. ' -ab ' . $format->getKiloBitrate() . 'k '
|
. ' -ab ' . $format->getKiloBitrate() . 'k '
|
||||||
. ' ' . escapeshellarg($outputPathfile);
|
. ' ' . escapeshellarg($outputPathfile);
|
||||||
|
|
||||||
|
|
@ -198,7 +211,7 @@ class FFMpeg extends Binary
|
||||||
try {
|
try {
|
||||||
$process->run();
|
$process->run();
|
||||||
} catch (\RuntimeException $e) {
|
} catch (\RuntimeException $e) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( ! $process->isSuccessful()) {
|
if ( ! $process->isSuccessful()) {
|
||||||
|
|
@ -216,11 +229,10 @@ class FFMpeg extends Binary
|
||||||
*
|
*
|
||||||
* @param Video $format The output format
|
* @param Video $format The output format
|
||||||
* @param string $outputPathfile The pathfile where to write
|
* @param string $outputPathfile The pathfile where to write
|
||||||
* @param integer $threads The number of threads to use
|
|
||||||
* @return \FFMpeg\FFMpeg
|
* @return \FFMpeg\FFMpeg
|
||||||
* @throws RuntimeException
|
* @throws RuntimeException
|
||||||
*/
|
*/
|
||||||
protected function encodeVideo(Video $format, $outputPathfile, $threads)
|
protected function encodeVideo(Video $format, $outputPathfile)
|
||||||
{
|
{
|
||||||
$cmd_part1 = $this->binary
|
$cmd_part1 = $this->binary
|
||||||
. ' -y -i '
|
. ' -y -i '
|
||||||
|
|
@ -283,7 +295,7 @@ class FFMpeg extends Binary
|
||||||
}
|
}
|
||||||
|
|
||||||
$cmd_part2 .= ' -b ' . $format->getKiloBitrate() . 'k'
|
$cmd_part2 .= ' -b ' . $format->getKiloBitrate() . 'k'
|
||||||
. ' -threads ' . $threads
|
. ' -threads ' . $this->threads
|
||||||
. ' -refs 6 -coder 1 -qmin 10 -qmax 51 '
|
. ' -refs 6 -coder 1 -qmin 10 -qmax 51 '
|
||||||
. ' -sc_threshold 40 -flags +loop -cmp +chroma'
|
. ' -sc_threshold 40 -flags +loop -cmp +chroma'
|
||||||
. ' -me_range 16 -subq 7 -i_qfactor 0.71 -qcomp 0.6 -qdiff 4 '
|
. ' -me_range 16 -subq 7 -i_qfactor 0.71 -qcomp 0.6 -qdiff 4 '
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue