Use ffmpeg instead of rtmpdump

This commit is contained in:
Pierre Rudloff 2017-12-23 15:14:43 +01:00
parent 7940446af3
commit f8c8935b4c
11 changed files with 57 additions and 122 deletions

View file

@ -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

View file

@ -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`

View file

@ -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?
*

View file

@ -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.');
}

View file

@ -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": {

30
composer.lock generated
View file

@ -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",

View file

@ -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

View file

@ -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

View file

@ -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.

View file

@ -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);

View file

@ -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.
*