Repository navigation
Conversation
Every recorded MP4 segment is finalised with movflags=+faststart, which re-reads the whole segment and re-writes it with the moov atom at the front. On network storage this roughly triples the I/O: measured on a 41-camera site recording ~8.7 MB/s to a single-disk NFS share, the NAS saw ~15 MB/s of writes plus ~13.6 MB/s of reads, and playback reads slowed to 3-8 MB/s. Add [storage] mp4_faststart (default true, the current behaviour) so a site recording to a NAS or slow HDD can skip the rewrite. Players that use HTTP range requests, including the web UI, play either layout. The option is read from and written back to the ini, exposed in the settings API, and applies to segments opened after a change. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
The live update has a data race and some MP4 muxing paths still enable faststart unconditionally.
2 open findings
What changed in this PR
Adds configurable MP4 faststart behavior to reduce storage I/O while preserving the existing default.
Changes:
- Adds and persists
[storage] mp4_faststart. - Exposes the option through the settings API.
- Conditionally enables FFmpeg
+faststartand adds configuration tests.
| File | Description |
|---|---|
tests/unit/test_config.c |
Tests default, loading, and persistence. |
src/web/api_handlers_settings.c |
Exposes and updates the setting. |
src/video/mp4_writer_utils.c |
Makes faststart conditional. |
src/video/mp4_segment_recorder.c |
Makes segment faststart conditional. |
src/core/config.c |
Loads, saves, and prints the option. |
include/core/config.h |
Adds the configuration field. |
docs/CONFIGURATION.md |
Documents the option. |
config/lightnvr.ini |
Adds the default setting. |
🧠 Review effort: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| // MP4 faststart (applies to segments opened after the change) | ||
| cJSON *mp4_faststart = cJSON_GetObjectItem(settings, "mp4_faststart"); | ||
| if (mp4_faststart && cJSON_IsBool(mp4_faststart)) { | ||
| g_config.mp4_faststart = cJSON_IsTrue(mp4_faststart); |
| camera was permanently deleted; per-camera overrides still apply, and | ||
| protected recordings are never expired by age. | ||
| - `auto_delete_oldest`: Whether to automatically delete the oldest recordings when storage is full | ||
| - `mp4_faststart`: Whether to rewrite each finished MP4 segment with its index (moov) at the front (default `true`). The rewrite re-reads and re-writes the whole segment, which roughly triples I/O on network storage (NFS/SMB) or a slow HDD; players that use HTTP range requests play either layout, so set `false` when recording to a NAS. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


Every recorded MP4 segment is finalised with movflags=+faststart, which re-reads the whole segment and re-writes it with the moov atom at the front. On network storage this roughly triples the I/O: measured on a 41-camera site recording ~8.7 MB/s to a single-disk NFS share, the NAS saw ~15 MB/s of writes plus ~13.6 MB/s of reads, and playback reads slowed to 3-8 MB/s.
Add [storage] mp4_faststart (default true, the current behaviour) so a site recording to a NAS or slow HDD can skip the rewrite. Players that use HTTP range requests, including the web UI, play either layout. The option is read from and written back to the ini, exposed in the settings API, and applies to segments opened after a change.