Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

record: set MTX_SEGMENT_DURATION in runOnRecordSegmentComplete #3440

Closed
wants to merge 1 commit into from
Closed

record: set MTX_SEGMENT_DURATION in runOnRecordSegmentComplete #3440

wants to merge 1 commit into from

Conversation

moenodedev
Copy link

@moenodedev moenodedev commented Jun 9, 2024

Provide MTX_SEGMENT_DURATION to the external command in the runOnRecordSegmentComplete hook. The duration of individual segments is useful when creating an HLS playlist.

Issue #2983

@moenodedev moenodedev marked this pull request as draft June 9, 2024 19:09
@moenodedev
Copy link
Author

moenodedev commented Jun 9, 2024

mediamtx.yml

pathDefaults:
  recordPartDuration: 500ms
  recordSegmentDuration: 1500ms  
  runOnRecordSegmentCreate: echo "path '$MTX_SEGMENT_PATH' duration '$MTX_SEGMENT_DURATION'"
  runOnRecordSegmentComplete: echo "$MTX_SEGMENT_PATH $MTX_SEGMENT_DURATION"

output

2024/06/09 18:03:57 INF [path skycam] runOnRecordSegmentCreate command launched
path './recordings/skycam/2024-06-09_18-03-57-411937.mp4' duration ''

2024/06/09 18:04:00 INF [path skycam] runOnRecordSegmentComplete command launched
path './recordings/skycam/2024-06-09_18-03-57-411937.mp4' duration '1.5'

@moenodedev moenodedev marked this pull request as ready for review June 9, 2024 19:57
@moenodedev moenodedev changed the title Set MTX_SEGMENT_DURATION in runOnRecordSegmentComplete record: set MTX_SEGMENT_DURATION in runOnRecordSegmentComplete Jun 9, 2024
@moenodedev
Copy link
Author

The duration is also useful for monitoring

mediamtx.yml

pathDefaults:
  runOnRecordSegmentComplete: sh notify.sh "$MTX_SEGMENT_PATH" "$MTX_SEGMENT_DURATION"

notify.sh

#!/bin/bash

PATH=$1
DURATION=$2

if [ -z "$DURATION" ]; then
  echo "ERROR $PATH duration is blank"
  exit 2
elif [ $(echo "$DURATION < 10.0" | /usr/bin/bc) -ne 0 ]; then
  echo "WARNING $PATH duration is < 10.0"
  exit 1
fi

echo "SUCCESS $PATH duration is >= 10.0"
exit 0

output

2024/06/09 18:45:53 INF [path skycam] runOnRecordSegmentComplete command launched
WARNING ./recordings/skycam/2024-06-09_18-45-51-084911.mp4 duration is < 10.0

@moenodedev moenodedev marked this pull request as draft June 9, 2024 20:47
@moenodedev moenodedev marked this pull request as ready for review June 9, 2024 20:47
@aler9
Copy link
Member

aler9 commented Jun 11, 2024

Hello, while the idea is good, this is implemented in a wrong way since MTX_SEGMENT_DURATION doesn't contain the real segment duration, but the maximum segment duration defined in the configuration.

@aler9
Copy link
Member

aler9 commented Jun 11, 2024

replaced by #3456

@moenodedev
Copy link
Author

Thank you!

aler9 added a commit that referenced this pull request Jun 11, 2024
) (#3456)

* improve tests

* add duration to OnSegmentComplete

* expose MTX_SEGMENT_DURATION to runOnRecordSegmentComplete

* add tests
Copy link
Contributor

This issue is mentioned in release v1.8.3 🚀
Check out the entire changelog by clicking here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants