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

implement native recording (#1399) #2255

Merged
merged 9 commits into from
Sep 16, 2023
Merged

implement native recording (#1399) #2255

merged 9 commits into from
Sep 16, 2023

Conversation

aler9
Copy link
Member

@aler9 aler9 commented Aug 27, 2023

Fixes #1399

TODO

  • support AV1 tracks
  • support VP9 tracks
  • [ ] support VP8 tracks
  • support H265 tracks
  • support H264 tracks
  • support MPEG-4 video tracks
  • support MPEG-1 video tracks
    * [ ] support M-JPEG tracks
  • support Opus tracks
  • support MPEG-4 audio tracks
  • support MPEG-1 audio tracks
    * [ ] support G722 tracks
    * [ ] support G711 tracks
    * [ ] support LPCM tracks
  • ability to disable cleaner
  • ability to disable recording for some paths
  • add tests

Usage

The recording format is fMP4, since it satisfies most requirements:

  • it is fault tolerant
  • it can be read by most players and browsers

All parameters are in the configuration file:

# Record streams to disk.
record: no
# Path of recording segments.
# Extension is added automatically.
# Available variables are %path (path name), %Y %m %d %H %M %S (time in strftime format)
recordPath: ./recordings/%path/%Y-%m-%d_%H-%M-%S
# Format of recorded segments.
# Currently the only available format is fmp4 (fragmented MP4).
recordFormat: fmp4
# fMP4 files are concatenation of small MP4 files (parts), each with this duration.
# When a system failure occurs, the last part of a recording is lost.
# Therefore, the part duration is equal to the RPO (recovery point objective).
# Increasing it decreases segment size, decreasing it decreases the RPO.
recordPartDuration: 100ms
# Minimum duration of each segment.
recordSegmentDuration: 1h
# Delete segments after this threshold.
recordDeleteAfter: 24h

Nightly binaries

[link removed]

@codecov
Copy link

codecov bot commented Aug 27, 2023

Codecov Report

Merging #2255 (b9c2635) into main (b7e7758) will decrease coverage by 0.45%.
The diff coverage is 53.59%.

@@            Coverage Diff             @@
##             main    #2255      +/-   ##
==========================================
- Coverage   60.44%   59.99%   -0.45%     
==========================================
  Files         120      126       +6     
  Lines       13351    14314     +963     
==========================================
+ Hits         8070     8588     +518     
- Misses       4661     5074     +413     
- Partials      620      652      +32     
Files Changed Coverage Δ
internal/conf/path.go 25.00% <ø> (ø)
internal/core/srt_conn.go 42.71% <0.00%> (-1.47%) ⬇️
internal/record/agent.go 36.31% <36.31%> (ø)
internal/core/path.go 72.29% <37.50%> (-1.37%) ⬇️
internal/core/core.go 83.69% <57.69%> (-1.17%) ⬇️
internal/core/webrtc_outgoing_track.go 25.09% <66.66%> (+0.45%) ⬆️
internal/record/segment.go 67.69% <67.69%> (ø)
internal/conf/conf.go 76.00% <70.00%> (-0.28%) ⬇️
internal/record/track.go 81.25% <81.25%> (ø)
internal/record/cleaner.go 87.65% <87.65%> (ø)
... and 3 more

... and 3 files with indirect coverage changes

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@pikachu937
Copy link

Greetings.

A very joyful and significant event. But still, I would like to clarify whether you plan to implement not only fmp4, but also mpegts format, as well as the ability to turn off the audio track, balance recording between mount points (save video files) and the ability to disable recording for some streams?

Thank you, you are the best.

@pikachu937
Copy link

pikachu937 commented Aug 27, 2023

I forgot to ask about the parameter:

recordDeleteAfter: 24h

How to disable deletion?
Thank you.

@aler9 aler9 force-pushed the feature/record branch 2 times, most recently from b436384 to 2eef77e Compare August 30, 2023 09:02
aler9 added a commit that referenced this pull request Aug 30, 2023
@aler9 aler9 added the enhancement New feature or request label Sep 1, 2023
@aler9 aler9 force-pushed the feature/record branch 2 times, most recently from 1fdde23 to 0e10a8c Compare September 2, 2023 20:36
@aler9
Copy link
Member Author

aler9 commented Sep 10, 2023

Hello @pikachu937,

you plan to implement not only fmp4, but also mpegts format

MPEG-TS support can be added in the future, by me or by anyone else through a PR. I chose to focus on fMP4 because it's browser-compatible (while MPEG-TS is not) and since the next step is developing playback API, i would like this API to return browser-compatible videos.

the ability to turn off the audio track

No. If you want to remove audio, you can create a reader that reads from a path, removes audio and republishes the stream to another path.

balance recording between mount points

No, load balancing can be achieved by using multiple instances of the server, while fauly tolerancy can be achieved by deploying the server inside Kubernetes with a storage plugin like Longhorn or GlusterFS or a hardware solution like a SAN. Nowadays load balancing and fault tolerancy are delegated to the infrastructure (K8s), there's no need to natively implement them.

ability to disable recording for some streams

yes, this will be done. The recording system is centralized in order clean up expired recordings regardless of the fact that a path is running or not.

How to disable deletion

we can also add this, even though i don't recommend it.

@pikachu937
Copy link

Hello

MPEG-TS support can be added in the future, by me or by anyone else through a PR. I chose to focus on fMP4 because it's browser-compatible (while MPEG-TS is not) and since the next step is developing playback API, i would like this API to return browser-compatible videos.

it would be very nice to see the implementation of mpegts

No. If you want to remove audio, you can create a reader that reads from a path, removes audio and republishes the stream to another path.

I asked about turning off the audio track when saving, and not when broadcasting.

No, load balancing can be achieved by using multiple instances of the server, while fauly tolerancy can be achieved by deploying the server inside Kubernetes with a storage plugin like Longhorn or GlusterFS or a hardware solution like a SAN. Nowadays load balancing and fault tolerancy are delegated to the infrastructure (K8s), there's no need to natively implement them.

hmm... you propose to outsource this function, but it will work many times faster if implemented (inside the server)

we can also add this, even though i don't recommend it.

I keep records from 7 to 60 days and I myself regulate when to delete them

Will you implement adding work with a database to save metadata on records?

@aler9 aler9 force-pushed the feature/record branch 7 times, most recently from 568f562 to 99573e3 Compare September 16, 2023 11:31
@aler9 aler9 merged commit 73ddb21 into main Sep 16, 2023
6 of 8 checks passed
@aler9 aler9 deleted the feature/record branch September 16, 2023 15:27
@aler9 aler9 mentioned this pull request Sep 18, 2023
3 tasks
@github-actions github-actions bot locked and limited conversation to collaborators Mar 29, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement native stream recording into the server
2 participants