Copy pattern.mp4 (in the zip) into one MP4 file with media in fragments.
dotnet add package RecursiveAI.OneMediaRequires .NET 10 (net10.0); .NET 9 and earlier aren’t supported.
using RecursiveAI.OneMedia; using RecursiveAI.OneMedia.Remuxing; var report = Media.Remux("pattern.mp4", "out.mp4", RemuxFormat.FragmentedMp4); Console.WriteLine(report.Tracks[0].Packets);
Writes out.mp4 without re-encoding. Prints the number of video packets copied from this sample:
72Unzip the example, then dotnet run.
Full program
The CC0 sample is a three-second H.264 test pattern at 24 frames per second, with one keyframe per second and no audio. The program also prints the number of entries in report.Losses, which lists what the remux didn’t carry over.
using RecursiveAI.OneMedia; using RecursiveAI.OneMedia.Remuxing; var report = Media.Remux("pattern.mp4", "out.mp4", RemuxFormat.FragmentedMp4); Console.WriteLine($"Packets: {report.Tracks[0].Packets}"); Console.WriteLine($"Reported losses: {report.Losses.Count}");
dotnet run prints:
Packets: 72 Reported losses: 0
If out.mp4 already exists, the file-to-file remux refuses to replace it by default; pick a different output name or move the old file before running again.
Variations
Set a one-second fragment target. Use Remuxer.Remux to pass both the explicit fragmented MP4 format and the options in the same call:
using RecursiveAI.OneMedia; using RecursiveAI.OneMedia.Remuxing; Remuxer.Remux("pattern.mp4", "one-second.mp4", RemuxFormat.FragmentedMp4, new RemuxOptions { FragmentDuration = MediaTime.FromTimeSpan( TimeSpan.FromSeconds(1)) }); Console.WriteLine("Wrote one-second.mp4");
Prints:
Wrote one-second.mp4Related recipes
Move the MP4 header to the front · Create a DASH manifest from an MP4
The short answer
Pass RemuxFormat.FragmentedMp4 as the third argument to Media.Remux. Both files in the recipe use the .mp4 extension, but the explicit format changes how the output stores the packets. Remuxing copies compressed media into a new container layout; it doesn’t decode the pictures or encode them again. This call writes a single .mp4 file, not a DASH manifest, a playlist, or a directory of independent clips.
What is fragmented MP4 format?
A fragmented MP4 (fMP4) starts with a file type box (ftyp) and a movie box (moov) that describes the tracks. It then stores media in pairs of boxes: moof describes the samples in a fragment and the following mdat holds their data. The next fragment has its own pair. OneMedia’s muxing docs describe which timing and sample information the writer puts in moof.
The default duration target is two seconds. With video, the muxer starts a new fragment at a keyframe once it reaches that target, or cuts at the fragment byte limit. A keyframe gives the decoder a point from which it can start without decoding earlier pictures. If keyframes are farther apart, a duration setting alone won’t make them closer together: the writer is copying the existing frames. The three-second example has keyframes at 0, 1, and 2 seconds, so the default layout holds the first two seconds in one fragment and the last second in another.
What is the difference between fragmented MP4 and MP4?
An ordinary, non-fragmented MP4 keeps its sample tables together in moov. A fast-start MP4 puts that box ahead of the media data so the reader encounters those tables first. Fast start does not introduce fragments. Both fast-start and fragmented files can have a moov box near the beginning; what distinguishes fMP4 is the series of moof boxes that describe successive groups of samples. See the layout table for the box order of each form.
Choose the layout your reader expects. If it requires fMP4, pass the explicit fragmented format rather than relying on the extension. If your viewer expects an ordinary fast-start MP4, keep that layout instead. Neither layout changes the video codec, and wrapping packets in fMP4 won’t make an unsupported codec playable. When you need separate MP4 files that open on their own, split at keyframes instead of writing fragments inside one file.