Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

trigerring youtube-dl by PHP exec() works but with some issues #7278

Closed
adrianTNT opened this issue Oct 23, 2015 · 9 comments
Closed

trigerring youtube-dl by PHP exec() works but with some issues #7278

adrianTNT opened this issue Oct 23, 2015 · 9 comments

Comments

@adrianTNT
Copy link

@adrianTNT adrianTNT commented Oct 23, 2015

I tried to trigger the youtube-dl from browser with this PHP code

exec('youtube-dl https://www.youtube.com/watch?v=sVG-IFSjWJA --extract-audio --audio-format mp3 --id --embed-thumbnail', $output);

It seems to work for the most part, but the output file for that command is an m4a file and no mp3 file.
Full output is this:

[0] => [youtube] sVG-IFSjWJA: Downloading webpage
[1] => [youtube] sVG-IFSjWJA: Downloading video info webpage
[2] => [youtube] sVG-IFSjWJA: Extracting video information
[3] => [youtube] sVG-IFSjWJA: Downloading DASH manifest
[4] => [youtube] sVG-IFSjWJA: Downloading thumbnail ...
[5] => [youtube] sVG-IFSjWJA: Writing thumbnail to: sVG-IFSjWJA.jpg
[6] => [download] Destination: sVG-IFSjWJA.m4a
[7] => 
[download]   0.0% of 4.23MiB at 213.41KiB/s ETA 00:20
...
[download] 100% of 4.23MiB in 00:00

And from ssh I trieggered same command and it generated an mp3 file:

youtube-dl https://www.youtube.com/watch?v=sVG-IFSjWJA --extract-audio --audio-format mp3 --id --embed-thumbnail
[youtube] sVG-IFSjWJA: Downloading webpage
[youtube] sVG-IFSjWJA: Downloading video info webpage
[youtube] sVG-IFSjWJA: Extracting video information
[youtube] sVG-IFSjWJA: Downloading DASH manifest
[youtube] sVG-IFSjWJA: Downloading thumbnail ...
[youtube] sVG-IFSjWJA: Writing thumbnail to: sVG-IFSjWJA.jpg
[download] Destination: sVG-IFSjWJA.m4a
[download] 100% of 4.23MiB in 00:00
[ffmpeg] Correcting container in "sVG-IFSjWJA.m4a"
[ffmpeg] Destination: sVG-IFSjWJA.mp3
Deleting original file sVG-IFSjWJA.m4a (pass -k to keep)
[ffmpeg] Adding thumbnail to "sVG-IFSjWJA.mp3"

I notice now that from ssh output contains [ffmpeg] lines that are not present in PHP output, so I tried this in PHP code:

--ffmpeg-location /root/bin/ffmpeg

But output was the same, .m4a but no .mp3 file.

@jaimeMF
Copy link
Collaborator

@jaimeMF jaimeMF commented Oct 23, 2015

Make sure you are redirecting stderr and post its output. Additionally as explained in the bug reporting instructions, you must use the --verbose option so that we get the required information.

@adrianTNT
Copy link
Author

@adrianTNT adrianTNT commented Oct 23, 2015

I added --verbose and 2>&1 at the end of exec() command, this is when also using --prefer-ffmpeg --ffmpeg-location /root/bin/ffmpeg, and this is the output, I can see this interesting one, but the file IS there, it is 24 MB:

[35] => WARNING: ffmpeg-location /root/bin/ffmpeg does not exist! Continuing without avconv/ffmpeg.

Full output:

[0] => [debug] System config: []
[1] => [debug] User config: []
[2] => [debug] Command-line args: [u'--verbose', u'https://www.youtube.com/watch?v=sVG-IFSjWJA', u'--prefer-ffmpeg', u'--ffmpeg-location', u'/root/bin/ffmpeg', u'--extract-audio', u'--audio-format', u'mp3', u'--id', u'--embed-thumbnail']
[3] => [debug] Encodings: locale ANSI_X3.4-1968, fs ANSI_X3.4-1968, out None, pref ANSI_X3.4-1968
[4] => [debug] youtube-dl version 2015.10.18
[5] => [debug] Python version 2.6.6 - Linux-2.6.32-358.18.1.el6.x86_64-x86_64-with-centos-6.4-Final
[6] => WARNING: ffmpeg-location /root/bin/ffmpeg does not exist! Continuing without avconv/ffmpeg.
[7] => [debug] exe versions: none
[8] => [debug] Proxy map: {}
[9] => WARNING: ffmpeg-location /root/bin/ffmpeg does not exist! Continuing without avconv/ffmpeg.
[10] => WARNING: ffmpeg-location /root/bin/ffmpeg does not exist! Continuing without avconv/ffmpeg.
[11] => [youtube] sVG-IFSjWJA: Downloading webpage
[12] => [youtube] sVG-IFSjWJA: Downloading video info webpage
[13] => [youtube] sVG-IFSjWJA: Extracting video information
[14] => [youtube] {43} signature length 42.40, html5 player new-en_US-vflmR8A04
[15] => [youtube] {18} signature length 42.40, html5 player new-en_US-vflmR8A04
[16] => [youtube] {5} signature length 42.40, html5 player new-en_US-vflmR8A04
[17] => [youtube] {36} signature length 42.40, html5 player new-en_US-vflmR8A04
[18] => [youtube] {17} signature length 42.40, html5 player new-en_US-vflmR8A04
[19] => [youtube] {135} signature length 42.40, html5 player new-en_US-vflmR8A04
[20] => [youtube] {244} signature length 42.40, html5 player new-en_US-vflmR8A04
[21] => [youtube] {134} signature length 42.40, html5 player new-en_US-vflmR8A04
[22] => [youtube] {243} signature length 42.40, html5 player new-en_US-vflmR8A04
[23] => [youtube] {133} signature length 42.40, html5 player new-en_US-vflmR8A04
[24] => [youtube] {242} signature length 42.40, html5 player new-en_US-vflmR8A04
[25] => [youtube] {160} signature length 42.40, html5 player new-en_US-vflmR8A04
[26] => [youtube] {278} signature length 42.40, html5 player new-en_US-vflmR8A04
[27] => [youtube] {140} signature length 42.40, html5 player new-en_US-vflmR8A04
[28] => [youtube] {171} signature length 42.40, html5 player new-en_US-vflmR8A04
[29] => [youtube] sVG-IFSjWJA: Downloading DASH manifest
[30] => [youtube] sVG-IFSjWJA: Downloading thumbnail ...
[31] => [youtube] sVG-IFSjWJA: Writing thumbnail to: sVG-IFSjWJA.jpg
[32] => [debug] Invoking downloader on 'https://r1---sn-4g57knk7.googlevideo.com/videoplayback?id=b151be2054a35890&itag=141&source=youtube&requiressl=yes&nh=IgpwcjAyLmZyYTE1KgkxMjcuMC4wLjE&ms=au&mn=sn-4g57knk7&mm=31&mv=m&pl=43&ratebypass=yes&mime=audio/mp4&gir=yes&clen=4434282&lmt=1392542714095340&dur=139.064&itag_bl=298,299,302,303,308,315&key=dg_yt0&fexp=9407002,9408710,9413123,9414764,9415863,9416126,9416729,9417707,9418019,9418204,9419802,9421254,9421711,9422287,9423431&sver=3&upn=HhK6W6uZNJw&signature=8220013227721FE6FE21071F74A5B4203528A62F.3F197C3E40F576C582F35359A677DD1E1CC12AD6&mt=1445603511&ip=2a01:4f8:151:10c7::2&ipbits=0&expire=1445625217&sparams=ip,ipbits,expire,id,itag,source,requiressl,nh,ms,mn,mm,mv,pl,ratebypass,mime,gir,clen,lmt,dur'
[33] => [download] sVG-IFSjWJA.m4a has already been downloaded
[34] => [download] 100% of 4.23MiB
[35] => WARNING: ffmpeg-location /root/bin/ffmpeg does not exist! Continuing without avconv/ffmpeg.
[36] => WARNING: sVG-IFSjWJA: writing DASH m4a. Only some players support this container. Install ffmpeg or avconv to fix this automatically.
[37] => ERROR: ffprobe or avprobe not found. Please install one.
[38] => Traceback (most recent call last):
[39] =>   File "/usr/local/bin/youtube-dl/youtube_dl/YoutubeDL.py", line 1712, in post_process
[40] =>     files_to_delete, info = pp.run(info)
[41] =>   File "/usr/local/bin/youtube-dl/youtube_dl/postprocessor/ffmpeg.py", line 215, in run
[42] =>     filecodec = self.get_audio_codec(path)
[43] =>   File "/usr/local/bin/youtube-dl/youtube_dl/postprocessor/ffmpeg.py", line 179, in get_audio_codec
[44] =>     raise PostProcessingError('ffprobe or avprobe not found. Please install one.')
[45] => PostProcessingError
@adrianTNT
Copy link
Author

@adrianTNT adrianTNT commented Oct 23, 2015

The above was when I forced the path to ffmpeg in the command, without it, output is like this:

[30] => [download] sVG-IFSjWJA.m4a has already been downloaded
[31] => [download] 100% of 4.23MiB
[32] => WARNING: sVG-IFSjWJA: writing DASH m4a. Only some players support this container. Install ffmpeg or avconv to fix this automatically.
[33] => ERROR: ffprobe or avprobe not found. Please install one.
[34] => Traceback (most recent call last):
[35] =>   File "/usr/local/bin/youtube-dl/youtube_dl/YoutubeDL.py", line 1712, in post_process
[36] =>     files_to_delete, info = pp.run(info)
[37] =>   File "/usr/local/bin/youtube-dl/youtube_dl/postprocessor/ffmpeg.py", line 215, in run
[38] =>     filecodec = self.get_audio_codec(path)
[39] =>   File "/usr/local/bin/youtube-dl/youtube_dl/postprocessor/ffmpeg.py", line 179, in get_audio_codec
[40] =>     raise PostProcessingError('ffprobe or avprobe not found. Please install one.')
[41] => PostProcessingError
@jaimeMF
Copy link
Collaborator

@jaimeMF jaimeMF commented Oct 23, 2015

Can you run ffmpeg or /root/bin/ffmpeg (for example with -version) from PHP?

@adrianTNT
Copy link
Author

@adrianTNT adrianTNT commented Oct 23, 2015

With both ffmpeg or /root/bin/ffmpeg I see result is the same, I did have an older version installed before I compiled this from Git

/root/bin/ffmpeg -version
ffmpeg version git-2015-10-21-1ec8c15 Copyright (c) 2000-2015 the FFmpeg developers
built with gcc 4.4.7 (GCC) 20120313 (Red Hat 4.4.7-16)
configuration: --prefix=/root/ffmpeg_build --extra-cflags=-I/root/ffmpeg_build/include --extra-ldflags=-L/root/ffmpeg_build/lib --bindir=/root/bin --pkg-config-flags=--static --enable-gpl --enable-nonfree --enable-libfdk-aac --enable-libfreetype --enable-libmp3lame --enable-libvorbis --enable-libx264 --enable-libx265
libavutil      55.  4.100 / 55.  4.100
libavcodec     57.  7.100 / 57.  7.100
libavformat    57. 10.100 / 57. 10.100
libavdevice    57.  0.100 / 57.  0.100
libavfilter     6. 12.100 /  6. 12.100
libswscale      4.  0.100 /  4.  0.100
libswresample   2.  0.100 /  2.  0.100
libpostproc    54.  0.100 / 54.  0.100
@jaimeMF
Copy link
Collaborator

@jaimeMF jaimeMF commented Oct 23, 2015

As I said, can you run them from PHP (using exec)?

@adrianTNT
Copy link
Author

@adrianTNT adrianTNT commented Oct 23, 2015

Sorry, I missed the php part. I tested now,

exec("/root/bin/ffmpeg -version 2>&1", $output);

says

Array ( [0] => sh: /root/bin/ffmpeg: Permission denied )

And without full path it says command not found.
Any tips ?

@adrianTNT
Copy link
Author

@adrianTNT adrianTNT commented Oct 23, 2015

After many tests, I was only able to make it work after I copied ffmpeg and ffprobe from /root/bin to /usr/local/bin without changing any permissions or owners, the two files still belong to root:root.

Strange that now it works even without specifying --ffmpeg-location in my PHP exec() function. Maybe youtube-dl has some commands that don't even use original path from /root/bin/ffmpeg but instead just triggered ffmpeg and failed (from PHP) ? I don't fully understand this.

@yan12125
Copy link
Collaborator

@yan12125 yan12125 commented Oct 23, 2015

I'm not sure what's the cause. Here's my guess: usually the HTTP server is run under unprivileged user http or www. It's possible that they don't have permissions to access /root.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.