SgtBatten / HA_blueprints

Somewhere to store automation blueprints
205 stars 78 forks source link

[Bug]: Clip not showing/broken #61

Closed Hamish1066 closed 1 year ago

Hamish1066 commented 1 year ago

Description

When I click the iOS notification, the clip is takes me to is just a crossed out play button - no actual video plays.

Version

0.12.0.1

Automation Config

alias: Front Door - Front Door Camera - Notification (Blueprint)
description: ""
use_blueprint:
  path: SgtBatten/Stable.yaml
  input:
    camera: camera.front_door
    notify_device: f35621be2644c6418833fca46ca6914c
    message: A {{label}} was detected on the {{ camera_name }}.
    ios_live_view: true
    base_url: https://[myurl].ui.nabu.casa
    tap_action: /frigate/notifications/{{id}}/camera.front_door_2/clip.mp4

Frigate Config

No response

Any other relevant information

For the tap action, I've tried just the regular "View Clip" drop down option, which yielded the same result except that it took me to the browser in my phone rather than the HA iOS app. I specified the name in the tap action as there is a related bug with this Blueprint - I already have a non-Frigate (Nest) camera called "Front Door", so when I gave the camera in Frigate the same name, Home Assistant assigned it the name "Front Door 2" within the HA Frigate integration. I had to manually update the camera name to match the name given in Frigate, as the drop down option didn't work.
SgtBatten commented 1 year ago
/frigate/notifications/{{id}}/camera.front_door_2/clip.mp4

This is invalid.

the camera name needs to match frigate config. and not have 'camera.' at the front.

so camera.front_door_2 probably needs to be just front_door i assume, which it would have been by default.

Hamish1066 commented 1 year ago
/frigate/notifications/{{id}}/camera.front_door_2/clip.mp4

This is invalid.

the camera name needs to match frigate config. and not have 'camera.' at the front.

so camera.front_door_2 probably needs to be just front_door i assume, which it would have been by default.

Thanks. I tried it with {{camera}} and front_door as you recommended, but it didn't work. They both show the image here: https://www.reddit.com/r/homeassistant/comments/155vtoh/frigate_blueprint_clip_broken/

I also tried changing the name to "front_yard" so there is no more conflict with the other camera entity, and tried using the blueprint with just the drop downs, but I still get the image above. I've confirmed that I can otherwise see the clips on my devices.

SgtBatten commented 1 year ago

Copy the url that it opens onto a device on your local network. Remove the nabu casa url and replace it with the Lan IP and port of home assistant. Any difference?

Hamish1066 commented 1 year ago

It didn't work with the Lan IP, but it did work when I replaced the Nabu Casa URL with homeassistant.local:8123. However, it only works in Chrome, and only on my laptop, not on my iPhone. I also tried pasting the Nabu Casa URL into Chrome, and it won't load - it just gives me a black video box that says "0:00" for time and the play button doesn't do anything.

SgtBatten commented 1 year ago

Perhaps a codec issue. Are the cams outputting h.265?

Hamish1066 commented 1 year ago

Yes, I think that’s why it’s not playing in certain browsers - it is h.265 - but that doesn’t explain why it won’t play in that companion app. The stream and recordings both play on the companion app, so I think clips should play as well?

SgtBatten commented 1 year ago

You said it wouldn't work with your nabu casa url even in chrome so I assume the same reason is the issue for the app. Though on android it doesn't open in the app, it opens in a browser so I can't play h.265 clips. I run two recorders for the hm265 cam. One in h.264 for being able to view it everywhere. And one just recording in beat quality in case I need it.

I suggest you try without the base url set and see what occurs.

Hamish1066 commented 1 year ago

I tried without the base url in the automation and there was no difference. I guess I’ll see if I can get a h.264 stream on my Reolink cameras. Any other suggestions?

SgtBatten commented 1 year ago

h.265 is not well supported still. I cannot play it on any of my devices, even my desktop computer due to older hardware. I also have reolink cams and there were heaps of resources on this topic I used when i set them up. Some cams can be tricked into h.264 with slight reductions in resolution, others only do h.265 on certain streams like my duo2.

I agree it's weird you can view it in the app when browsing frigate normally but not via the api. How certain are you it's opening in the app?

Hamish1066 commented 1 year ago

I’m 100% certain that it’s opening in the app. I’ve tried opening it in the app and the browser, and both have the same result. I’ll try to get h.264 working. Do you set the h.264 stream for detect and recording?

As a side note, I was thinking of getting a duo2. Does it not do h.264 at all?

SgtBatten commented 1 year ago

The duo2 is the only 265 cam I have but I read about many others over the time.

If I recall correctly the main duo2 stream is only 265. The substream is only 264. So in frigate I have two cams setup for the one duo2. One which detects and records on the 264 substream. I use this for all my notifications. The other cam detects on 264 and records the main 265 stream so I have the highest resolution recorded if I need to pull tapes.

Hamish1066 commented 1 year ago

Thank you. Any chance you could share your config for the Duo and your other Reolink camera? I’ve read a LOT online of peoples configs for these, but all seem to be a year or two old - I can’t get them working on mine and I’m wondering if something has changed on that time.

Hamish1066 commented 1 year ago

Further, I just tried setting this up on a h.264 camera, and I’m having the exact same issue. So I think I can rule the stream out – it seems to be something else. Any ideas? It would be great if you could share your config as requested above so I could debug this.

Hamish1066 commented 1 year ago

Sorry - one other thought - are you able to share the yaml for how the automation opens the specific clip, and perhaps I could try it in another automation without the blueprint?

SgtBatten commented 1 year ago

are you able to share the yaml for how the automation opens the specific clip, and perhaps I could try it in another automation without the blueprint?

You've already done this. The automation just open the url. It has some behind the scenes bits to generate the ID but if you've copied it, and pasted it somewhere else that's the whole process.

Frigate generates the event I'd and we are simply using the frigate notification API from the integration.

Can you please check what you have configured for the integration?

Screenshot_20230724-071203

Frigate config I will share in a little bit.

Hamish1066 commented 1 year ago

Thanks. My config for the integration is identical:

[Image.jpeg]

For the yaml for how to open the specific clip, I don’t understand how to pull the event ID outside of your blueprint?

I really appreciate your help so far! I’m very excited about Frigate and this is the last piece that I would like to get working in order to ditch my old canards setup completely.

SgtBatten commented 1 year ago

Here is the reference to the api we are using. It hasn't changed in forever so we know it's good. https://docs.frigate.video/integrations/home-assistant/#notification-api

to get the id, one easy way is to go to frigate events, click and event, click snapshot instead of clip image

right click and open the image in new window. the url contains the relevant ID near the end where it says /api/events/3620134358.35426-gydf7o/snapshot.jpg

SgtBatten commented 1 year ago

I've cut most of this out just to show the relevant bits. All the cams below are reolink but the duo2 is the only one with a 265 stream. My config was a lot of trial and error and is not perfect, just showing you what i have working currently. front and front4k are the two frigate cams i pull from the duo2.

go2rtc:
  streams:
    side: http://192.168.1.81/flv?port=1935&app=bcs&stream=channel0_main.bcs&user=admin&password={FRIGATE_REOLINK_PASSWORD}
    side_sub: http://192.168.1.81/flv?port=1935&app=bcs&stream=channel0_ext.bcs&user=admin&password={FRIGATE_REOLINK_PASSWORD}
    front_sub: ffmpeg:http://192.168.1.82/flv?port=1935&app=bcs&stream=channel0_sub.bcs&user=admin&password={FRIGATE_REOLINK_PASSWORD}
    doorbell: http://192.168.1.83/flv?port=1935&app=bcs&stream=channel0_main.bcs&user=admin&password={FRIGATE_REOLINK_PASSWORD}
    doorbell_sub: http://192.168.1.83/flv?port=1935&app=bcs&stream=channel0_ext.bcs&user=admin&password={FRIGATE_REOLINK_PASSWORD}

cameras:
side:
    ffmpeg:
      inputs:
        - path: rtsp://127.0.0.1:8554/side?video=copy&audio=aac
          input_args: preset-rtsp-restream
          roles:
            - record
        - path: rtsp://127.0.0.1:8554/side_sub?video=copy
          input_args: preset-rtsp-restream
          roles:
            - detect

  front:
    ffmpeg:
      inputs:        
        - path: rtsp://127.0.0.1:8554/front_sub?video=copy&audio=aac
          input_args: preset-rtsp-restream
          roles:
            - record
            - detect

  front_4K:
    ffmpeg:
      inputs:
        - path: rtsp://admin:{FRIGATE_REOLINK_PASSWORD}@192.168.1.82:554/h265Preview_01_main
          roles:
            - record
          hwaccel_args:
            -hwaccel vaapi
            -hwaccel_device /dev/dri/renderD128
            -hwaccel_output_format vaapi
          input_args: 
            -avoid_negative_ts make_zero
            -fflags genpts+discardcorrupt
            -strict experimental
            -analyzeduration 1000M
            -probesize 1000M

        - path: rtsp://127.0.0.1:8554/front_sub?video=copy&audio=aac
          input_args: preset-rtsp-restream
          roles:
            - detect
Hamish1066 commented 1 year ago

Thanks. Why is there a difference in the IP addresses for go2rtc vs the camera setups?

Hamish1066 commented 1 year ago

So I've found that if I hold the notification I can see a live view of the camera stream, and I have the options to view the clip or snapshot. If I click view the clip it gives me the same broken play button image, and if I try the snapshot it worked once but otherwise says not found. Is there a way to configure the stream that pulls up when I hold the notification to show me the clip instead of the live stream? I think that could fix this issue for me, since it seems to be able to play from there.

SgtBatten commented 1 year ago

Thanks. Why is there a difference in the IP addresses for go2rtc vs the camera setups?

Gortc connects to the reolink cams and then restreams them.

For the camera section it's connecting to gortc, not the camera. Exception is front 4k main stream. I can't remember exactly but direct connection worked better when I set it up.

SgtBatten commented 1 year ago

Is there a way to configure the stream that pulls up when I hold the notification to show me the clip instead of the live stream?

No, is is specifically a live stream entity on iOS.

SgtBatten commented 1 year ago

You'll need to do some digging into the network/console using a browser.

The fact you couldn't open it when using a Lan IP and port but could when using homeassistant.local is extremely weird to me. What exactly is your network setup?

Hamish1066 commented 1 year ago

I think I may have found the source of the issue. In the HA media sources folder, there is a “My Media” folder and a “Frigate” folder. If I go into the Frigate folder, everything is recorded as I’ve set it up. However, in the path mymedia/frigate/clips, there is nothing. I suspect clips are being pulled from here which is why they aren’t showing up. Does that make sense?

SgtBatten commented 1 year ago

That is normal. The media is in the frigate folder as you said. There integration is what connects frigate media with the HA media folder

Solarflor commented 1 year ago

Hi all, I'm having a similar issue. I have installed HA_blueprints Frigate Notifications (0.12.0.1) with notification on my Iphone and it seems to work almost well. Almost because I'm even able to receive snapshot on my Iwatch. image

But not on my Iphone where I only can see: image

Below frigate config

mqtt:
 host: core-mosquitto
 port: 1883
 user: solarflor
 password: floriano1628
birdseye:
  enabled: True
  restream: False
  width: 1280
  height: 720
  quality: 5
  mode: objects
ffmpeg:
  hwaccel_args: preset-rpi-64-h264
detect:
  enabled: True # <---- disable detection until you have a working camera feed
  width: 1920 # <---- update for your camera's resolution
  height: 1080 # <---- update for your camera's resolution
motion:
record:
  enabled: true
  expire_interval: 60
  retain:
    days: 0
    mode: all
  events:
    pre_capture: 3
    post_capture: 3
    objects:
      - person
      - car
    required_zones: []
    retain:
      default: 10
      mode: motion
      objects:
        person: 3
        car: 2
        truck: 2
        bicycle: 2
        motorcycle: 2
        dog: 2
        cat: 2
cameras:
  Piazzale_1: # <------ Name the camera
    ffmpeg:
      hwaccel_args: preset-rpi-64-h264
      inputs:
        - path: rtsp://admin:Antonio1628@192.168.1.209:554/cam/realmonitor?channel=1&subtype=1 # <----- The stream you want to use for detection
          roles:
            - detect
    objects:
      track:
        - person
        - car
    record: # <----- Enable recording
      enabled: True
    snapshots: # <----- Enable snapshots
      enabled: True

I have a Dahua Camera IPC-HFW3441T-ZS

Thanks for your support

SgtBatten commented 1 year ago

@Solarflor can you please share your automation config?

Solarflor commented 1 year ago

Here it is

alias: Frigate Notifications (0.12.0.1)
description: ""
use_blueprint:
  path: SgtBatten/Stable.yaml
  input:
    camera: camera.piazzale_1
    notify_device: b76118c030e61eef2c2eee37a5d0fc0e
    attachment: snapshot
    labels:
      - person
    presence_filter: person.floriano
Solarflor commented 1 year ago

sorry, not sure why the code is showed as above (no readable way). I used the <> comand

Hamish1066 commented 1 year ago

I'm still working at this problem btw. Interesting to see someone else has it. I've tested the notification on my MacBook Pro as well. When I open the notification in Safari, I get the same broken play button icon and no video. In Firefox, I get a video player that just plays black for the amount of the clip. In Chrome, it works fine. I've tried opening it in Chrome on my iPhone as well, but I get the broken play button.

Hamish1066 commented 1 year ago

Another update - this is definitely related to file format issues with iOS/MacOS/Safari. I downloaded VLC for iPhone and tried the clip there - it plays fine.

Is there a way to update the HA app so it can play these videos, or alternatively open the clips in VLC from the notification?

I'm still not sure why these videos won't play on iOS/MacOS/Safari, when in theory they are h.265 so therefore compatible. Maybe there is an issue with my Frigate config? Or possibly my HA config?

SgtBatten commented 1 year ago

H.265 is not supported as far as I know. Not on android either.

But you said it also happened on h.264?

SgtBatten commented 1 year ago

Here it is

Have you tried using a baseurl?

Solarflor commented 1 year ago

Have you tried using a baseurl?

give me some more instruction please

SgtBatten commented 1 year ago

give me some more instruction please

How do you access home assistant remotely? Do you have a url you setup?

E.g through nabu casa or you own private domain.

Or maybe you only use it at home, still you would have the Lan IP address and port and could use that.

Whatever it is, enter it in the bases url field in the automation.

Solarflor commented 1 year ago

How do you access home assistant remotely?

I have a duckdns url.

Whatever it is, enter it in the bases url field in the automation

do you mean someting like base_url: http://[myurl].duckdns.org ok I will try although it is not a protect url (https)

Hamish1066 commented 1 year ago

H.265 is not supported as far as I know. Not on android either.

But you said it also happened on h.264?

H.265 is supported on iPhone and MacOS, but I understand from some further reading that certain transcoders, including FFmpeg which is used by Frigate, aren’t compatible.

And yes, I’ve had the same issue using my h.264 cameras.

Hamish1066 commented 1 year ago

OK I FINALLY GO THIS WORKING WOOOOOOOO!

So, this issue is h.265. It turns out that, although both iOS and MacOS can play h.265 video, as I stated above, it cannot play video transcoded with FFmpeg. But there is a workaround (below).

I had two issues here:

  1. The FFmpeg transcoding not playing on Apple devices (I understand it works fine on Android); and
  2. Trying to play the clip in the HA companion app vs the web.

On issue 2, I was trying to play the clips directly within the companion app using this instead of the "View Clip" drop down option:

/frigate/notifications/{{id}}/{{camera}}/clip.mp4

That forced it to open the clip in the HA app rather than the browser, and caused the playback issued described above.

On issue 1, I found you can force compatibility by adding -tag:v hvc1 \ to your FFmpeg line in your Frigate config. This gives you an hvc1 output instead of hev1, which is incompatible with Apple.

My complete FFmpeg config is as follows (though only the one line mentioned above is necessary to get this to work:

ffmpeg:
  hwaccel_args: preset-vaapi
  input_args: -tag:v hvc1 
  output_args:
    record: preset-record-generic-audio-aac

@SgtBatten Thanks for your patience on this. I really appreciate you supporting such an awesome project (or projects - both HA and Frigate), and really appreciate you taking the time to create this Blueprint and respond to me. I'll leave this open for a day so that @Solarflor can try it out to confirm it's working, then assuming this works for that person we can close this issue.
SgtBatten commented 1 year ago

Thanks for the update mate. Great work

Solarflor commented 1 year ago

ok I will try

Unfortunately it doesn't work

Solarflor commented 1 year ago

OK I FINALLY GO THIS WORKING WOOOOOOOO!

Hi Hamish, how I should change my config file (see above) to solve the problem? Thanks for your help

Solarflor commented 1 year ago

I have changed the configuration as below

` cameras: Piazzale_1: # <------ Name the camera ffmpeg: hwaccel_args: preset-rpi-64-h264 input_args: -tag:v hvc1 inputs:

Solarflor commented 1 year ago

FINALLY IT WORKS sorry, really sorry but my problem was create by a stupid copy and past I did. I added hwaccel_args: preset-rpi-64-h264 although I'm using a Dahua h265 camera. Now I removed it and it works.

Many, many thanks to both of you and really sorry for wasting your time

Hamish1066 commented 1 year ago

Thanks everyone - I'll mark this as closed.