Project

General

Profile

How to Chromecast?

Added by Gabs Man over 8 years ago

I have a Chromecast 2. I also have a Media server running OpenMediaVault and TVHeadEnd with a dual tuner. I think it's great, works really well I have been using TVHClient on my phone, Kodi, Plex and the web interface.

I can watch Live TV or Recordings via Kodi no problem, and the Guide looks really good in Kodi too; but alas, there's no way to cast it to my TV from Kodi.

I have also set up channels in Plex for TVHeadEnd. I can view the Live TV adn also Recordings, although the Recordings won't play in the browser with Plex. I have worked out with a Movie library I can play the Recordings though. Unfortunately, although they play in the browser, Chromecast just wont play it properly, not sure if it's transcoding settings or what, it either say s Cannot play video or shows half the picture blurry. Similary using the Plex app on my phone.

With teh TVHClient it uses an external player. But when I go to the external player, it won't allow Chromecst; not sure if that's being limited by the app or TVH?

So has anyone got this working? If so, how do you do it? It's really frustrated as I just want to be able to watch TV recording on my TV, not just on my phone and tablet :(

cheers,
gabs


Replies (56)

RE: How to Chromecast? - Added by Paul M over 5 years ago

I too wondered why there wasn't a chromecast feature.

I found this, I don't know whether it's relevant as I'm not a developer.
https://github.com/googlecast/CastVideos-chrome

RE: How to Chromecast? - Added by thermionic valve about 5 years ago

With the exception of casting a web page to a chromecast device, when one casts using netflix/youtube/bbc iplayer etc, the stream address to cast from is passed to the chromecast, and the chromecast then connects directly to the stream.

There are two options, one complex, and one easy.

The complex option would be to write a "caster" for tvhe, and a suitable client (in effect duplicating the bbc iplayer client and server infrastructure)

The easy option would be to run Kodi on a device connected to your TV over HDMI.

RE: How to Chromecast? - Added by Joe User about 5 years ago

I have not used in at least 3 years, but the paid version of tvhclient for android was able to "cast" live tvheadend streams. I never tried the paid version, but with the free version, I was able to use the an external player (mxplayer, I think??) and cast from it. The key was you had to transcode the stream to a format chromecast will accept. I think I just used one of the built in webtv profiles. Also, it was with the original chromecast device, I am not sure what format newer chromecast devices will accept. Also note this only worked for live streams as recordings are not transcoded...

RE: How to Chromecast? - Added by thermionic valve about 5 years ago

If you were able to do so, it would be lovely thing to see.

You would need to use one of the supported codecs https://developers.google.com/cast/docs/media and either pass credentials to tvhe, or allow access without credentials.

RE: How to Chromecast? - Added by Joe User about 5 years ago

I found my old chromecast over the weekend and plugged it in. Of course it immediately started an automatic update. After that, I could not cast anything. A factory reset and reconfigure allowed me to cast from chrome browser and VLC, but was not working with MXPlayer. Sorry, did not have time to troubleshoot anymore...

VLC could be used to cast: https://forum.videolan.org/viewtopic.php?t=143114

Or have you seen this?:https://github.com/balloob/pychromecast

RE: How to Chromecast? - Added by Paul M about 5 years ago

@"Joe User"
pychromecast looks just about perfect for the job, thanks!

RE: How to Chromecast? - Added by Paul M about 5 years ago

it's early days yet, but I have managed to watch a stream of BBC One HD, on my chromecast.

I created a "chromecast" profile which transcodes to h264/mp4.

It's eating 75% of one core of a core i3-2100, so working hard to transcode the video to h264 on the fly to chromecast to play.

I'll be posting code as soon as it's no longer hand cranked.

RE: How to Chromecast? - Added by Paul M about 5 years ago

First cut of an EPG which allows you to cast live channels to a chromecast device is here:

https://github.com/speculatrix/tvh_epg

instructions copied to here: https://github.com/speculatrix/tvh_epg/blob/master/CHROMECAST.md
with a screenshot to show you how the streaming profile is made

I also send an email to "baloob" to say thanks.

Unfortunately I can't cast recordings because persistent auth tokens don't work for playing recordings, and I can't see in the API docs how to generate a ticket to temporarily authenticate playback.

RE: RE: How to Chromecast? - Added by Paul M almost 5 years ago

Some good progress on tvh_epg project.

At home I have my own DNS, so my TV Headend server has a resolvable name using my private DNS server. However, it appears that Chromecasts always use Google, so, I added a feature to make the program resolve the hostname to an IP address before telling Chromecast to play the stream.

I have found it works very well with my Chromecast 3rd gen. Also, I discovered that it works with my Chromecast Audio, allowing me to stream radio and the soundtrack off TV channels (both mpeg2 std def and h264 hi def channels). Oddly, ClassicFM only plays for two seconds and cuts out, I thought it might be due to a high bit rate but BBC Radio 3 plays just fine.

Talking of radio channels, people might like my command-line radio app (although it was written for the raspberry pi, it will run on anything: https://github.com/speculatrix/ya_pi_radio )

RE: How to Chromecast? - Added by brimur brimur almost 5 years ago

Hi all, a simple ready made option that I use on my Android phone is to download TVHClient, set it to use an external player and select Google Photos as the app. Set the cast profile in TVHClient settings to webtv-h264-aac-matroska. In your Tvheadend server edit that profile and set the video codec to just Copy so you don't have to transcode (most TV channels use H264 so no need).
Now when you play in TVHClient it will open in Google Photos. Tap the screen and select the Chromecast icon. Google Photos is the only Chromecast enabled app that I have found that will reliable cast without the need to transcode first.

RE: How to Chromecast? - Added by David G almost 5 years ago

@Paul_M I have just setup tvh_epg to read from TVHeadEnd but it is not finding my Chromecast device. I have checked pychromecast (using the example scripts) and that seems to work and I can see my CC device. I'm therefore a little lost with tvh_epg. Any ideas please?

The other issue is that the current stable TVHeadEnd for Buster (4.2.8-34~g24a2f59e9) does not seem to have the options under "passwords" for Persistent Authentication so I cannot set this up?

I have tried upgrading TVHeadEnd to the latest unstable (for Buster) (4.3-1857~g221c29b40) and that does allow Persistent Authentication settings, BUT, does not allow transcoding profiles and tvh_epg does not seem to be able to login and keeps coming up with authorisation errors.

Do you have a deb package for a version of TVHeadEnd that works with tvh_epg or any other suggestions to get this working please?

RE: How to Chromecast? - Added by Paul M almost 5 years ago

Hi, sorry, I don't have a deb. After all, there's just one single file to put in place, and one directory to make with the right permissions.

I presume that the settings page comes up OK and saves correctly to /var/lib/tvh_epg/tvh_epg_settings.ini ? Ensure that file is writable by apache daemon (or whatever web service you're using).

I just committed a new version with a few bug fixes, mainly around authentication. I tried adding username/password to the URL for DVR playback and failed.

I'm not sure why tvh_epg gives authorisation failures, however, it does need a fair few privileges in order to do things. I'll check mine and let you know.

I am running 4.3-1855~gd453f5bef~bionic and I was able to set up the the right trancoding profile for chromecast. I'll re-read my docs and check they're correct.

RE: How to Chromecast? - Added by Paul M almost 5 years ago

in case it's not clear, the pychromecast files live in a subdirectory where the tvh_epg.py is living, so you should see something like this

$ pwd
/usr/lib/cgi-bin

$ ls -la *
-rwxrwxr-x 1 paulm paulm 49958 Jan  6 21:11 tvh_epg.py

pychromecast:
total 148
drwxrwsr-x 4 paulm paulm   233 Nov 14 10:52 .
drwxrwsr-x 3 root  paulm    97 Jan  6 21:11 ..
-rw-rw-r-- 1 paulm paulm  3938 Nov 13 21:54 authority_keys_pb2.py
-rw-rw-r-- 1 paulm paulm 19055 Nov 13 21:54 cast_channel_pb2.py
-rw-rw-r-- 1 paulm paulm  1117 Nov 13 21:54 config.py
drwxrwsr-x 3 paulm paulm   174 Nov 14 10:52 controllers
-rw-rw-r-- 1 paulm paulm  5005 Nov 13 21:54 dial.py
-rw-rw-r-- 1 paulm paulm  5378 Nov 13 21:54 discovery.py
-rw-rw-r-- 1 paulm paulm  1253 Nov 13 21:54 error.py
-rw-rw-r-- 1 paulm paulm 14812 Nov 13 21:54 __init__.py
-rw-rw-r-- 1 paulm paulm 36511 Nov 13 21:54 logging_pb2.py
drwxrwsr-x 2 paulm paulm  4096 Nov 19 20:33 __pycache__
-rw-rw-r-- 1 paulm paulm 43534 Nov 13 21:54 socket_client.py

RE: How to Chromecast? - Added by David G almost 5 years ago

Thanks for your reply Paul. I have made some progress today;

1) Chromecast not working - pychromecast was failing on import (Apache2 server) due to missing zeroconf module, even though it was installed for Python3 when used from the command line. After a lot of research and trials, the fix for Apache was "pip3 install zeroconf  --upgrade". Easy when you know!

2) In order to get "Persistent Authentication" I have to upgrade to TVHeadend 4.3-1857. Initially TVH_EPG gave authorisation errors, so was unable to see the EPG / Channels pages etc. This was resolved (by chance!) by running TvhClient on my iPhone. It came up with an error (sorry did not note what it said) but it offered an option to FIX. Both TVH_EPG and TvhClient, then worked.

3) The problem with the latest TVHeadEnd is that there are no transcoding profiles and you cannot create your own either, like "chromecast". This transcoding functionality seems to have been removed from latest builds and so I am now trying to compile a DEB with it enabled. I am running in to problems though and so have raised a new forum post.

4) Without transcoding, I will not get Chromecast to work but I am also having an issue with the URL starting with "http://127.0.0.1". Whislt this works from a web browser, the example pychromecast files only work with a) http://localhost/ or the IP address itself on my setup. To help me tick this off my list of issues, how do I change TVH_EPG so that for now I can manually type in my IP? (Line 552?).
EDIT- Issue resolved to change 127.0.01 to my IP address, can be done in the settings tab :-)

Any advice would be appreciated, the winning line is in sight!!??

RE: How to Chromecast? - Added by David G almost 5 years ago

@Paulm, I've pretty much got things working now, thanks to all your coding efforts :-)

I have 2 issues to ask you about please;

1) I am not seeing any TV Logos, even though I have copied over the .png files and setup in the settings tab. I have attached two screen shots of my settings and what the page is actually looking like. If I manually browse to a .png file, it will display fine, eg http://192.168.1.183/tvlogos/4Music.png

2) I get python errors on the EPG Guide, python error HTML attached.

Is there something I still have not got correct on my setup?

Edit: Also added the TVClient "fix" message that I see initially, FYI.

RE: How to Chromecast? - Added by Paul M almost 5 years ago

Hi David G,
are you running the tvh_epg web interface on the same machine as the tvheadend server, or on a different machine.
I have both, depending where I am, at home it's on the TVH server, when I am outside and connecting via a VPN, it's on different machine.


if you look at the HTML for the EPG, what URL do you see for the logo images? is it correctly being set to http://192.168.1.183/tvlogos/XYZ.png?

My code is seeing whether the channel information from TVH knows about icons. If you put the URL for the picons into the TV Headend server into Configuration->General->Base->Channel icon path then tph_epg knows there's an icon. If that is blank, then tvh_epg won't show anything.

I think at one point I was going to try and test, if tvh_epg ran on the same server as the one serving picons then it would check for the existence of the file before putting putting the img-src into the html. Sorry if I am a bit vague, I've not worked on that bit for quite a while. It's beginning to come back to me now! I probably need to rethink the whole thing.


the json error is probably due to a bad conversion to utf8. there's some possible fixes here:
https://stackoverflow.com/questions/22394235/invalid-control-character-with-python-json-loads

maybe the "json_str = json.loads(jsonString, strict=False)" fix?

this is hard to reproduce, as I'd need to encounter the bad data from TVH server at the time.

RE: How to Chromecast? - Added by Paul M almost 5 years ago

oh, and thanks DavidG for persisting, you're one of the very (privileged!) few to be trying this out.

RE: How to Chromecast? - Added by David G almost 5 years ago

Hi PaulM, I'm feeling privileged too :-)

I'm running both TVH_EPG.py and TVH on the same PI4.

Thanks for explaining how to setup TVH for the channel logos, they work now :-). There are some not coming through but that must be a naming issue, so will look at the logo file names now.

I will take a look at the json part next, looks a bit harder for me that one though ;-)

RE: How to Chromecast? - Added by David G almost 5 years ago

Umm, in terms of "json_str = json.loads(jsonString, strict=False)", where would you suggest to add this in the PY code please?

RE: How to Chromecast? - Added by Paul M almost 5 years ago

Hi,
yes, there's channels which have no icon. And some channels with a +1 do have icons and some don't, so there's a hack to always using the non +1 icon. It's all a bit hacky really. If I knew that tvh_epg.py was always going to run on the same server where it can find the picons then it could peak into the file system and have a better guess.

thanks for the comments about pip modules, I've added comments to the chromecast.md about it, so a fresh git pull will grab that. there's no functional change.

I'll work out where to put the updated json.loads and publish an update.

thanks for your patience and persistence.

I've forgotten how to make a deb package, I should remind myself then I can do that and make the whole process simpler.

thanks

RE: How to Chromecast? - Added by David G almost 5 years ago

Thanks for the update Paul. I've updated to the latest PY file, not noticed any difference from my side.

I've now setup the missing logos as you described - job done :-)

In terms of the EPG tab error, I've noticed that at some times during the day, it will actually display all the channels, then at other times, it seems to get stuck on a particular channel for awhile. I'm wondering therefore if there is something in the DVB-T EPG data that's tripping up the code, which is fine though for DVB-S?

Let me know if you want me to do some sort of logging to help work out what's going on?

RE: How to Chromecast? - Added by Paul M almost 5 years ago

I've not had an problems with the page stalling other than rendering the very large table with many images if I'm using a slower device. On my laptop it's just fine. Is your R-Pi beginning to run a little low on RAM to run TVH and the web ui and anything else?

RE: How to Chromecast? - Added by David G almost 5 years ago

Sorry Paul, my post was misleading. I was trying to clarify that the point when I get the "JSONDecodeError: Invalid control character" appears on a particular channel and will continue, presumably until the epg data moves along to the next time slot later in the day.

Maybe its down to working out how to implement "json_str = json.loads(jsonString, strict=False" but I dont know where to start ;-)

RE: How to Chromecast? - Added by Paul M almost 5 years ago

Hi David G,
I've a little more free time now, had some time consuming deadline things to attend to.

I added the quick fix for the non-strict json.loading from the json sent by the TVH server.

If you still get the problem, please uncomment line 341 and send me the raw dump text before it gets to json conversion, code snippet at end

The the epg page will display the raw dump from the server, please copy the raw dump into pastebin or something and post the URL here.

thanks for your patience. hopefully we can crack this problem so others will find it easier to use.

regards
Paul

#print('
Extreme Debug!\n\n%s\n<pre>' % (ts_text,))
(1-25/56)