home-assistant / android

:iphone: Home Assistant Companion for Android
https://companion.home-assistant.io/
Apache License 2.0
2.26k stars 628 forks source link

Problem with video in notify #3470

Open Henrik1986 opened 1 year ago

Henrik1986 commented 1 year ago

Home Assistant Android app version(s): beta-9876-e592c334-full

Android version(s): 13

Device model(s): Pixel 6 Pro

Home Assistant version: Home Assistant 2023.3.6

Last working Home Assistant release (if known): Never

Description of problem, include YAML if issue is related to notifications:

I want to attach a video in a message. I use this code to create a video when the front door opens and the alarm is on.

  - service: camera.record
    target:
      entity_id: "camera.grovkok"
    data:
      filename: '/media/cctv_grovkok/video.mp4'
      duration: 30

That works perfect and I get a video when I trigger it. Then I use this code to send the video to my android phone. I have a delay so the video will stored.

  - delay:
      seconds: 59
  - service: notify.mobile_app_pixel_6_pro
    data:
      message: Någon kom in
      data:
        url: "/lovelace/camera"
        priority: high
        video: '/media/local/cctv_grovkok/video.mp4'

I get the message but no video. The logg shows this.

04-10 18:22:55.647 10826 10826 D MessagingService: Found 0 frames for video notification
04-10 18:22:55.650 10826 10826 D MessagingService: Show notification with tag "null" and id "1811561647"

If I convert the video on the internet and put I back in the same folder and trigger the automation I get the video in the message. I converted the file from mp4 to mp4. Logg show this.

04-10 18:47:57.030 10826 10826 D MessagingService: Found 19 frames for video notification
04-10 18:47:57.064 10826 10826 D MessagingService: Show notification with tag "null" and id "1812946270"

Companion App Logs: I get the message but no video. The logg shows this.

04-10 18:22:55.647 10826 10826 D MessagingService: Found 0 frames for video notification
04-10 18:22:55.650 10826 10826 D MessagingService: Show notification with tag "null" and id "1811561647"

If I convert the video on the internet and put I back in the same folder and trigger the automation I get the video in the message. I converted the file from mp4 to mp4. Logg show this.

04-10 18:47:57.030 10826 10826 D MessagingService: Found 19 frames for video notification
04-10 18:47:57.064 10826 10826 D MessagingService: Show notification with tag "null" and id "1812946270"

Screenshot or video of problem:

Additional information:

dshokouhi commented 1 year ago

Please do not delete the issue template, all requested information is required to help you out. Please restore the template and fill out all requested data.

Henrik1986 commented 1 year ago

Done!

dshokouhi commented 1 year ago

Thanks are you by chance able to attach example videos of one working and the other that is not? That will be helpful in troubleshooting the issue.

jpelgrom commented 1 year ago

If I convert the video on the internet (...) I get the video in the message

This also sounds like a codec or resolution issue. If you're unable to provide a sample, more technical information about the video before and after conversion would be helpful.

javiromero commented 1 year ago

Experiencing the same issue described in the ticket: video file generated using camera.record service and pushed using notify service. Both from Reolink cameras (different models though)

Sharing two video files in case it helps debugging the problem


- converted
- works
- https://user-images.githubusercontent.com/385944/232806069-064a5449-7c62-40e3-9336-b745222708d5.mp4

```bash
ffprobe converted-recording.mp4 
ffprobe version 4.4.3-0ubuntu1~20.04.sav1 Copyright (c) 2007-2022 the FFmpeg developers
  built with gcc 9 (Ubuntu 9.4.0-1ubuntu1~20.04.1)
  configuration: --prefix=/usr --extra-version='0ubuntu1~20.04.sav1' --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --arch=amd64 --enable-gpl --disable-stripping --enable-gnutls --enable-ladspa --enable-libaom --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libcodec2 --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libjack --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librabbitmq --enable-librubberband --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libsrt --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzmq --enable-libzvbi --enable-lv2 --enable-omx --enable-openal --enable-opencl --enable-opengl --enable-sdl2 --enable-pocketsphinx --enable-librsvg --enable-libdav1d --enable-librist --enable-libvmaf --enable-libzimg --enable-crystalhd --enable-libmfx --enable-libsvtav1 --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-chromaprint --enable-frei0r --enable-libx264 --enable-librav1e --enable-shared
  libavutil      56. 70.100 / 56. 70.100
  libavcodec     58.134.100 / 58.134.100
  libavformat    58. 76.100 / 58. 76.100
  libavdevice    58. 13.100 / 58. 13.100
  libavfilter     7.110.100 /  7.110.100
  libswscale      5.  9.100 /  5.  9.100
  libswresample   3.  9.100 /  3.  9.100
  libpostproc    55.  9.100 / 55.  9.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'converted-recording.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf59.27.100
  Duration: 00:00:10.96, start: 0.000000, bitrate: 1056 kb/s
  Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1536x576, 993 kb/s, 25 fps, 25 tbr, 12800 tbn, 50 tbc (default)
    Metadata:
      handler_name    : VideoHandler
      vendor_id       : [0][0][0][0]
      encoder         : Lavc59.37.100 libx264
  Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 16000 Hz, mono, fltp, 63 kb/s (default)
    Metadata:
      handler_name    : SoundHandler
      vendor_id       : [0][0][0][0]
willhaggan commented 1 year ago

is it something top do with the frame rate? I have came across the same problem from a tapo camera recording

Ceralor commented 1 year ago

Chiming in that I'm having the same issue. Likewise, zero frames in the app log. FFProbe shows:

Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '\\homeassistant.local\media\front_door\clip.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso6iso2avc1mp41
    encoder         : Lavf59.16.100
  Duration: 00:00:16.60, start: 0.000000, bitrate: 1007 kb/s
  Stream #0:0(und): Video: h264 (Main) (avc1 / 0x31637661), yuv420p, 640x360, 1004 kb/s, 25 fps, 25 tbr, 90k tbn, 50 tbc (default)
    Metadata:
      handler_name    : VideoHandler
      vendor_id       : [0][0][0][0]

EDIT: This is using the same camera.record call to create the clip first, except my camera's native FPS is 25.

EDIT 2: I was able to just run ffmpeg -i clip.mp4 clip_test.mp4 and send clip_test.mp4 and it worked fine. The heck.

Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '\\homeassistant.local\media\front_door\clip_test.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf58.76.100
  Duration: 00:00:11.21, start: 0.000000, bitrate: 101 kb/s
  Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 640x360, 99 kb/s, 15.17 fps, 15.17 tbr, 11648 tbn, 30.33 tbc (default)
    Metadata:
      handler_name    : VideoHandler
      vendor_id       : [0][0][0][0]
jpelgrom commented 1 year ago

Testing with the bugged recording that was provided, logs suggest metadata is missing or cannot be parsed by Android. One item specifically reads:

2023-05-16 19:58:09.003  1287-2613  MPEG4Extractor          media.extractor                      E  No width or height, assuming worst case 1080p

Video duration as extracted is 0ms, which is why it isn't adding any video frames to the notification. When I edit the code to hardcode a >0 duration, it is able to extract the first frame, but not any later frames.

The only major difference in your output appears to be that compatible_brands includes iso6.

If Android's metadata retriever returns that it is unable to get the duration, the app will use a 'backup duration' of 7 seconds and try to get at least a few frames. Would that be reasonable to use if the duration is 0 as well? (to display one frame instead of nothing)

Henrik1986 commented 1 year ago

Some progress?

dshokouhi commented 1 year ago

Some progress? @dshokouhi

Please don't tag people asking for updates

ReX1983 commented 9 months ago

Is this still an issue? Found the same problem with the Reolink Doorbell (the video is recorded but it is not displayed in the notification).

zagielek commented 9 months ago

I've just notice the same issue with my TP Link tapo camera. I'm unable to send the video in notification. I'm able to send an snapshot without issues ( using path image: '/local/snapshots/testsnapshot.jpg' ) When I download the /config/www/snapshots/testvideo.mp4 from home assistant to my PC, I can play it without issues.

Andoird 13.0 OnePlus Nord 2 Home Assistant mobile app version: 2023.10.2-full

Tapo C320WS f/w: 1.1.6

Home Assistant:

HACS: 1.33.0 Tapo: Cameras Control: 5.4.12

- alias: test_video_notification
  initial_state: true
  trigger:
    - platform: state
      entity_id: input_boolean.test6
      to: "on"
  action:
    - service: camera.record
      data:
        entity_id: camera.tpcam_hd_stream
        filename: "/config/www/snapshots/testvideo.mp4"
        duration: 5
        #lookback: 3
    - service: notify.mobile_app_1
      data:
        message: "Test message"
        data:
          video: /local/snapshots/testvideo.mp4
          notification_icon: mdi:bell-alert
          sticky: 'true'
    - service: input_boolean.turn_off
      entity_id: input_boolean.test6
$ ffprobe testvideo.mp4 
ffprobe version 4.4.2-0ubuntu0.22.04.1 Copyright (c) 2007-2021 the FFmpeg developers
  built with gcc 11 (Ubuntu 11.2.0-19ubuntu1)
  configuration: --prefix=/usr --extra-version=0ubuntu0.22.04.1 --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --arch=amd64 --enable-gpl --disable-stripping --enable-gnutls --enable-ladspa --enable-libaom --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libcodec2 --enable-libdav1d --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libjack --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librabbitmq --enable-librubberband --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libsrt --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzimg --enable-libzmq --enable-libzvbi --enable-lv2 --enable-omx --enable-openal --enable-opencl --enable-opengl --enable-sdl2 --enable-pocketsphinx --enable-librsvg --enable-libmfx --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-chromaprint --enable-frei0r --enable-libx264 --enable-shared
  libavutil      56. 70.100 / 56. 70.100
  libavcodec     58.134.100 / 58.134.100
  libavformat    58. 76.100 / 58. 76.100
  libavdevice    58. 13.100 / 58. 13.100
  libavfilter     7.110.100 /  7.110.100
  libswscale      5.  9.100 /  5.  9.100
  libswresample   3.  9.100 /  3.  9.100
  libpostproc    55.  9.100 / 55.  9.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'testvideo.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso6iso2avc1mp41
    encoder         : Lavf59.27.100
  Duration: 00:00:05.38, start: 0.000000, bitrate: 213 kb/s
  Stream #0:0(und): Video: h264 (Main) (avc1 / 0x31637661), yuvj420p(pc), 2560x1440, 210 kb/s, 15.05 fps, 20 tbr, 90k tbn, 30 tbc (default)
    Metadata:
      handler_name    : VideoHandler
      vendor_id       : [0][0][0][0]
creeve4 commented 8 months ago

I am also experiencing this issue.

Home Assistant Android app version(s): 2023.12.4-full

Android version(s): 11

Device model(s): Pixel 4a

Home Assistant version: Home Assistant 2023.12.4

I am using the Reolink Video Doorbell Wifi to record the video. If I re-encode the original video with ffmpeg and then send it, it works correctly.

Related log entries from the companion app:

01-04 10:40:20.486  7258  7258 D MessagingService: Creating notification with following data: {group=Doorbell, title=Motion Detected, video=/local/tmp/video.mp4, webhook_id=b210cc02e6221550f03908706373f1be0817155e697a817e6c5501f0fb874fb8, channel=Doorbell, clickAction=noAction, message=Front door 10:40 AM, importance=max, server_id=2}
01-04 10:40:20.498  7258  7258 D ServerConnectionInfo: localUrl is: true, usesInternalSsid is: false, usesWifi is: false
01-04 10:40:20.499  7258  7258 D ServerConnectionInfo: Using cloud / remote UI URL
01-04 10:40:20.503  7258 10095 D ServerConnectionInfo: localUrl is: true, usesInternalSsid is: false, usesWifi is: false
01-04 10:40:20.503  7258 10095 D ServerConnectionInfo: Using cloud / remote UI URL
01-04 10:40:22.021  7258  7258 D MessagingService: Found 0 frames for video notification
01-04 10:40:22.024  7258  7258 D MessagingService: Show notification with tag "null" and id "-711996033"

Below is my automation:

alias: Doorbell Motion Video
description: ""
trigger:
  - platform: state
    entity_id:
      - binary_sensor.doorbell_person
    from: "off"
    to: "on"
    for:
      hours: 0
      minutes: 0
      seconds: 0
action:
  - service: camera.record
    target:
      device_id: []
      area_id: []
      entity_id: camera.doorbell_fluent
    data:
      filename: /config/www/tmp/video.mp4
      lookback: 3
      duration: 7
  - delay:
      hours: 0
      minutes: 0
      seconds: 5
      milliseconds: 0
  - service: notify.mobile_app_chris
    data:
      message: Front door {{ now().strftime('%-I:%M %p') }}
      title: Motion Detected
      data:
        channel: Doorbell
        importance: max
        group: Doorbell
        video: /local/tmp/video.mp4
        ttl: 0
        priority: high
        clickAction: noAction
mode: single

Media Info for the original recording:

Format                                   : MPEG-4
Format profile                           : Base Media
Codec ID                                 : isom (isom/iso6/iso2/avc1/mp41)
File size                                : 506 KiB
Duration                                 : 7 s 90 ms
Overall bit rate                         : 585 kb/s
Frame rate                               : 15.000 FPS
Writing application                      : Lavf59.27.100

Video
ID                                       : 1
Format                                   : AVC
Format/Info                              : Advanced Video Codec
Format profile                           : High@L5.1
Format settings                          : CABAC / 1 Ref Frames
Format settings, CABAC                   : Yes
Format settings, Reference frames        : 1 frame
Format settings, GOP                     : M=1, N=15
Codec ID                                 : avc1
Codec ID/Info                            : Advanced Video Coding
Duration                                 : 7 s 1 ms
Bit rate                                 : 524 kb/s
Maximum bit rate                         : 451 kb/s
Width                                    : 640 pixels
Height                                   : 480 pixels
Display aspect ratio                     : 4:3
Frame rate mode                          : Variable
Frame rate                               : 15.000 FPS
Minimum frame rate                       : 7.834 FPS
Maximum frame rate                       : 666.667 FPS
Color space                              : YUV
Chroma subsampling                       : 4:2:0
Bit depth                                : 8 bits
Scan type                                : Progressive
Bits/(Pixel*Frame)                       : 0.114
Stream size                              : 448 KiB (89%)
Codec configuration box                  : avcC

Audio
ID                                       : 2
Format                                   : AAC LC
Format/Info                              : Advanced Audio Codec Low Complexity
Codec ID                                 : mp4a-40-2
Duration                                 : 7 s 90 ms
Bit rate mode                            : Constant
Nominal bit rate                         : 53.7 kb/s
Maximum bit rate                         : 53.7 kb/s
Channel(s)                               : 1 channel
Channel layout                           : M
Sampling rate                            : 16.0 kHz
Frame rate                               : 15.625 FPS (1024 SPF)
Compression mode                         : Lossy
Default                                  : Yes
Alternate group                          : 1

Media Info for the re-encoded (ffmpeg) recording:

Format                                   : MPEG-4
Format profile                           : Base Media
Codec ID                                 : isom (isom/iso2/avc1/mp41)
File size                                : 562 KiB
Duration                                 : 7 s 91 ms
Overall bit rate mode                    : Variable
Overall bit rate                         : 649 kb/s
Frame rate                               : 15.000 FPS
Writing application                      : Lavf60.3.100

Video
ID                                       : 1
Format                                   : AVC
Format/Info                              : Advanced Video Codec
Format profile                           : High@L2.2
Format settings                          : CABAC / 4 Ref Frames
Format settings, CABAC                   : Yes
Format settings, Reference frames        : 4 frames
Codec ID                                 : avc1
Codec ID/Info                            : Advanced Video Coding
Duration                                 : 7 s 67 ms
Bit rate                                 : 594 kb/s
Width                                    : 640 pixels
Height                                   : 480 pixels
Display aspect ratio                     : 4:3
Frame rate mode                          : Constant
Frame rate                               : 15.000 FPS
Color space                              : YUV
Chroma subsampling                       : 4:2:0
Bit depth                                : 8 bits
Scan type                                : Progressive
Bits/(Pixel*Frame)                       : 0.129
Stream size                              : 513 KiB (91%)
Writing library                          : x264 core 164
Encoding settings                        : cabac=1 / ref=3 / deblock=1:0:0 / analyse=0x3:0x113 / me=hex / subme=7 / psy=1 / psy_rd=1.00:0.00 / mixed_ref=1 / me_range=16 / chroma_me=1 / trellis=1 / 8x8dct=1 / cqm=0 / deadzone=21,11 / fast_pskip=1 / chroma_qp_offset=-2 / threads=6 / lookahead_threads=1 / sliced_threads=0 / nr=0 / decimate=1 / interlaced=0 / bluray_compat=0 / constrained_intra=0 / bframes=3 / b_pyramid=2 / b_adapt=1 / b_bias=0 / direct=1 / weightb=1 / open_gop=0 / weightp=2 / keyint=250 / keyint_min=15 / scenecut=40 / intra_refresh=0 / rc_lookahead=40 / rc=crf / mbtree=1 / crf=23.0 / qcomp=0.60 / qpmin=0 / qpmax=69 / qpstep=4 / ip_ratio=1.40 / aq=1:1.00
Codec configuration box                  : avcC

Audio
ID                                       : 2
Format                                   : AAC LC
Format/Info                              : Advanced Audio Codec Low Complexity
Codec ID                                 : mp4a-40-2
Duration                                 : 7 s 91 ms
Source duration                          : 7 s 154 ms
Bit rate mode                            : Variable
Bit rate                                 : 50.9 kb/s
Maximum bit rate                         : 69.0 kb/s
Channel(s)                               : 1 channel
Channel layout                           : M
Sampling rate                            : 16.0 kHz
Frame rate                               : 15.625 FPS (1024 SPF)
Compression mode                         : Lossy
Stream size                              : 44.1 KiB (8%)
Source stream size                       : 44.4 KiB (8%)
Default                                  : Yes
Alternate group                          : 1
deezid commented 3 months ago

Same here, no video shown in messages on Android. The converted video via ffmpeg sends perfectly fine though... Weird.

m90att commented 2 months ago

Same here