pi_lover
Posts: 75
Joined: Fri Apr 28, 2017 4:00 am

How to stream Youtube videos using youtube-dl and omxplayer ?

Sat Apr 21, 2018 6:09 am

How to stream Youtube videos using youtube-dl and omxplayer ?

In the past I found a one line command that worked fine but now

cant find it anymore.


mikerr
Posts: 2800
Joined: Thu Jan 12, 2012 12:46 pm
Location: UK
Contact: Website

Re: How to stream Youtube videos using youtube-dl and omxplayer ?

Sat Apr 21, 2018 7:47 am

This should work:

Code: Select all

omxplayer `youtube-dl -g <youtube-url>`
Android app - Raspi Card Imager - download and image SD cards - No PC required !

gkreidl
Posts: 6168
Joined: Thu Jan 26, 2012 1:07 pm
Location: Germany

Re: How to stream Youtube videos using youtube-dl and omxplayer ?

Sat Apr 21, 2018 7:49 am

pi_lover wrote:
Sat Apr 21, 2018 6:09 am
How to stream Youtube videos using youtube-dl and omxplayer ?

In the past I found a one line command that worked fine but now

cant find it anymore.
You need youtube-dl:
sudo pip install youtube-dl

A one liner (though not very comfortable) might look like this:
omxplayer $(youtube-dl -g -f best https://www.youtube.com/watch?v=74pX6-3u7uE)
Minimal Kiosk Browser (kweb)
Slim, fast webkit browser with support for audio+video+playlists+youtube+pdf+download
Optional fullscreen kiosk mode and command interface for embedded applications
Includes omxplayerGUI, an X front end for omxplayer

gkreidl
Posts: 6168
Joined: Thu Jan 26, 2012 1:07 pm
Location: Germany

Re: How to stream Youtube videos using youtube-dl and omxplayer ?

Sat Apr 21, 2018 7:51 am

mikerr wrote:
Sat Apr 21, 2018 7:47 am
This should work:

Code: Select all

omxplayer `youtube-dl -g <youtube-url>`
You have to use the "-f best" option. Otherwise you will get audio and video as separate streams.
Minimal Kiosk Browser (kweb)
Slim, fast webkit browser with support for audio+video+playlists+youtube+pdf+download
Optional fullscreen kiosk mode and command interface for embedded applications
Includes omxplayerGUI, an X front end for omxplayer

pi_lover
Posts: 75
Joined: Fri Apr 28, 2017 4:00 am

Re: How to stream Youtube videos using youtube-dl and omxplayer ?

Sat Apr 21, 2018 7:54 am

$ omxplayer youtube-dl -g https://www.youtube.com/watch?v=rqA7b4ba29o
File "youtube-dl" not found.

pi_lover
Posts: 75
Joined: Fri Apr 28, 2017 4:00 am

Re: How to stream Youtube videos using youtube-dl and omxplayer ?

Sat Apr 21, 2018 8:02 am

@gkreidl

The following worked
$ omxplayer $(youtube-dl -g -f best https://www.youtube.com/watch?v=rqA7b4ba29o)


But it takes a long time to start the video.

I have downloaded youtube-dl directly from github.

n67
Posts: 938
Joined: Mon Oct 30, 2017 4:55 pm

Re: How to stream Youtube videos using youtube-dl and omxplayer ?

Sat Apr 21, 2018 8:11 am

You obviously don't HAVE to use "-f best", since I never do and it works fine.

I always use "-f mp4", because if I don't, I find that things often don't work as expected (sometimes the problem isn't immediately obvious, but it presents somewhere down the line).

But it does, of course, work reasonably OK without any "-f" option at all.
"L'enfer, c'est les autres"

G fytc hsqr rum umpbq rm qyw rm rfc kmbq md rfgq dmpsk:

Epmu Sn!

J lnacjrw njbruh-carppnanm vxm rb mnuncrwp vh yxbcb!

gkreidl
Posts: 6168
Joined: Thu Jan 26, 2012 1:07 pm
Location: Germany

Re: How to stream Youtube videos using youtube-dl and omxplayer ?

Sat Apr 21, 2018 8:13 am

pi_lover wrote:
Sat Apr 21, 2018 8:02 am
@gkreidl

The following worked
$ omxplayer $(youtube-dl -g -f best https://www.youtube.com/watch?v=rqA7b4ba29o)


But it takes a long time to start the video.

I have downloaded youtube-dl directly from github.
This is very slow. Using the pip installation it will take about half the time.
It would be much faster, if you would use omxplayerGUI and its embedded youtube-dl server, but if I remember correctly, you don't want to install software which does not come from the official repositories.
For a speed comparison of all methods look at the bottom of this post: viewtopic.php?f=66&t=208595#p1289651
Minimal Kiosk Browser (kweb)
Slim, fast webkit browser with support for audio+video+playlists+youtube+pdf+download
Optional fullscreen kiosk mode and command interface for embedded applications
Includes omxplayerGUI, an X front end for omxplayer

User avatar
TheComputerWizard
Posts: 6
Joined: Wed Sep 18, 2019 4:03 am
Location: Atlanta, Georgia
Contact: Website YouTube

Re: How to stream Youtube videos using youtube-dl and omxplayer ?

Fri Sep 20, 2019 9:18 pm

Youtube-dl has changed once again. Best only appears to be a teaser. Only shows 1 minute of video for me. Try next best, which consistently seems to be 18, for now. All other formats appear to be audio only or video only. Next best is a lower resolution, but does the job. Plays all but last 15 seconds of the video in a lower resolution 640x360. Here is the script to play it in a window.

Code: Select all

#!/bin/bash
omxplayer -o hdmi --win "40 40 640 360" $(youtube-dl -g -f $2 $1)
Use text editor to save it as ytplaywin in your default terminal directory, pi. Use chmod 755 ytplaywin to make it executable. To run it type.

./ytplaywin URL Format

WIth URL being the Youtube url address of the video, and Format being 18, or best, for just the 1st minute. Following code does same thing, but full screen. I call it ytplayfs, fs for full screen.

Code: Select all

#!/bin/bash
omxplayer -o hdmi $(youtube-dl -g -f $2 $1)
You can use the following keyboard commands to control playback. If playing in a window, just make sure you have terminal text window you used to launch the play selected for these keys to work.

Space or p Pause/Resume
q Exit OMXPlayer
z Show Info

- Decrease Volume
+ Increase Volume

i Previous Chapter
o Next Chapter

Left Arrow Seek -30
Right Arrow Seek +30
Down Arrow Seek -600
Up Arrow Seek +600

1 Increase Speed
2 Decrease Speed

j Previous Audio stream
k Next Audio stream
n Previous Subtitle stream
m Next Subtitle stream
s Toggle subtitles
d Subtitle delay -250 ms
f Subtitle delay +250 ms

User avatar
TheComputerWizard
Posts: 6
Joined: Wed Sep 18, 2019 4:03 am
Location: Atlanta, Georgia
Contact: Website YouTube

Re: How to stream Youtube videos using youtube-dl and omxplayer ?

Fri Sep 20, 2019 9:40 pm

If you are so inclined, you can do the same thing with the VLC media player to stream the video to a window with visible controls that can be resized. Unfortunately, this does not appear to fix the stuttering problem I have observed with streaming media on the pi, which appears everywhere, not just with YT, but with Pluto.TV, and everywhere else, but not Kodi.

Code: Select all

#!/bin/bash
youtube-dl -f $2 -o - "$1" | vlc -
I call this one ytplayvlc. Uses the same parameters as the above post, where the first argument is the URL, and the second is the format.

Maybe by observing the results and the errors reported back to the terminal by VLC the developers can remedy this stutter in Rasbian Buster. Following is a log of these results for a video I played with this method, which did not want to finish playing.
  • pi@raspberrypi:~ $ ./ytplayvlc https://www.youtube.com/watch?v=kHPO1iek4BA 18
    VLC media player 3.0.8 Vetinari (revision 3.0.8-0-gf350b6b5a7)
    [00354b58] main libvlc: Running vlc with the default interface. Use 'cvlc' to use vlc without interface.
    qt5ct: using qt5ct plugin
    qt5ct: D-Bus global menu: no
    qt5ct: D-Bus system tray: no
    [youtube] kHPO1iek4BA: Downloading webpage
    [youtube] kHPO1iek4BA: Downloading video info webpage
    WARNING: Unable to extract video title
    [download] Destination: -
    [download] 4.5% of 44.63MiB at 2.80MiB/s ETA 00:15[9a63baf0] mmal_codec decoder: VCSM init succeeded: CMA
    [9a63baf0] main decoder error: buffer deadlock prevented
    [9525c5b8] main decoder error: buffer deadlock prevented
    [download] 81.6% of 44.63MiB at 37.35KiB/s ETA 03:45[download] Got server HTTP error: [Errno 104] Connection reset by peer. Retrying (attempt 1 of 10)...
    [download] Destination: -
    [download] 90.1% of 44.63MiB at 13.62KiB/s ETA 05:31[9a900668] main input error: ES_OUT_SET_(GROUP_)PCR is called too late (pts_delay increased to 300 ms)
    [download] 90.1% of 44.63MiB at 13.64KiB/s ETA 05:30[9a63baf0] main decoder error: buffer deadlock prevented
    [download] 90.2% of 44.63MiB at 13.44KiB/s ETA 05:33[9a900668] main input error: ES_OUT_SET_(GROUP_)PCR is called too late (pts_delay increased to 4847 ms)
    [download] 91.0% of 44.63MiB at 11.82KiB/s ETA 05:48[9a600eb8] prefetch stream error: reading while paused (buggy demux?)
    [download] 91.7% of 44.63MiB at 11.32KiB/s ETA 05:34[9a900668] main input error: ES_OUT_SET_(GROUP_)PCR is called too late (jitter of 71000 ms ignored)
    [download] 91.9% of 44.63MiB at 11.26KiB/s ETA 05:29[9a900668] main input error: ES_OUT_SET_(GROUP_)PCR is called too late (jitter of 6755 ms ignored)
    [download] 92.0% of 44.63MiB at 11.22KiB/s ETA 05:25[9a900668] main input error: ES_OUT_SET_(GROUP_)PCR is called too late (jitter of 6292 ms ignored)
    [download] 92.2% of 44.63MiB at 11.17KiB/s ETA 05:20[9a900668] main input error: ES_OUT_SET_(GROUP_)PCR is called too late (jitter of 6292 ms ignored)
    [download] 92.3% of 44.63MiB at 11.11KiB/s ETA 05:16main input error: ES_OUT_SET_(GROUP_)PCR is called too late (jitter of 6398 ms ignored)
    [download] 92.5% of 44.63MiB at 11.07KiB/s ETA 05:11[9a900668] main input error: ES_OUT_SET_(GROUP_)PCR is called too late (jitter of 6513 ms ignored)
    [download] 92.6% of 44.63MiB at 11.03KiB/s ETA 05:07[9a900668] main input error: ES_OUT_SET_(GROUP_)PCR is called too late (jitter of 7233 ms ignored)
    [download] 92.8% of 44.63MiB at 10.98KiB/s ETA 05:00[9a900668] main input error: ES_OUT_SET_(GROUP_)PCR is called too late (jitter of 7269 ms ignored)
    [download] 92.9% of 44.63MiB at 11.00KiB/s ETA 04:54[9a900668] main input error[download] 93.0% of 44.63MiB at 10.98KiB/s ETA 04:53ES_OUT_SET_(GROUP_)PCR is called too late (jitter of 7269 ms ignored)
    [download] 93.0% of 44.63MiB at 11.00KiB/s ETA 04:51[9a63baf0] main decoder error: Timestamp conversion failed for 594927667: no reference clock
    [9a63baf0] main decoder error: Could not convert timestamp 0 for MMAL decoder
    [download] 93.4% of 44.63MiB at 10.72KiB/s ETA 04:42[9a900668] main input error: ES_OUT_SET_(GROUP_)PCR is called too late (jitter of 6018 ms ignored)
    [download] 93.5% of 44.63MiB at 10.71KiB/s ETA 04:38[9a900668] main input error: ES_OUT_SET_(GROUP_)PCR is called too late (jitter of 6018 ms ignored)
    [download] 93.5% of 44.63MiB at 10.62KiB/s ETA 04:38[9a63baf0] main decoder error: Timestamp conversion failed for 597997401: no reference clock
    [9a63baf0] main decoder error: Could not convert timestamp 0 for MMAL decoder
    [download] 94.1% of 44.63MiB at 10.27KiB/s ETA 04:21[9a900668] main input error: ES_OUT_SET_(GROUP_)PCR is called too late (jitter of 11367 ms ignored)
    [download] 94.3% of 44.63MiB at 10.26KiB/s ETA 04:14[9a900668] main input error: ES_OUT_SET_(GROUP_)PCR is called too late (jitter of 11367 ms ignored)
    [download] 94.3% of 44.63MiB at 10.23KiB/s ETA 04:13[9a900668] main input error: ES_OUT_SET_(GROUP_)PCR is called too late (jitter of 5639 ms ignored)
    [download] 94.5% of 44.63MiB at 10.15KiB/s ETA 04:09[9a900668] main input error: ES_OUT_SET_(GROUP_)PCR is called too late (jitter of 5639 ms ignored)
    [download] 94.5% of 44.63MiB at 10.08KiB/s ETA 04:07[9a900668] main input error: ES_OUT_SET_(GROUP_)PCR is called too late (jitter of 6488 ms ignored)
    [download] 94.9% of 44.63MiB at 9.80KiB/s ETA 03:59[9a900668] main input error: ES_OUT_SET_(GROUP_)PCR is called too late (jitter of 6488 ms ignored)
    [download] 95.0% of 44.63MiB at 9.69KiB/s ETA 03:53[9a900668] main input error: ES_OUT_SET_(GROUP_)PCR is called too late (jitter of 6488 ms ignored)
    [download] 95.2% of 44.63MiB at 9.69KiB/s ETA 03:48[9a900668] main input error: ES_OUT_SET_(GROUP_)PCR is called too late (jitter of 8623 ms ignored)
    [download] 95.3% of 44.63MiB at 9.64KiB/s ETA 03:43[9a900668] main input error: ES_OUT_SET_(GROUP_)PCR is called too late (jitter of 8623 ms ignored)
    [download] 95.5% of 44.63MiB at 9.61KiB/s ETA 03:35main input error: ES_OUT_SET_(GROUP_)PCR is called too late (jitter of 7943 ms ignored)
    [download] 95.6% of 44.63MiB at 9.60KiB/s ETA 03:30[9a900668] main input error: ES_OUT_SET_(GROUP_)PCR is called too late (jitter of 5714 ms ignored)
    [download] 96.3% of 44.63MiB at 9.38KiB/s ETA 02:59[9a900668] main input error: ES_OUT_SET_(GROUP_)PCR is called too late (jitter of 7943 ms ignored)
    [9a63baf0] main decoder error: Timestamp conversion failed for 611177234: no reference clock
    [9a63baf0] main decoder error: Could not convert timestamp 0 for MMAL decoder
    [download] 96.8% of 44.63MiB at 9.23KiB/s ETA 02:38[9a900668] main input error: ES_OUT_SET_(GROUP_)PCR is called too late (jitter of 8144 ms ignored)
    [9a63baf0] main decoder error: Timestamp conversion failed for 617083134: no reference clock
    [9a63baf0] main decoder error: Could not convert timestamp 0 for MMAL decoder
    [download] 96.9% of 44.63MiB at 9.23KiB/s ETA 02:35QObject::~QObject: Timers cannot be stopped from another thread


    ERROR: unable to write data: [Errno 32] Broken pipe

User avatar
TheComputerWizard
Posts: 6
Joined: Wed Sep 18, 2019 4:03 am
Location: Atlanta, Georgia
Contact: Website YouTube

Re: How to stream Youtube videos using youtube-dl and omxplayer ?

Mon Sep 30, 2019 5:41 am

I find this works best for me playing on a 1080 HD monitor. Puts the window in the bottom left corner so as not to obfuscate the system menu when they are position at the top of the display by default.

Code: Select all

#!/bin/bash
omxplayer -o hdmi --win "0 690 640 1050" $(youtube-dl -g -f $2 $1)
Execute as described before in the posting two up.

./ytplaywin URL Format

WIth URL being the Youtube url address of the video, and Format being 18, or best. 18 typically matches up with 640x360 which matches the dimensions of the window created with this script.

Return to “Raspbian”