From 23bffdfd5fbf75cba0eb39d412ce7b1f2dd9d758 Mon Sep 17 00:00:00 2001 From: Romain Neutron Date: Thu, 7 Feb 2013 12:40:11 +0100 Subject: [PATCH 1/2] Enhance options for better output --- src/FFMpeg/FFMpeg.php | 19 +++++++++++-------- tests/src/FFMpeg/FFMpegTest.php | 2 +- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/FFMpeg/FFMpeg.php b/src/FFMpeg/FFMpeg.php index 0e9159d..df5ac9a 100644 --- a/src/FFMpeg/FFMpeg.php +++ b/src/FFMpeg/FFMpeg.php @@ -361,16 +361,19 @@ class FFMpeg extends Binary $builder->add('-vcodec')->add($format->getVideoCodec()); } - $builder->add('-b')->add($format->getKiloBitrate() . 'k') + $builder->add('-b:v')->add($format->getKiloBitrate() . 'k') ->add('-threads')->add($this->threads) - ->add('-refs')->add('6')->add('-coder')->add('1')->add('-qmin') - ->add('10')->add('-qmax')->add('51') - ->add('-sc_threshold')->add('40')->add('-flags')->add('+loop') - ->add('-me_range')->add('16')->add('-subq')->add('7') - ->add('-i_qfactor')->add('0.71')->add('-qcomp')->add('0.6') + ->add('-refs')->add('6') + ->add('-coder')->add('1') + ->add('-sc_threshold')->add('40') + ->add('-flags')->add('+loop') + ->add('-me_range')->add('16') + ->add('-subq')->add('7') + ->add('-i_qfactor')->add('0.71') + ->add('-qcomp')->add('0.6') ->add('-qdiff')->add('4') - ->add('-trellis')->add('1')->add('-qscale')->add('1') - ->add('-ab')->add('92k'); + ->add('-trellis')->add('1') + ->add('-b:a')->add('92k'); if ($format instanceof AudioTranscodable) { $builder->add('-acodec')->add($format->getAudioCodec()); diff --git a/tests/src/FFMpeg/FFMpegTest.php b/tests/src/FFMpeg/FFMpegTest.php index 477f773..1597e5f 100644 --- a/tests/src/FFMpeg/FFMpegTest.php +++ b/tests/src/FFMpeg/FFMpegTest.php @@ -203,7 +203,7 @@ class FFMpegTest extends \PHPUnit_Framework_TestCase $format = new Format\Video\X264(); $format-> setDimensions(32, 32); - $this->object->open(__DIR__ . '/../../files/Test.ogv'); + $this->object->open(__DIR__ . '/../../files/EmpireStateofMind-Jay-Z.mov'); $this->object->encode($format, $dest); $this->probe->probeFormat($dest); From 50dbd23ad527dd61522ac2afb3f2a3b53f1823cd Mon Sep 17 00:00:00 2001 From: Romain Neutron Date: Thu, 7 Feb 2013 13:01:56 +0100 Subject: [PATCH 2/2] Fix #20 : Use a distinct stat file foreach encoding --- src/FFMpeg/FFMpeg.php | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/FFMpeg/FFMpeg.php b/src/FFMpeg/FFMpeg.php index df5ac9a..9caeff3 100644 --- a/src/FFMpeg/FFMpeg.php +++ b/src/FFMpeg/FFMpeg.php @@ -379,16 +379,20 @@ class FFMpeg extends Binary $builder->add('-acodec')->add($format->getAudioCodec()); } - $tmpFile = new \SplFileInfo(tempnam(sys_get_temp_dir(), 'temp') . '.' . pathinfo($outputPathfile, PATHINFO_EXTENSION)); - + $passPrefix = uniqid('pass-'); + $pass1 = $builder; $pass2 = clone $builder; $passes[] = $pass1 - ->add('-pass')->add('1')->add('-an')->add($tmpFile->getPathname()) + ->add('-pass')->add('1') + ->add('-passlogfile')->add($passPrefix) + ->add('-an')->add($outputPathfile) ->getProcess(); $passes[] = $pass2 - ->add('-pass')->add('2')->add('-ac')->add('2') + ->add('-pass')->add('2') + ->add('-passlogfile')->add($passPrefix) + ->add('-ac')->add('2') ->add('-ar')->add('44100')->add($outputPathfile) ->getProcess(); @@ -403,10 +407,9 @@ class FFMpeg extends Binary } } - $this->cleanupTemporaryFile($tmpFile->getPathname()); - $this->cleanupTemporaryFile(getcwd() . '/ffmpeg2pass-0.log'); - $this->cleanupTemporaryFile(getcwd() . '/av2pass-0.log'); - $this->cleanupTemporaryFile(getcwd() . '/ffmpeg2pass-0.log.mbtree'); + $this->cleanupTemporaryFile(getcwd() . '/' . $passPrefix . '-0.log'); + $this->cleanupTemporaryFile(getcwd() . '/' . $passPrefix . '-0.log'); + $this->cleanupTemporaryFile(getcwd() . '/' . $passPrefix . '-0.log.mbtree'); if (!$process->isSuccessful()) { $this->logger->addInfo(sprintf('FFmpeg command failed'));