Add support for H.265 in stream component

Do you use the mobile or web app? This can force the camera to revert. You should be able to enable logging and see exactly what is changing it. I wound up setting my substreams to h.264 instead. At 960/480@15 the stream is larger than the main stream for the most part at 2560/1440@15.

This literally cuts my storage in half. I just set it up a few days ago and I think I’m just going to disable the feeds in HA. I’m confused to why I can play h.265 streams on the camera’s web page in Firefox but not in HA because of Firefox.

Hmm, that’s weird…they should work fine in the iOS app (not sure about actionable notifications though) and in Safari. The stream should get passed through to the native player the exact same way for both types of codecs.
Chrome won’t work, as I mentioned above.
Everything works fine when using H.264 but not when using H.265? Have you disabled all kinds of proprietary codec enhancements like H.265+?

Yeah, the compatibility issues across various devices sucks, but there’s not much more we can do. As I mentioned above, a lot of the lack of support is due to the codec wars between Google (and the content providers or codec freeloaders depending on your view eg Netflix) and MPEG-LA (the codec developers or codec extortionists depending on your view).
For my own setup I have all the cameras on H.265 except one which I cast since the cast device doesn’t seem to support H.265 as well as H.264. No issues with the iOS app or Safari.
I’m not sure how you get H.265 streams in Firefox. It’s pretty well documented that the browser doesn’t support H.265. Some camera manufacturers provide web browser plugins to help play camera streams, but I thought they removed support for those types of plugins in Firefox. Is it possible that it’s actually just playing a substream?

My sub steams are D1 480x704 aside from the obvious blurry picture you can just switch the resolution from sub to main stream. It also work fine on chrome.

I grabbed the code from the web page it seems to use h5player for the stream.

I’m sure there is someway to view the codec used in the inspector but I just not sure how to find it. In the debbuger I can see the web app is java and there I find h5.js

<div id="h5player_header_2" class="h5player_header"><i class="h5player_closeIcon"></i></div><div id="videoBackground_2" class="video_background" style="margin-left: 494.5px; margin-top: 82.75px; display: none;"></div>                                                <canvas id="canvasplayer_2" style="position: absolute; display: block; top: 15px; left: 0px; width: 1110.67px; height: 241.667px;" width="1920" height="1080"></canvas>                                                <div id="videoLoading_2" class="video_loading" style="display: none;"></div>                                                <video id="videoplayer_2" style="position: absolute; display: none; top: 15px; left: 0px; width: 1110.67px; height: 595.667px;" width="300" height="300"></video>                                                <div id="h5playerProptip_2" class="h5playerProptip" style="display:none"></div>                                                <div id="h5playertip_2" class="h5playertip" style="display:none"><span id="h5playertipWord_2></span><i class=" i-close"=""></span></div><div id="downloadCert" class="download-plugin fn-hide" style="height: 150px; margin-top: -75px; background-color: rgb(0, 0, 0); z-index: 110000; display: none;">                          <div style="margin-top: 59px;">                            <a class="pluginMsg" id="downloadCert_a" onclick="downloadCert()" href="javascript:void(0)">                            <span class="download-plugin-icon"></span>                            <span t="sys.DownloadCer">Download Certificate</span></a>                          <div>                        </div></div></div>

I can’t make much of the html you posted, and googling of “h5” and “h5player” was a bit inconclusive. It looks like there may be some Chinese js libraries that use web assembly to decode H.265 video such as https://github.com/tsingsee/EasyPlayer.js .
Unfortunately I don’t have the time now to look into it much further. If you have time, maybe you could dig into it and get us a H.265 solution that works on all platforms =)

Looking further I found a js wrapper for ffmpeg. I could be wrong but it seems that either of these h.265 libraries can be used with ffmpeg:

https://bitbucket.org/multicoreware/x265_git/src/master/

which is used by VLC and

Which I think the Dahua webapp uses with ffmpeg

You will have to tie the codec to a player which can play HLS streams. Some of those Chinese libraries do that (maybe with ffmpeg in web assembly), but I’m not sure about the licensing on them. Actually I’m not sure HA is allowed to incorporate the codec at all. There seems to be an exemption for costless software but that is only from some of the patent holders - see https://en.wikipedia.org/wiki/High_Efficiency_Video_Coding#Provision_for_costless_software
BTW, hls.js could have gone this route (incorporating ffmpeg in webassembly) but decided against it, possibly for similar reasons - see https://github.com/video-dev/hls.js/issues/2451#issuecomment-592770018
Good luck!

1 Like

I have a hikvision system too. I don’t think I have the problem of it not keeping the setting, but thought it might be worth noting for yourself or others that there are separate settings for the main stream and secondary stream (i.e. 101 vs 102), and it is possible to have one H.264 and another H.265.

I have “Synology DSM” integration enabled with all my cameras on it. Unfortunately, they just show snapshots, looking pretty and doing nothing because they are streaming in h.265.

+1 for this

Is h265 still not implemented through HA and desktop browsers (Chrome)?

1 Like

Agreed this hopefully will get fixed as cameras are moving toward more compressed stream qualities. I can see my cameras on my cell phones and tablets but not on my PC web browser. very disheartening!!

Yeah chrome(pc) still doesn’t support h265 and I don’t think it will in the near future.

1 Like

Works on Edge now, not tried Chrome recently

Indeed it does work on Edge provided you have HEVC extensions installed, but to get it working properly with stream, we need a new release of PyAV that includes this PR I made back in February:
Expose codec_tag in codec_context by uvjustin · Pull Request #748 · PyAV-Org/PyAV · GitHub
PyAV hasn’t been updated in quite some time, so if you see a new release please let me know and I will bump the version in HA.

1 Like

How did you get it working on Edge? I have HEVC extension installed but still the h265 cams shows up blank.

Configuration.yaml looks like this: -

ffmpeg:
stream:
camera:
   - platform: generic
     name: DoorCamera265
     still_image_url: http://192.168.1.10/webcapture.jpg?command=snap
     stream_source: rtsp://192.168.1.10:554/user=xxxx&password=xxxx&channel=1&stream=0.sdp?

and Picture Entity Card Configuration is simply:-

type: picture-entity
entity: camera.doorcamera265
name: ' '
camera_image: camera.doorcamera265
camera_view: live
show_state: false

You might not want live view

Hope that helps

I created a fork of PyAV so we could access the feature needed to get H.265 working in Edge and other chromium builds with H.265 support.
This is in the beta and will be in the 2021.11 release.

2 Likes

Worth mentioning here that I have a Hikvision DS-2CD2455FWD-IW (where do they get these names?!) connected to a Synology Surveillance Station, streaming in H.265+ and, while it does indeed work in Edge, it’s a solid 25 seconds behind real-time. Not complaining, just feeding back.

A similar sort of delay affects my h.264 cameras via Home Assistant (again, same setup to Synology which presents the cameras to HA through the DSM integration) - for the h.264 cameras though, that’s about 7-10 seconds behind real-time.

I overcome this delay using AlexxIT’s WebRTC (HACS integration) for the h.264 cameras when I want to see as near to real-time as possible in HA, but that doesn’t work for the h.265 cameras. Obviously I can use the Synology native Android app if necessary but having a tablet switch to the lovelace card for the camera when motion is detected (and with minimal latency in stream) is the goal.

Still, nice to see h.265 support arriving! Thanks for your work.

1 Like

Glad the H.265 support works for you.
The latency from H.265+ streams is from the large intervals between i-frames. If you want to reduce latency, use the LL-HLS option that was added in 2021.10 and improved in 2021.11.
Stream - Home Assistant (home-assistant.io)
Using the configuration there should help bring your latency down to about 3 seconds even with H.265+.

1 Like

@uvjustin I have 3 cameras with h265+ streams added with the picture-entity cards. I open the Android HA app. In the view where all 3 are shown below each other, I get bufferIncompatibleCodecsError. But when I click on each of them, the stream loads correctly and an almost live view is shown. Shouldn’t those streams load correctly on the view of 3 cards as well? And not just if I tap on them.