From f8c8935b4c7812a258c6ae2bdc97137cb1c4af6a Mon Sep 17 00:00:00 2001 From: Pierre Rudloff Date: Sat, 23 Dec 2017 15:14:43 +0100 Subject: [PATCH] Use ffmpeg instead of rtmpdump --- .appveyor.yml | 2 +- README.md | 4 +- classes/Config.php | 8 --- classes/VideoDownload.php | 111 ++++++++++++++++----------------- composer.json | 1 - composer.lock | 30 +-------- config/config.example.yml | 3 - config/config_test_windows.yml | 1 - resources/FAQ.md | 1 - tests/ConfigTest.php | 1 - tests/VideoDownloadTest.php | 17 ----- 11 files changed, 57 insertions(+), 122 deletions(-) diff --git a/.appveyor.yml b/.appveyor.yml index dbcdd30..5445fbd 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -2,7 +2,7 @@ install: - sc config wuauserv start= auto - net start wuauserv - - cinst php composer ffmpeg rtmpdump + - cinst php composer ffmpeg - refreshenv - copy C:\tools\php72\php.ini-development C:\tools\php72\php.ini - echo extension=C:\tools\php72\ext\php_gmp.dll >> C:\tools\php72\php.ini diff --git a/README.md b/README.md index 7b68aa3..1c9a929 100644 --- a/README.md +++ b/README.md @@ -130,14 +130,14 @@ server { ## Other dependencies -You need [avconv](https://libav.org/avconv.html) and [rtmpdump](http://rtmpdump.mplayerhq.hu/) +You need [avconv](https://libav.org/avconv.html) in order to enable conversions. If you don't want to enable conversions, you can disable it in `config.yml`. On Debian-based systems: ```bash -sudo apt-get install libav-tools rtmpdump +sudo apt-get install libav-tools ``` You also probably need to edit the `avconv` variable in `config.yml` diff --git a/classes/Config.php b/classes/Config.php index cc2abf3..e66a77d 100644 --- a/classes/Config.php +++ b/classes/Config.php @@ -54,13 +54,6 @@ class Config */ public $avconv = 'vendor/bin/ffmpeg'; - /** - * rtmpdump binary path. - * - * @var string - */ - public $rtmpdump = 'vendor/bin/rtmpdump'; - /** * Disable URL rewriting. * @@ -111,7 +104,6 @@ class Config * * youtubedl: youtube-dl binary path * * python: Python binary path * * avconv: avconv or ffmpeg binary path - * * rtmpdump: rtmpdump binary path * * params: Array of youtube-dl parameters * * convert: Enable conversion? * diff --git a/classes/VideoDownload.php b/classes/VideoDownload.php index 8be0d2c..d9b83a2 100644 --- a/classes/VideoDownload.php +++ b/classes/VideoDownload.php @@ -201,54 +201,32 @@ class VideoDownload * * @param object $video Video object returned by youtube-dl * - * @return array + * @return array Arguments */ - private function getRtmpProcessArguments(\stdClass $video) + private function getRtmpArguments(\stdClass $video) { - $arguments = [ - $this->config->rtmpdump, - '-q', - ]; foreach ([ - 'url' => 'rtmp', - 'webpage_url' => 'pageUrl', - 'player_url' => 'swfVfy', - 'flash_version' => 'flashVer', - 'play_path' => 'playpath', - 'app' => 'app', + 'url' => '-rtmp_tcurl', + 'webpage_url' => '-rtmp_pageurl', + 'player_url' => '-rtmp_swfverify', + 'flash_version' => '-rtmp_flashver', + 'play_path' => '-rtmp_playpath', + 'app' => '-rtmp_app', ] as $property => $option) { if (isset($video->{$property})) { - $arguments[] = '--'.$option; + $arguments[] = $option; $arguments[] = $video->{$property}; } } - return $arguments; - } - - /** - * Get a process that runs rtmp in order to download a video. - * - * @param object $video Video object returned by youtube-dl - * - * @throws \Exception If rtmpdump is missing - * - * @return \Symfony\Component\Process\Process Process - */ - private function getRtmpProcess(\stdClass $video) - { - if (!$this->checkCommand([$this->config->rtmpdump, '--help'])) { - throw(new \Exception('Can\'t find rtmpdump')); - } - $arguments = $this->getRtmpProcessArguments($video); if (isset($video->rtmp_conn)) { foreach ($video->rtmp_conn as $conn) { - $arguments[] = '--conn'; + $arguments[] = '-rtmp_conn'; $arguments[] = $conn; } } - return new Process($arguments); + return $arguments; } /** @@ -269,28 +247,39 @@ class VideoDownload /** * Get a process that runs avconv in order to convert a video to MP3. * - * @param string $url URL of the video file + * @param object $url Video object returned by youtube-dl * * @throws \Exception If avconv/ffmpeg is missing * * @return \Symfony\Component\Process\Process Process */ - private function getAvconvMp3Process($url) + private function getAvconvMp3Process(\stdClass $video) { if (!$this->checkCommand([$this->config->avconv, '-version'])) { throw(new \Exception('Can\'t find avconv or ffmpeg')); } - $arguments = [ - $this->config->avconv, - '-v', $this->config->avconvVerbosity, - '-i', $url, - '-f', 'mp3', - '-b:a', $this->config->audioBitrate.'k', - '-vn', - 'pipe:1', - ]; - if ($url != '-') { + if ($video->protocol == 'rtmp') { + $rtmpArguments = $this->getRtmpArguments($video); + } else { + $rtmpArguments = []; + } + + $arguments = array_merge( + [ + $this->config->avconv, + '-v', $this->config->avconvVerbosity, + ], + $rtmpArguments, + [ + '-i', $video->url, + '-f', 'mp3', + '-b:a', $this->config->audioBitrate.'k', + '-vn', + 'pipe:1', + ] + ); + if ($video->url != '-') { //Vimeo needs a correct user-agent $arguments[] = '-user_agent'; $arguments[] = $this->getProp(null, null, 'dump-user-agent'); @@ -318,17 +307,9 @@ class VideoDownload throw(new \Exception('Conversion of M3U8 files is not supported.')); } - if (parse_url($video->url, PHP_URL_SCHEME) == 'rtmp') { - $process = $this->getRtmpProcess($video); - $chain = new Chain($process); - $chain->pipe($this->getAvconvMp3Process('-')); + $avconvProc = $this->getAvconvMp3Process($video); - $stream = popen($chain->getProcess()->getCommandLine(), 'r'); - } else { - $avconvProc = $this->getAvconvMp3Process($video->url); - - $stream = popen($avconvProc->getCommandLine(), 'r'); - } + $stream = popen($avconvProc->getCommandLine(), 'r'); if (!is_resource($stream)) { throw new \Exception('Could not open popen stream.'); @@ -356,7 +337,7 @@ class VideoDownload $process = new Process( [ $this->config->avconv, - '-v', 'quiet', + '-v', $this->config->avconvVerbosity, '-i', $video->url, '-f', $video->ext, '-c', 'copy', @@ -388,7 +369,7 @@ class VideoDownload $process = new Process( [ $this->config->avconv, - '-v', 'quiet', + '-v', $this->config->avconvVerbosity, '-i', $urls[0], '-i', $urls[1], '-c', 'copy', @@ -418,7 +399,21 @@ class VideoDownload */ public function getRtmpStream(\stdClass $video) { - $stream = popen($this->getRtmpProcess($video)->getCommandLine(), 'r'); + $process = new Process( + array_merge( + [ + $this->config->avconv, + '-v', $this->config->avconvVerbosity, + ], + $this->getRtmpArguments($video), + [ + '-i', $video->url, + '-f', $video->ext, + 'pipe:1', + ] + ) + ); + $stream = popen($process->getCommandLine(), 'r'); if (!is_resource($stream)) { throw new \Exception('Could not open popen stream.'); } diff --git a/composer.json b/composer.json index 5164521..6ac079b 100644 --- a/composer.json +++ b/composer.json @@ -25,7 +25,6 @@ "doctrine/instantiator": "~1.0.0", "ffmpeg/ffmpeg": "dev-release", "rg3/youtube-dl": "2017.12.10", - "rudloff/rtmpdump-bin": "~2.3.0", "heroku/heroku-buildpack-php": "*" }, "extra": { diff --git a/composer.lock b/composer.lock index 2dac004..a413892 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "content-hash": "81616b497a5848eeb2aafb7b7dcfbed3", + "content-hash": "96a0790e383a8870104483939363bcc0", "packages": [ { "name": "aura/session", @@ -2162,34 +2162,6 @@ }, "type": "library" }, - { - "name": "rudloff/rtmpdump-bin", - "version": "2.3.1", - "source": { - "type": "git", - "url": "https://github.com/Rudloff/rtmpdump-bin.git", - "reference": "1042538e0a97940c6605c67c26ff48932ba5e61f" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/Rudloff/rtmpdump-bin/zipball/1042538e0a97940c6605c67c26ff48932ba5e61f", - "reference": "1042538e0a97940c6605c67c26ff48932ba5e61f", - "shasum": "" - }, - "require-dev": { - "rtmpdump/rtmpdump": "2.3" - }, - "bin": [ - "rtmpdump" - ], - "type": "library", - "notification-url": "https://packagist.org/downloads/", - "license": [ - "GPL-2.0" - ], - "description": "rtmpdump binary for Linux 64 bit", - "time": "2017-12-23T12:11:49+00:00" - }, { "name": "sebastian/code-unit-reverse-lookup", "version": "1.0.1", diff --git a/config/config.example.yml b/config/config.example.yml index 4b25bcd..25d0469 100644 --- a/config/config.example.yml +++ b/config/config.example.yml @@ -21,9 +21,6 @@ avconv: vendor/bin/ffmpeg # avconv/ffmpeg logging level. avconvVerbosity: error -# Path to your rtmpdump binary -rtmpdump: vendor/bin/rtmpdump - # True to disable URL rewriting uglyUrls: false diff --git a/config/config_test_windows.yml b/config/config_test_windows.yml index 78f24df..1098072 100644 --- a/config/config_test_windows.yml +++ b/config/config_test_windows.yml @@ -3,7 +3,6 @@ convert: false python: C:\Python36\python.exe avconv: C:\ProgramData\chocolatey\bin\ffmpeg.exe avconvVerbosity: fatal -rtmpdump: C:\ProgramData\chocolatey\bin\rtmpdump youtubedl: C:\Python36\Lib\site-packages\youtube_dl\__main__.py params: - --no-warnings diff --git a/resources/FAQ.md b/resources/FAQ.md index 3877d08..4aa3a35 100644 --- a/resources/FAQ.md +++ b/resources/FAQ.md @@ -18,7 +18,6 @@ Here are the parameters that you can set: * `params`: an array of parameters to pass to youtube-dl * `convert`: true to enable audio conversion * `avconv`: path to your avconv or ffmpeg binary -* `rtmpdump`: path to your rtmpdump binary * `remux`: enable remux mode (experimental) See [`config.example.yml`](../config/config.example.yml) for default values. diff --git a/tests/ConfigTest.php b/tests/ConfigTest.php index 5535109..b9223f6 100644 --- a/tests/ConfigTest.php +++ b/tests/ConfigTest.php @@ -62,7 +62,6 @@ class ConfigTest extends TestCase $this->assertInternalType('string', $config->youtubedl); $this->assertInternalType('string', $config->python); $this->assertInternalType('string', $config->avconv); - $this->assertInternalType('string', $config->rtmpdump); $this->assertInternalType('bool', $config->convert); $this->assertInternalType('bool', $config->uglyUrls); $this->assertInternalType('bool', $config->stream); diff --git a/tests/VideoDownloadTest.php b/tests/VideoDownloadTest.php index 436b41d..b4e6767 100644 --- a/tests/VideoDownloadTest.php +++ b/tests/VideoDownloadTest.php @@ -385,23 +385,6 @@ class VideoDownloadTest extends TestCase $download->getAudioStream($url, $format); } - /** - * Test getAudioStream function without curl or rtmpdump. - * - * @param string $url URL - * @param string $format Format - * - * @return void - * @expectedException Exception - * @dataProvider rtmpUrlProvider - */ - public function testGetAudioStreamRtmpError($url, $format) - { - $this->config->rtmpdump = 'foobar'; - $download = new VideoDownload($this->config); - $download->getAudioStream($url, $format); - } - /** * Test getAudioStream function with a M3U8 file. *