# Fragment MP4 for Streaming

Convert a progressive MP4 into a single-file fragmented MP4 for MSE, DASH byte ranges or CMAF-style playback. Stream-copy by default; optional H.264/AAC re-encode.

## Run it

- **CLI:** `gizza tool video-fragmented-mp4 'url=https://example.com/input' 'mode=copy' 'profile=mse' 'keyframe_interval=2' 'segment_index=true'`
- **Web:** https://gizza.ai/tools/video-fragmented-mp4/
- **Agents:** machine-readable descriptor (parameters JSON Schema) at https://gizza.ai/tools/video-fragmented-mp4/tool.json

## Inputs

- `file` — Video file _(file; accept: video/*)_
- `mode` — Conversion mode _(field)_
- `profile` — Streaming profile _(field)_
- `fragment_duration` — Minimum fragment duration (seconds) _(field)_
- `keyframe_interval` — H.264 keyframe interval (seconds) _(field)_
- `segment_index` — Write a global sidx segment index _(field)_

## Output

- Fragmented MP4 (video)

## Query parameters

Open the tool pre-filled and auto-run via URL:

- `mode` — Conversion mode
- `profile` — Streaming profile
- `fragment_duration` — Minimum fragment duration (seconds)
- `keyframe_interval` — H.264 keyframe interval (seconds)
- `segment_index` — Write a global sidx segment index
- `url` — fetch the input file from a public URL (CORS-permitting)

Example: `https://gizza.ai/tools/video-fragmented-mp4/?url=https://example.com/input&mode=copy&profile=mse&keyframe_interval=2&segment_index=true`

---

## About this tool

A progressive MP4 usually has one `moov` index for the whole file. A fragmented MP4 (fMP4) instead starts with a small initialization header and then stores media in `moof` + `mdat` fragments. That layout is what Media Source Extensions players, DASH byte-range workflows, and CMAF-style packaging expect.

This tool rewrites a video into a **single-file fragmented MP4**. In the default `copy` mode it stream-copies every track with ffmpeg, so there is no quality loss and no re-encode step. If the source codecs are not browser-friendly, switch to `h264` mode to re-encode video as H.264/yuv420p and audio as AAC.

### Worked example

For an MP4 that already uses browser-compatible codecs, use:

- **Conversion mode:** `copy`
- **Streaming profile:** `MSE / generic fMP4`
- **Minimum fragment duration:** `0`
- **sidx segment index:** off

The ffmpeg plan applies the key flags for a single-file fMP4: keyframe-aligned fragments, an empty initialization `moov`, and default-base-is-moof offsets. The output remains an `.mp4`, but it is organized as fragments instead of one progressive media data run.

### Limits and edge cases

- The output is one `.mp4` file. It does not create an HLS/DASH manifest, `init.mp4`, or multiple `.m4s` segment files.
- `copy` mode cannot create new keyframes. Fragment boundaries follow the keyframes already in the source. Use `h264` mode when you need regular 2-second keyframes.
- `fragment_duration` is a minimum target in seconds. Fragments stay keyframe-aligned, so exact lengths depend on the encoded keyframes.
- `faststart` is not exposed: with an empty initialization `moov`, the useful header is already at the front.
- A global `sidx` is optional because it adds overhead and is mainly useful for byte-range single-file DASH.

## FAQ

<details>
<summary>Is fragmented MP4 the same as moving moov to the front?</summary>

No. `faststart` moves one progressive MP4 index to the beginning. Fragmented MP4 creates an initialization header plus repeated `moof`/`mdat` fragments, which is a different container layout for streaming append and byte-range workflows.

</details>

<details>
<summary>Does copy mode reduce quality?</summary>

No. Copy mode uses ffmpeg stream copy, so encoded audio and video packets are not decoded or re-encoded. The container is rewritten, but the media quality is unchanged.

</details>

<details>
<summary>When should I use H.264 mode?</summary>

Use H.264 mode when the source codec is not accepted by your target browser/player, or when the source has sparse keyframes and you want more regular fragments. It is slower and lossy because it re-encodes the video.

</details>

<details>
<summary>Why are my fragments not exactly the duration I requested?</summary>

Fragments are cut on keyframes so each fragment starts at a random-access point. If the source has keyframes every five seconds, copy mode cannot safely produce exact two-second fragments. Re-encode with a two-second keyframe interval if you need that cadence.

</details>

<details>
<summary>Can this create an HLS or DASH manifest?</summary>

No. This block returns a single media file, which fits the gizza page and CLI surfaces. Manifest generation and multi-file segment output need a different artifact model.

</details>

## Related tools

- [Set Video Keyframe Interval](https://gizza.ai/tools/video-set-keyframe-interval/): Re-encode a video with a fixed keyframe interval — one keyframe every 2 seconds, or any GOP size in frames — for clean seeking and even HLS/DASH segments.
- [Change Video Speed](https://gizza.ai/tools/change-speed/): Speed up or slow down a video right in your browser, keeping audio in sync — pick a speed factor (0.25x–4x). Re-encodes locally with ffmpeg, nothing is uploaded, free.
- [Extract Video Frames to a Contact Sheet](https://gizza.ai/tools/extract-frames/): Sample frames from a video by interval, fps or scene change and tile them into one contact-sheet image. Free, in your browser with ffmpeg, nothing is uploaded.
- [Gamma Correct an Image](https://gizza.ai/tools/gamma-correct/): Apply gamma correction to image midtones in your browser, with per-channel gamma, highlight protection and PNG/JPG/WebP output options.
- [GIF to MP4 / WebM](https://gizza.ai/tools/gif-to-mp4/): Convert an animated GIF into a much smaller MP4 or WebM video, right in your browser. Re-encodes locally with ffmpeg (H.264 / VP9), nothing is uploaded, free.
