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

playback: support serving streams in standard MP4 format #3213

Merged
merged 3 commits into from Apr 14, 2024

Conversation

aler9
Copy link
Member

@aler9 aler9 commented Apr 8, 2024

Description

This PR adds the mp4 (standard MP4) output format to the playback server, in additional to the existing fMP4 (fragmented MP4) output format.

Pros of standard MP4 with respect to fragmented MP4

  • Broader compatibility
  • Duration is explicit
  • Frames with negative DTS are hidden by using the "edit list" feature of MP4, instead of voiding their duration, reducing warnings and errors from some players

Cons

  • Generation is slower

Usage

Add format=mp4 to paths in playback server:

http://localhost:9996/get?path=stream&start=2024-04-07T12%3A57%3A33.808301%2B02%3A00&duration=1147&format=mp4

Nightly binaries

https://github.com/bluenviron/mediamtx/actions/runs/8621626444

TODO

  • sort samples of different tracks by DTS before writing them
  • Tests
  • Documentation

@aler9 aler9 force-pushed the feature/playback-mp4 branch 2 times, most recently from a24b960 to e3a3825 Compare April 8, 2024 22:34
Copy link

codecov bot commented Apr 8, 2024

Codecov Report

Attention: Patch coverage is 34.28571% with 92 lines in your changes are missing coverage. Please review.

Project coverage is 55.87%. Comparing base (665e11a) to head (16baf95).

Files Patch % Lines
internal/playback/muxer_mp4.go 0.00% 60 Missing ⚠️
internal/playback/on_get.go 60.52% 11 Missing and 4 partials ⚠️
internal/playback/segment_fmp4.go 57.14% 8 Missing and 4 partials ⚠️
internal/playback/muxer_fmp4.go 64.28% 4 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3213      +/-   ##
==========================================
- Coverage   56.03%   55.87%   -0.16%     
==========================================
  Files         149      150       +1     
  Lines       17043    17105      +62     
==========================================
+ Hits         9550     9558       +8     
- Misses       6742     6797      +55     
+ Partials      751      750       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@aler9 aler9 force-pushed the feature/playback-mp4 branch 4 times, most recently from ffa7133 to 9c22059 Compare April 9, 2024 20:04
@aler9 aler9 merged commit 4157f49 into main Apr 14, 2024
6 of 8 checks passed
@aler9 aler9 deleted the feature/playback-mp4 branch April 14, 2024 17:29
Copy link
Contributor

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

@stardast
Copy link

Hi, a question about the cons:
What do you mean by "generation is slower"? Is a file created that concatenates all the segments? On disk or in RAM? or is it necessary to read all the segments to get the total size without creating a temporary file? Is the slowness proportional to the length of the requested video?

Thanks,
Paolo

@aler9
Copy link
Member Author

aler9 commented May 24, 2024

What do you mean by "generation is slower"? Is a file created that concatenates all the segments? On disk or in RAM? or is it necessary to read all the segments to get the total size without creating a temporary file? Is the slowness proportional to the length of the requested video?

The slowness is caused by the fact that in standard MP4s there is a single list that contains all samples. Therefore, all segments must be scanned and their samples have to be parsed before the playback file can be served.

Yes, the slowness is proportional to the length of the requested video.

In fragmented MP4 on the other hand there are multiple, small lists of samples, and these are concatenated them together along with the sample content. Therefore, the playback file can be generated as soon as the first segment is scanned.

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.

None yet

2 participants