bluenviron / mediamtx

Ready-to-use SRT / WebRTC / RTSP / RTMP / LL-HLS media server and media proxy that allows to read, publish, proxy, record and playback video and audio streams.
MIT License
10.69k stars 1.39k forks source link

Hooks not working (runOnRead,runOnUnread,runOnRecordSegmentCreate,runOnRecordSegmentComplete) #3372

Closed Byorun closed 1 week ago

Byorun commented 1 month ago

Which version are you using?

v1.8.1

Which operating system are you using?

Describe the issue

I am trying to use several hooks in order to automate/track some things of the stream, but several hooks won't get triggered. Only runOnReady and runOnNotReady are working

All scripts are basically the same, only the final webhook url changes

#!/usr/bin/bash

WEBHOOK_URL="https://HOSTNAME/mediamtx/webhook/on-stream-ready"

curl -s -d "{\"MTX_PATH\":\"${1}\", \"MTX_QUERY\":\"${2}\", \"MTX_SOURCE_TYPE\":\"${3}\", \"MTX_SOURCE_ID\":\"${4}\"}" -H "Content-Type: application/json" -X POST $WEBHOOK_UR

If I start a stream the runOnReady hook is triggered (which can be confirmed by the mediamtx log and and the webserver log) If I stop a stream the runOnNotReady hook is triggered (which can be confirmed by the mediamtx log and and the webserver log) The rest does nothing.

Describe how to replicate the issue

  1. start the server
  2. configure external http auth
    authHTTPExclude:
    - action: playback
    - action: read
    - action: api
    - action: metrics
    - action: pprof

    I disabled read and playback auth calls due to heavy server load due to too many auth post requests in case of LL-HLS streams

    paths:
    # example:
    # my_camera:
    #   source: rtsp://my_camera
    "~^livestream/([a-z0-9]+)$":
    record: yes
    runOnReady: /usr/local/bin/mediamtx_on_stream_ready $MTX_PATH $MTX_QUERY $MTX_SOURCE_TYPE $MTX_SOURCE_ID $G1
    runOnNotReady: /usr/local/bin/mediamtx_on_stream_not_ready $MTX_PATH $MTX_QUERY $MTX_SOURCE_TYPE $MTX_SOURCE_ID $G1
    runOnRead: /usr/local/bin/mediamtx_on_stream_read $MTX_PATH $MTX_QUERY $MTX_READER_TYPE $MTX_READER_ID $G1
    runOnUnread: /usr/local/bin/mediamtx_on_stream_unread $MTX_PATH $MTX_QUERY $MTX_READER_TYPE $MTX_READER_ID $G1
    runOnRecordSegmentCreate: /usr/local/bin/mediamtx_on_record_segement_created $MTX_PATH $MTX_SEGMENT_PATH $G1
    runOnRecordSegmentComplete: /usr/local/bin/mediamtx_on_record_segement_completed $MTX_PATH $MTX_SEGMENT_PATH $G1
    # Settings under path "all_others" are applied to all paths that
    # do not match another entry.
    #  all_others:
  3. publish with obs
  4. read with web browser

Did you attach the server logs?

no useful output even on log level debug other than the two lines mentioned above

Did you attach a network dump?

no

irg1008 commented 2 weeks ago

Yep not working for me either

irg1008 commented 1 week ago

It's been a month without this pretty important feature. Does this mean it's not supported anymore, is this lib being abandonded? It's a deal breaker I think...., because the auth call for "ready" is not usable since it calls the url all the time while using LL-HLS....

aler9 commented 1 week ago

All problems reported in this issue are not bugs but misunderstandings about how the server works.

runOnRead : no execution, no logs even on debug (I am trying to capture the current viewer count with that) runOnUnread: no execution, no logs even on debug (I am trying to capture the current viewer count with that)

In HLS there is no concept of reader and it's not technically possible to count readers, as explained in #962

runOnRecordSegmentCreate: [path livestream/byorun] runOnRecordSegmentCreate command launched in logs but the script is not executed runOnRecordSegmentComplete: [path livestream/byorun] runOnRecordSegmentComplete command launched in logs but the script is not executed

you wrote "segement" instead of "segment" in the script name. It's impossible to assert for certainty if this solve your issue since you didn't attach server logs or configuration.

the auth call for "ready" is not usable since it calls the url all the time while using LL-HLS....

The "read" auth call (not the "ready" one which doesn't exist) is called for each HLS request if and only if you configure the server with external HTTP authentication. There are alternative ways to handle authentication, from JWTs to reverse proxies. The JWT method is described in the README.

irg1008 commented 1 week ago

Would be great to have an auth call on client connect, the "read" can bloat the server

aler9 commented 1 week ago

Would be great to have an auth call on client connect, the "read" can bloat the server

as written in the previous post, there is not concept of "client" in HLS. BTW you're completely off topic here, so i'm forced to lock the issue.