From 3a227ccafbd6bf98485216a4ed553e97ae8e5827 Mon Sep 17 00:00:00 2001 From: pascalbaljet Date: Wed, 7 Aug 2019 11:40:54 +0200 Subject: [PATCH 1/5] Copy remote file using 'stream_copy_to_stream' --- composer.json | 3 ++- src/FFMpeg.php | 6 +++++- tests/AudioVideoTest.php | 15 +++++---------- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/composer.json b/composer.json index 811c2e7..9743e0a 100644 --- a/composer.json +++ b/composer.json @@ -27,7 +27,8 @@ }, "require-dev": { "mockery/mockery": "^1.0", - "phpunit/phpunit": "7.5" + "phpunit/phpunit": "7.5", + "twistor/flysystem-http": "^0.2.0" }, "autoload": { "psr-4": { diff --git a/src/FFMpeg.php b/src/FFMpeg.php index 11148f5..59a3895 100644 --- a/src/FFMpeg.php +++ b/src/FFMpeg.php @@ -77,7 +77,11 @@ public function open($path): Media $ffmpegPathFile = $file->getFullPath(); } else { $ffmpegPathFile = static::newTemporaryFile(); - file_put_contents($ffmpegPathFile, $this->disk->read($path)); + + stream_copy_to_stream( + $this->disk->getDriver()->readStream($path), + fopen($ffmpegPathFile, 'w') + ); } $ffmpegMedia = $this->ffmpeg->open($ffmpegPathFile); diff --git a/tests/AudioVideoTest.php b/tests/AudioVideoTest.php index fd08b03..1124e74 100644 --- a/tests/AudioVideoTest.php +++ b/tests/AudioVideoTest.php @@ -25,6 +25,7 @@ use Pbmedia\LaravelFFMpeg\File; use Pbmedia\LaravelFFMpeg\Media; use Pbmedia\LaravelFFMpeg\MediaExporter; +use Twistor\Flysystem\Http\HttpAdapter; class AudioVideoTest extends TestCase { @@ -197,16 +198,10 @@ public function testOpeningFromRemoteDisk() $config = Mockery::mock(ConfigRepository::class); $logger = new Writer(new Logger('ffmpeg')); - $adapter = Mockery::mock(AdapterInterface::class); + $adapter = new HttpAdapter("https://raw.githubusercontent.com/pascalbaljetmedia/laravel-ffmpeg/master/tests/src/"); + $driver = new \League\Flysystem\Filesystem($adapter); - $driver = Mockery::mock(FilesystemInterface::class); - $driver->shouldReceive('getAdapter')->andReturn($adapter); - - $remoteDisk = Mockery::mock(FilesystemAdapter::class); - $remoteDisk->shouldReceive('getDriver')->andReturn($driver); - $remoteDisk->shouldReceive('read')->with('remote_guitar.m4a')->andReturn( - $videoContents = file_get_contents(__DIR__ . '/src/guitar.m4a') - ); + $remoteDisk = new FilesystemAdapter($driver); $localDisk = $this->getLocalAdapter(); @@ -217,7 +212,7 @@ public function testOpeningFromRemoteDisk() $config->shouldReceive('get')->once()->with('filesystems.default')->andReturn('s3'); $service = new FFMpeg($filesystems, $config, $logger); - $media = $service->open('remote_guitar.m4a'); + $media = $service->open('guitar.m4a'); $format = new \FFMpeg\Format\Audio\Aac; From bb04fa98e0de020b44199c68b66b4eca89b077cd Mon Sep 17 00:00:00 2001 From: pascalbaljet Date: Wed, 28 Aug 2019 00:40:44 +0200 Subject: [PATCH 2/5] Update .travis.yml --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 8d48350..d934df2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -17,7 +17,7 @@ before_install: install: - travis_retry composer update ${COMPOSER_FLAGS} --no-interaction - - sudo add-apt-repository -y ppa:mc3man/trusty-media + - sudo add-apt-repository -y ppa:mc3man/xerus-media - sudo apt-get -qq update - sudo apt-get install -y --allow-unauthenticated software-properties-common ffmpeg From 42d79f35f12f67ce4ead2c476d37e644745b2bc8 Mon Sep 17 00:00:00 2001 From: pascalbaljet Date: Wed, 28 Aug 2019 00:46:17 +0200 Subject: [PATCH 3/5] Update .travis.yml --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index d934df2..4fb3982 100644 --- a/.travis.yml +++ b/.travis.yml @@ -22,4 +22,4 @@ install: - sudo apt-get install -y --allow-unauthenticated software-properties-common ffmpeg script: - - phpunit + - ./vendor/bin/phpunit From ee999e012e3dc0fb938020b4cf6a712508b851be Mon Sep 17 00:00:00 2001 From: pascalbaljet Date: Wed, 28 Aug 2019 00:48:14 +0200 Subject: [PATCH 4/5] Update .travis.yml --- .travis.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 4fb3982..bc13fc5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,9 +1,9 @@ language: php php: - - 7.1 - - 7.2 - - 7.3 + - '7.1' + - '7.2' + - '7.3' env: matrix: From 9916167a804cfb20fa79ef814299d14aa1c95c47 Mon Sep 17 00:00:00 2001 From: pascalbaljet Date: Wed, 28 Aug 2019 00:50:00 +0200 Subject: [PATCH 5/5] Update Disk.php --- src/Disk.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Disk.php b/src/Disk.php index 3f94cfe..bb93393 100644 --- a/src/Disk.php +++ b/src/Disk.php @@ -6,6 +6,7 @@ use League\Flysystem\Adapter\Local as LocalAdapater; /** + * @method \League\Flysystem\FilesystemInterface getDriver() * @method bool put($path, $contents, $visibility = null) * @method array|false read($path) * @method void setVisibility($path, $visibility)