Camera using ffmpeg platform and drawtext overlay showing on snapshot but not recording

I have a camera:

  - platform: ffmpeg
    name: security_camera
    input: -rtsp_transport tcp -i rtsp://securitypi.local:8554/unicast
    extra_arguments: >-
      -vf "hue=s=0, drawtext=fontfile=/usr/share/fonts/truetype/dejavu/DejaVuSans-Bold.ttf:text='%{localtime\:%Y-%m-%d %T}':[email protected]:x=10:y=10"

I’ve added the drawtext filter recently (in extra_arguments). What stumps me is that snapshops (and the live still view) contain the overlay, but the recordings (and live stream) don’t. The only thing I can imagine is that the snapshot and record services follow different code paths or that there is a bug in the underlying haffmpeg library. I’ve been reading the code to understand this better, but my current knowledge falls short in order to put all the pieces together. I can see the extra_arguments is supported by the haffmpeg library. What am I missing that this isn’t working as expected?

Screenshot 2021-12-28 at 16.24.25

These are my scripts:

  mode: queued
    - service: camera.record
        entity_id: camera.security_camera
        filename: '/tmp/camera.security_camera_{{ now().strftime("%Y%m%d-%H%M%S") }}.mp4'
        duration: 10
    - delay: "00:00:15"
    - service: shell_command.copy_last_video_clip
    - service: input_datetime.set_datetime
      entity_id: input_datetime.security_camera_last_clip
        datetime: "{{ now() }}"

  mode: queued
    - service: camera.snapshot
        entity_id: camera.security_camera
        filename: '/tmp/camera.security_camera_{{ now().strftime("%Y%m%d-%H%M%S") }}.jpg'
    - service: input_datetime.set_datetime
      entity_id: input_datetime.security_camera_last_snapshot
        datetime: "{{ now() }}"
    - service: shell_command.copy_last_snapshot_image
    - condition: state
      entity_id: group.security_automations
      state: "on"
    - service:
        title: Security Camera
        message: "Motion detected!"
          group: "security-camera-snapshots"
            url: !secret security_camera_last_snapshot_url

A second observation is that the ffmpeg camera state is never anything but idle (even when recording). It seems like the ffmpeg platform never sets the state in code (not explicitly). If this gets supported, I can get rid of the delay I’m using above.

Posted on a related thread previously: Camera with rtmp stream - #7 by parautenbach.

Ok, at last I’m finding more info on this (after researching it again after many months):

When you click on a picture card in the UI, it starts a stream object, not the ffmpeg command that you’ve set up in configuration.

This seems to be true when one captures a stream to file too.

The suggested workaround to use a proxy is partly working: I’m getting my overlay, but when opening the live camera view, the image is enormous (need to pan) and the quality seems drastically lower (but it may be due to the apparent upscaling). It seems there’s a bug in trying to control the stream quality.

Next learning: You cannot record from this proxy camera – which puts me right back at square one: I want the overlay when viewing the stream and when recording it (i.e. always).

I just learned this the hard way, after going through the steps to implement.
I believe there should be somewhere in the documentations explaining why and when can the service camera.record work and when not…

So far i’ve only been able to use the record service with an ONVIF-based camera. Try to setup your camera with such feed and retry.

Good idea. I recently set up another camera using ONVIF. Pretty sure this will work, thanks! I’ll post my feedback.

1 Like