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.78k stars 1.4k forks source link

playback: support serving streams in standard MP4 format #3213

Closed aler9 closed 2 months ago

aler9 commented 3 months ago

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

Cons

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

codecov[bot] commented 2 months ago

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 :warning:
internal/playback/on_get.go 60.52% 11 Missing and 4 partials :warning:
internal/playback/segment_fmp4.go 57.14% 8 Missing and 4 partials :warning:
internal/playback/muxer_fmp4.go 64.28% 4 Missing and 1 partial :warning:
Additional details and impacted files ```diff @@ 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 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

github-actions[bot] commented 2 months ago

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

stardast commented 1 month ago

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 commented 1 month ago

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.