blakeblackshear / frigate

NVR with realtime local object detection for IP cameras
https://frigate.video
MIT License
18.96k stars 1.73k forks source link

[Support]: MQTT has_clip: true but clip reports "Could not create clip from recordings for front_door." #3873

Closed Rogue136198 closed 2 years ago

Rogue136198 commented 2 years ago

Describe the problem you are having

The issue I'm looking to solve is being able to send a Home Assistant notification as soon as a person is detected then update the notification with a clip once the clip is available.

Right now I see events with "has_clip: true" but when I attempt to access the clip I receive the error "Could not create clip from recordings for front_door." After a few seconds the clip does get generated and is then available but by that time HA has already updated the notification with the URL for the clip but it fails to load the clip.

Version

0.11.0-BE7B858

Frigate config file

{
  "birdseye": {
    "enabled": true,
    "height": 1920,
    "mode": "objects",
    "quality": 1,
    "width": 1080
  },
  "cameras": {
    "backyard": {
      "best_image_timeout": 60,
      "birdseye": {
        "enabled": true,
        "mode": "objects"
      },
      "detect": {
        "enabled": true,
        "fps": 7,
        "height": 480,
        "max_disappeared": 35,
        "stationary": {
          "interval": 0,
          "max_frames": {
            "default": 300,
            "objects": {}
          },
          "threshold": 50
        },
        "width": 640
      },
      "ffmpeg": {
        "global_args": [
          "-hide_banner",
          "-loglevel",
          "warning"
        ],
        "hwaccel_args": "-c:v h264_cuvid",
        "input_args": "-avoid_negative_ts make_zero -fflags nobuffer+genpts+discardcorrupt -flags low_delay -strict experimental -analyzeduration 1000M -probesize 1000M -rw_timeout 5000000",
        "inputs": [
          {
            "global_args": [],
            "hwaccel_args": [],
            "input_args": [],
            "path": "rtmp://10.15.0.132/bcs/channel0_sub.bcs?channel=0&stream=1&user=admin&password=mji89ikm",
            "roles": [
              "record",
              "rtmp",
              "detect"
            ]
          }
        ],
        "output_args": {
          "detect": [
            "-f",
            "rawvideo",
            "-pix_fmt",
            "yuv420p"
          ],
          "record": "-f segment -segment_time 60 -segment_format mp4 -reset_timestamps 1 -strftime 1 -c:v copy -c:a aac",
          "rtmp": [
            "-c",
            "copy",
            "-f",
            "flv"
          ]
        }
      },
      "ffmpeg_cmds": [
        {
          "cmd": "ffmpeg -hide_banner -loglevel warning -c:v h264_cuvid -avoid_negative_ts make_zero -fflags nobuffer+genpts+discardcorrupt -flags low_delay -strict experimental -analyzeduration 1000M -probesize 1000M -rw_timeout 5000000 -i rtmp://10.15.0.132/bcs/channel0_sub.bcs?channel=0&stream=1&user=admin&password=mji89ikm -f segment -segment_time 60 -segment_format mp4 -reset_timestamps 1 -strftime 1 -c:v copy -c:a aac /tmp/cache/backyard-%Y%m%d%H%M%S.mp4 -c copy -f flv rtmp://127.0.0.1/live/backyard -r 7 -s 640x480 -f rawvideo -pix_fmt yuv420p pipe:",
          "roles": [
            "record",
            "rtmp",
            "detect"
          ]
        }
      ],
      "live": {
        "height": 720,
        "quality": 8
      },
      "motion": {
        "contour_area": 30,
        "delta_alpha": 0.2,
        "frame_alpha": 0.2,
        "frame_height": 50,
        "improve_contrast": false,
        "mask": "",
        "mqtt_off_delay": 30,
        "threshold": 25
      },
      "mqtt": {
        "bounding_box": true,
        "crop": true,
        "enabled": true,
        "height": 270,
        "quality": 70,
        "required_zones": [],
        "timestamp": true
      },
      "name": "backyard",
      "objects": {
        "filters": {
          "bicycle": {
            "mask": null,
            "max_area": 24000000,
            "max_ratio": 24000000,
            "min_area": 0,
            "min_ratio": 0,
            "min_score": 0.5,
            "threshold": 0.7
          },
          "bus": {
            "mask": null,
            "max_area": 24000000,
            "max_ratio": 24000000,
            "min_area": 0,
            "min_ratio": 0,
            "min_score": 0.5,
            "threshold": 0.7
          },
          "car": {
            "mask": null,
            "max_area": 24000000,
            "max_ratio": 24000000,
            "min_area": 0,
            "min_ratio": 0,
            "min_score": 0.5,
            "threshold": 0.7
          },
          "cat": {
            "mask": null,
            "max_area": 24000000,
            "max_ratio": 24000000,
            "min_area": 0,
            "min_ratio": 0,
            "min_score": 0.5,
            "threshold": 0.7
          },
          "dog": {
            "mask": null,
            "max_area": 24000000,
            "max_ratio": 24000000,
            "min_area": 0,
            "min_ratio": 0,
            "min_score": 0.5,
            "threshold": 0.7
          },
          "motorcycle": {
            "mask": null,
            "max_area": 24000000,
            "max_ratio": 24000000,
            "min_area": 0,
            "min_ratio": 0,
            "min_score": 0.5,
            "threshold": 0.7
          },
          "person": {
            "mask": null,
            "max_area": 24000000,
            "max_ratio": 24000000,
            "min_area": 1500,
            "min_ratio": 0,
            "min_score": 0.5,
            "threshold": 0.7
          }
        },
        "mask": "",
        "track": [
          "person",
          "car",
          "bicycle",
          "motorcycle",
          "bus",
          "cat",
          "dog"
        ]
      },
      "record": {
        "enabled": true,
        "events": {
          "objects": [
            "person",
            "car",
            "bicycle",
            "motorcycle",
            "bus",
            "cat",
            "dog"
          ],
          "post_capture": 5,
          "pre_capture": 0,
          "required_zones": [],
          "retain": {
            "default": 60,
            "mode": "motion",
            "objects": {}
          }
        },
        "expire_interval": 60,
        "retain": {
          "days": 10,
          "mode": "all"
        },
        "retain_days": null
      },
      "rtmp": {
        "enabled": true
      },
      "snapshots": {
        "bounding_box": false,
        "clean_copy": true,
        "crop": false,
        "enabled": true,
        "height": null,
        "quality": 70,
        "required_zones": [],
        "retain": {
          "default": 60,
          "mode": "motion",
          "objects": {
            "car": 60,
            "person": 60
          }
        },
        "timestamp": false
      },
      "timestamp_style": {
        "color": {
          "blue": 255,
          "green": 255,
          "red": 255
        },
        "effect": null,
        "format": "%m/%d/%Y %H:%M:%S",
        "position": "tl",
        "thickness": 2
      },
      "ui": {
        "dashboard": true,
        "order": 0
      },
      "zones": {}
    },
    "front_door": {
      "best_image_timeout": 60,
      "birdseye": {
        "enabled": true,
        "mode": "objects"
      },
      "detect": {
        "enabled": true,
        "fps": 7,
        "height": 576,
        "max_disappeared": 35,
        "stationary": {
          "interval": 0,
          "max_frames": {
            "default": 300,
            "objects": {}
          },
          "threshold": 50
        },
        "width": 720
      },
      "ffmpeg": {
        "global_args": [
          "-hide_banner",
          "-loglevel",
          "warning"
        ],
        "hwaccel_args": "-c:v h264_cuvid",
        "input_args": [
          "-avoid_negative_ts",
          "make_zero",
          "-fflags",
          "+genpts+discardcorrupt",
          "-rtsp_transport",
          "tcp",
          "-timeout",
          "5000000",
          "-use_wallclock_as_timestamps",
          "1"
        ],
        "inputs": [
          {
            "global_args": [],
            "hwaccel_args": [],
            "input_args": [],
            "path": "rtsp://admin:mji89ikm@10.15.0.131:554/cam/realmonitor?channel=1&subtype=1",
            "roles": [
              "record",
              "rtmp",
              "detect"
            ]
          }
        ],
        "output_args": {
          "detect": [
            "-f",
            "rawvideo",
            "-pix_fmt",
            "yuv420p"
          ],
          "record": "-f segment -segment_time 60 -segment_format mp4 -reset_timestamps 1 -strftime 1 -c:v copy -c:a aac",
          "rtmp": [
            "-c",
            "copy",
            "-f",
            "flv"
          ]
        }
      },
      "ffmpeg_cmds": [
        {
          "cmd": "ffmpeg -hide_banner -loglevel warning -c:v h264_cuvid -avoid_negative_ts make_zero -fflags +genpts+discardcorrupt -rtsp_transport tcp -timeout 5000000 -use_wallclock_as_timestamps 1 -i rtsp://admin:mji89ikm@10.15.0.131:554/cam/realmonitor?channel=1&subtype=1 -f segment -segment_time 60 -segment_format mp4 -reset_timestamps 1 -strftime 1 -c:v copy -c:a aac /tmp/cache/front_door-%Y%m%d%H%M%S.mp4 -c copy -f flv rtmp://127.0.0.1/live/front_door -r 7 -s 720x576 -f rawvideo -pix_fmt yuv420p pipe:",
          "roles": [
            "record",
            "rtmp",
            "detect"
          ]
        }
      ],
      "live": {
        "height": 720,
        "quality": 8
      },
      "motion": {
        "contour_area": 30,
        "delta_alpha": 0.2,
        "frame_alpha": 0.2,
        "frame_height": 50,
        "improve_contrast": false,
        "mask": "",
        "mqtt_off_delay": 30,
        "threshold": 25
      },
      "mqtt": {
        "bounding_box": true,
        "crop": true,
        "enabled": true,
        "height": 270,
        "quality": 70,
        "required_zones": [],
        "timestamp": true
      },
      "name": "front_door",
      "objects": {
        "filters": {
          "bicycle": {
            "mask": null,
            "max_area": 24000000,
            "max_ratio": 24000000,
            "min_area": 0,
            "min_ratio": 0,
            "min_score": 0.5,
            "threshold": 0.7
          },
          "bus": {
            "mask": null,
            "max_area": 24000000,
            "max_ratio": 24000000,
            "min_area": 0,
            "min_ratio": 0,
            "min_score": 0.5,
            "threshold": 0.7
          },
          "car": {
            "mask": null,
            "max_area": 24000000,
            "max_ratio": 24000000,
            "min_area": 0,
            "min_ratio": 0,
            "min_score": 0.5,
            "threshold": 0.7
          },
          "cat": {
            "mask": null,
            "max_area": 24000000,
            "max_ratio": 24000000,
            "min_area": 0,
            "min_ratio": 0,
            "min_score": 0.5,
            "threshold": 0.7
          },
          "dog": {
            "mask": null,
            "max_area": 24000000,
            "max_ratio": 24000000,
            "min_area": 0,
            "min_ratio": 0,
            "min_score": 0.5,
            "threshold": 0.7
          },
          "motorcycle": {
            "mask": null,
            "max_area": 24000000,
            "max_ratio": 24000000,
            "min_area": 0,
            "min_ratio": 0,
            "min_score": 0.5,
            "threshold": 0.7
          },
          "person": {
            "mask": null,
            "max_area": 24000000,
            "max_ratio": 24000000,
            "min_area": 1500,
            "min_ratio": 0,
            "min_score": 0.5,
            "threshold": 0.7
          }
        },
        "mask": "",
        "track": [
          "person",
          "car",
          "bicycle",
          "motorcycle",
          "bus",
          "cat",
          "dog"
        ]
      },
      "record": {
        "enabled": true,
        "events": {
          "objects": [
            "person",
            "car",
            "bicycle",
            "motorcycle",
            "bus",
            "cat",
            "dog"
          ],
          "post_capture": 5,
          "pre_capture": 0,
          "required_zones": [],
          "retain": {
            "default": 60,
            "mode": "motion",
            "objects": {}
          }
        },
        "expire_interval": 60,
        "retain": {
          "days": 10,
          "mode": "all"
        },
        "retain_days": null
      },
      "rtmp": {
        "enabled": true
      },
      "snapshots": {
        "bounding_box": false,
        "clean_copy": true,
        "crop": false,
        "enabled": true,
        "height": null,
        "quality": 70,
        "required_zones": [],
        "retain": {
          "default": 60,
          "mode": "motion",
          "objects": {
            "car": 60,
            "person": 60
          }
        },
        "timestamp": false
      },
      "timestamp_style": {
        "color": {
          "blue": 255,
          "green": 255,
          "red": 255
        },
        "effect": null,
        "format": "%m/%d/%Y %H:%M:%S",
        "position": "tl",
        "thickness": 2
      },
      "ui": {
        "dashboard": true,
        "order": 0
      },
      "zones": {}
    }
  },
  "database": {
    "path": "/media/frigate/frigate.db"
  },
  "detect": {
    "enabled": true,
    "fps": 5,
    "height": 720,
    "max_disappeared": null,
    "stationary": {
      "interval": 0,
      "max_frames": {
        "default": 300,
        "objects": {}
      },
      "threshold": 50
    },
    "width": 1280
  },
  "detectors": {
    "cpu1": {
      "device": "usb",
      "num_threads": 8,
      "type": "cpu"
    }
  },
  "environment_vars": {
    "PLUS_API_KEY": "44cc9543-9425-418b-8b51-164082ed1251:ad49e73cb2b6921ed1303d57f7567176dd4eb8d8"
  },
  "ffmpeg": {
    "global_args": [
      "-hide_banner",
      "-loglevel",
      "warning"
    ],
    "hwaccel_args": "-c:v h264_cuvid",
    "input_args": [
      "-avoid_negative_ts",
      "make_zero",
      "-fflags",
      "+genpts+discardcorrupt",
      "-rtsp_transport",
      "tcp",
      "-timeout",
      "5000000",
      "-use_wallclock_as_timestamps",
      "1"
    ],
    "output_args": {
      "detect": [
        "-f",
        "rawvideo",
        "-pix_fmt",
        "yuv420p"
      ],
      "record": [
        "-f",
        "segment",
        "-segment_time",
        "10",
        "-segment_format",
        "mp4",
        "-reset_timestamps",
        "1",
        "-strftime",
        "1",
        "-c",
        "copy",
        "-an"
      ],
      "rtmp": [
        "-c",
        "copy",
        "-f",
        "flv"
      ]
    }
  },
  "live": {
    "height": 720,
    "quality": 8
  },
  "logger": {
    "default": "info",
    "logs": {}
  },
  "model": {
    "height": 320,
    "labelmap": {},
    "labelmap_path": null,
    "path": null,
    "width": 320
  },
  "motion": null,
  "mqtt": {
    "client_id": "frigate",
    "host": "10.15.1.6",
    "password": null,
    "port": 1883,
    "stats_interval": 60,
    "tls_ca_certs": null,
    "tls_client_cert": null,
    "tls_client_key": null,
    "tls_insecure": null,
    "topic_prefix": "frigate",
    "user": null
  },
  "objects": {
    "filters": {
      "person": {
        "mask": null,
        "max_area": 24000000,
        "max_ratio": 24000000,
        "min_area": 1500,
        "min_ratio": 0,
        "min_score": 0.5,
        "threshold": 0.7
      }
    },
    "mask": "",
    "track": [
      "person",
      "car",
      "bicycle",
      "motorcycle",
      "bus",
      "cat",
      "dog"
    ]
  },
  "plus": {
    "enabled": false
  },
  "record": {
    "enabled": true,
    "events": {
      "objects": [
        "person",
        "car",
        "bicycle",
        "motorcycle",
        "bus",
        "cat",
        "dog"
      ],
      "post_capture": 5,
      "pre_capture": 0,
      "required_zones": [],
      "retain": {
        "default": 60,
        "mode": "motion",
        "objects": {}
      }
    },
    "expire_interval": 60,
    "retain": {
      "days": 10,
      "mode": "all"
    },
    "retain_days": null
  },
  "rtmp": {
    "enabled": true
  },
  "snapshots": {
    "bounding_box": false,
    "clean_copy": true,
    "crop": false,
    "enabled": true,
    "height": null,
    "quality": 70,
    "required_zones": [],
    "retain": {
      "default": 60,
      "mode": "motion",
      "objects": {
        "car": 60,
        "person": 60
      }
    },
    "timestamp": false
  },
  "timestamp_style": {
    "color": {
      "blue": 255,
      "green": 255,
      "red": 255
    },
    "effect": null,
    "format": "%m/%d/%Y %H:%M:%S",
    "position": "tl",
    "thickness": 2
  },
  "ui": {
    "use_experimental": false
  }
}

Relevant log output

N/A

I could not find any relevant logs.

FFprobe output from your camera

# ffprobe version n5.1-2-g915ef932a3-20220731 Copyright (c) 2007-2022 the FFmpeg developers
  built with gcc 12.1.0 (crosstool-NG 1.25.0.55_3defb7b)
  configuration: --prefix=/ffbuild/prefix --pkg-config-flags=--static --pkg-config=pkg-config --cross-prefix=x86_64-ffbuild-linux-gnu- --arch=x86_64 --target-os=linux --enable-gpl --enable-version3 --disable-debug --enable-iconv --enable-libxml2 --enable-zlib --enable-libfreetype --enable-libfribidi --enable-gmp --enable-lzma --enable-fontconfig --enable-libvorbis --enable-opencl --enable-libpulse --enable-libvmaf --enable-libxcb --enable-xlib --enable-amf --enable-libaom --enable-libaribb24 --enable-avisynth --enable-libdav1d --enable-libdavs2 --disable-libfdk-aac --enable-ffnvcodec --enable-cuda-llvm --enable-frei0r --enable-libgme --enable-libass --enable-libbluray --enable-libjxl --enable-libmp3lame --enable-libopus --enable-mbedtls --enable-librist --enable-libtheora --enable-libvpx --enable-libwebp --enable-lv2 --enable-libmfx --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenh264 --enable-libopenjpeg --enable-libopenmpt --enable-librav1e --enable-librubberband --disable-schannel --enable-sdl2 --enable-libsoxr --enable-libsrt --enable-libsvtav1 --enable-libtwolame --enable-libuavs3d --enable-libdrm --enable-vaapi --enable-libvidstab --enable-vulkan --enable-libshaderc --enable-libplacebo --enable-libx264 --enable-libx265 --enable-libxavs2 --enable-libxvid --enable-libzimg --enable-libzvbi --extra-cflags=-DLIBTWOLAME_STATIC --extra-cxxflags= --extra-ldflags=-pthread --extra-ldexeflags=-pie --extra-libs='-ldl -lgomp' --extra-version=20220731
  libavutil      57. 28.100 / 57. 28.100
  libavcodec     59. 37.100 / 59. 37.100
  libavformat    59. 27.100 / 59. 27.100
  libavdevice    59.  7.100 / 59.  7.100
  libavfilter     8. 44.100 /  8. 44.100
  libswscale      6.  7.100 /  6.  7.100
  libswresample   4.  7.100 /  4.  7.100
  libpostproc    56.  6.100 / 56.  6.100

Frigate stats

No response

Operating system

UNRAID

Install method

Docker Compose

Coral version

CPU (no coral)

Network connection

Wired

Camera make and model

Amcrest AD410, Reolink RLC-520

Any other information that may be helpful

I'm wondering if has_clip is working correctly. I would assume it would not be true until the clip is ready. If this is not the case can I receive a recommendation on how to check when the clip is ready so I can use that to trigger adding it to my notification.

NickM-27 commented 2 years ago

has_clip is just a very simple toggle that is essentially saying if recording is currently enabled for this camera.

The easiest way is just to wait until the type: "end" message is fired and then go to show the clip.

blakeblackshear commented 2 years ago

has_clip just means that recording was enabled during the event. You are overriding the default output args and setting segment time to 60 seconds which means it will take much longer for the video to be available. I would recommend setting it to the default of 10 seconds or just removing the output args from your config if you aren't customizing them.

Rogue136198 commented 2 years ago

The easiest way is just to wait until the type: "end" message is fired and then go to show the clip.

I'll give that a try this evening. Thanks

You are overriding the default output args and setting segment time to 60 seconds which means it will take much longer for the video to be available. I would recommend setting it to the default of 10 seconds or just removing the output args from your config if you aren't customizing them.

Yeah, I was just playing with this setting to see what would happen. I had it at the default 10s and it was still not working as I expected.

Rogue136198 commented 2 years ago

Okay, I gave type: "end" a try and while it works it is far less than ideal.

There has to be a way to know when the clip is ready, no?

NickM-27 commented 2 years ago

Okay, I gave type: "end" a try and while it works it is far less than ideal.

There has to be a way to know when the clip is ready, no?

Can you elaborate on what is not ideal? Regardless of whether it is "end" or clip it will be ready at the end of the event so it's not clear what could be better.

In my automation I have a clip get sent as soon as end occurs and it has worked great for many months.

There's also an existing request: https://github.com/blakeblackshear/frigate/issues/2128

Rogue136198 commented 2 years ago

Okay, I gave type: "end" a try and while it works it is far less than ideal. There has to be a way to know when the clip is ready, no?

Can you elaborate on what is not ideal? Regardless of whether it is "end" or clip it will be ready at the end of the event so it's not clear what could be better.

In my automation I have a clip get sent as soon as end occurs and it has worked great for many months.

What is not ideal is often the clip is ready before the "end" of the event. Let's say you have somebody walking up to your front door and ringing the bell. As long as the person is standing there the event will not "end". However the clip would be generated by then. I know the clip would be generated because if I use "update" it would insert the clip before "end" but doing this comes at the cost of using 5-10 notifications out of the 500 permitted daily in the HA app.

There's also an existing request: #2128

It would appear this is right along the same lines as what I am looking for. I would not mind attempting to implement a new flag ("clip_ready") in the MQTT event to specify once the clip is finished recording but I dont know where to start.

NickM-27 commented 2 years ago

From my point of view there's a major problem in what you're describing though. The clip for the event is not finished being processed until the event is over. Any solution which signaled that the clip was finished and ready before the event was over would be incorrect.

yes, a partial clip is available before the event is over, but I don't think we want that flagged as "clip ready" since it would just be a single 10 second segment.

With a segment time of 10 seconds, if you requested the events clip ~10 (might want to wait 12-15 just to be sure) seconds after the event started then it should get the clip you are looking for.

Rogue136198 commented 2 years ago

With a segment time of 10 seconds, if you requested the events clip ~10 (might want to wait 12-15 just to be sure) seconds after the event started then it should get the clip you are looking for.

I'll take this as a decent comprimise.

Thanks for the help