Skip to content

feat(storage): make MP4 faststart configurable ([storage] mp4_faststart) - #633

Open
hotkhwan wants to merge 1 commit into
opensensor:mainfrom
hotkhwan:mp4-faststart-config
Open

hotkhwan wants to merge 1 commit into
opensensor:mainfrom
hotkhwan:mp4-faststart-config

Conversation

@hotkhwan

@hotkhwan hotkhwan commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

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.

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>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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 +faststart and 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);
Comment thread docs/CONFIGURATION.md
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.
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