YouTube on the Raspberry Pi At Last
To cut a long story short: YouTube finally works in HD on my TV with RemotePi. I can’t stop watching LaFerrari and McLaren P1 videos in HD with great sound!
Why was it so difficult?
In the old times, youtube-dl -g spat out YouTube stream URLs, and omxplayer could play them straight away. The excellent ncurses based yt worked this way. But things have changed. YouTube now only streams the video if a session cookie is presented. But omxplayer can’t use cookie jars.
But curl can! We tell youtube-dl to save the cookie, and let curl save/stream the video using the cookie.
curl -b jar `youtube-dl -g --cookies jar --write-thumbnail`
will spit out the video stream.
1st Attempt – Save to File
Let curl save to a file, and start omxplayer a few seconds later to play it back. Keep fingers crossed that curl saves faster than omxplayer reads.
It does not. This solution is so disk/sdcard IO intensive, that omxplayer will reach the EOF too soon and exit.
2nd Attempt – Stream via FIFO
Let’s create a FIFO file, and let curl write the video stream into that. And start omxplayer immediately to read the video stream from the FIFO. It works beautifully:
- there is no disk IO at all, so 
curlwrites faster thanomxplayerreads - even if it’s not the case due to a slow network, the player does not exit, just blocks until 
curlcatches up. Bacause the FIFO is a character device! - if 
omxplayerexits for any reason,curlgets a SIGPIPE and exits too 
The Result – rpyt
It’s all wrapped up in a new script packaged with omxd: rpyt.
And the RemotePi remote-control web-app also uses that from now. See the project homepage and the code on Github.


