SubtitleGenerator editorial
Our browser-exported MP4s were "0 seconds long" on Android
Our browser video exports used fragmented MP4. On the Android phone we tested, the media library recorded them as 0 ms and CapCut's picker hid them. What was in the file, the fix, and how we test it now.
Disclosure: I build SubtitleGenerator, the browser video editor this bug lived in. I used AI to help draft and fact-check this post against our code and test records; the code, measurements and device readings come from the fix and release records of November 22, 2026.
If you use SubtitleGenerator: videos exported before November 22, 2026 may not show up in your Android gallery or in CapCut's picker. Export them again; new exports are regular MP4 files with a real duration.
TL;DR: We wrote browser exports as fragmented MP4 so the finished video never had to sit in memory. The files played. But on the Android phone we tested, the media library recorded them as 0 ms long, and the exported video was missing from both the system photo picker and CapCut's new-project picker. Switching to a regular MP4 with moov at the end fixed the duration, but only after our file writer learned to write at arbitrary positions instead of only appending.
The symptom
SubtitleGenerator burns subtitles into a video in the browser: decode with WebCodecs, draw each frame plus captions on an OffscreenCanvas, encode, mux to MP4, and write the result to the Origin Private File System (OPFS) before handing it to the user.
On November 22 I tested importing an exported video on a Xiaomi 13 Ultra (Android 16) with CapCut 15.6.0. The exported file did not appear in the system photo picker or in CapCut's new-project picker. A plain MP4 pushed to the same phone at the same moment appeared in both.
Nothing in our desktop checks had flagged the file. It was still missing exactly where a phone user would look for it.
What was actually in the file
An MP4 is a sequence of boxes. Our two outputs looked like this at the top level:
- Fragmented (old):
ftyp → moov → moof/mdat × 16 → mfra. The firstmoovdescribes the tracks; eachmoofdescribes only its own chunk of samples. - Regular (new):
ftyp → mdat → moov. Onemdatwith all the media, and onemoovat the end describing every sample.
The browser-export implementation we introduced on August 1 used fragmented MP4:
// Before: fragmented MP4, appended to OPFS chunk by chunk
const output = new Output({
format: new Mp4OutputFormat({ fastStart: 'fragmented' }),
target: new AppendOnlyStreamTarget(opfsTarget.writable),
});That choice was deliberate. Exports can run 30 to 60 minutes. Fragmented output is written strictly front to back, so we could stream it to OPFS without holding the complete encoded video in memory.
The catch is in the movie header. Mediabunny 1.51.0, the muxer we use, writes an mvex box with trex entries but no mehd (the optional box that carries a fragmented file's total duration). In this fragmented path, mediabunny writes the initial moov when it finalizes the first fragment, and it does not fill the regular sample table that mvhd's duration is calculated from. So that duration is 0 in our output. When I parsed one of our production exports from before the fix, mvhd said 0 and there were 16 moof boxes.
Tools disagree about such a file. As a quick illustration (not our export), I made a 5-second fragmented MP4 with ffmpeg's -movflags frag_keyframe+empty_moov: its mvhd also says 0, while ffprobe still reports 5.0 seconds.
Playback alone had not exposed the problem. On our test phone, Android's MediaStore did. I pushed old- and new-format test files into DCIM/Camera with adb, triggered a media scan, and read the duration MediaStore recorded:
| File | Container | MediaStore duration on the tested phone (ms) |
|---|---|---|
| 25 s test clip | regular, moov at end | 25000 |
| 25 s test clip | fragmented (old) | 0 |
| 37 s test clip | fragmented (old) | 0 |
| 41 s test clip | regular, moov at end | 41000 |
| Real Chromium export, 1 s | regular, moov at end | 1045 |
The test clips came from the same muxer, written from an ffmpeg test pattern (video only). The last row is a real export from desktop Chromium with H.264 and AAC.
These results are consistent with the affected pickers filtering on duration, but I did not inspect their code. Not every app behaved the same way: in a separate test on the same phone, TikTok's picker did list an old fragmented export, with its correct length.
The fix, and why it was not one line
The obvious fix is a regular MP4. Mediabunny offers three ways to get one, and two did not fit:
fastStart: 'in-memory'keeps all the media in memory until it can writemoovat the front. For a 60-minute export, that is the memory problem we chose fragmented MP4 to avoid.fastStart: 'reserve'reserves space at the front for the metadata, and needs an upper bound on the packet count of every track. Mediabunny 1.51'sConversionAPI, which drives our export, does not expose that setting.fastStart: falsewritesmdatas it goes and putsmoovat the end. It does not buffer the encoded video, though it keeps per-sample metadata that grows with the number of audio and video packets. We did not measure that heap overhead separately.
We picked fastStart: false. It changes the writer contract, though. When the muxer finalizes, it goes back and patches the size field in the mdat header it wrote at the start. An append-only writer cannot do that.
Our OPFS writer uses a FileSystemSyncAccessHandle, normally inside a dedicated worker, with a same-thread fallback. Both paths used to keep their own running offset. Now they write each chunk at the position the muxer gives them. These are excerpts, not standalone programs: the mediabunny imports, the StreamTargetChunk type, OPFS setup and the worker's message handler are omitted.
// After: regular MP4, each chunk written where the muxer says.
// `request` posts the chunk to the OPFS worker (definition omitted).
const writable = new WritableStream<StreamTargetChunk>({
async write(chunk) {
const copy = chunk.data.slice();
await request('write', { buffer: copy.buffer, position: chunk.position }, [copy.buffer]);
},
});
const output = new Output({
format: new Mp4OutputFormat({ fastStart: false }),
target: new StreamTarget(writable),
});// Inside the worker: write at the chunk's own position, not at a running offset
let written = 0;
while (written < bytes.byteLength) {
written += accessHandle.write(bytes.subarray(written), { at: position + written });
}We made the same container and writer change in the path that appends rolling credits to an exported video, which had copied the fragmented setting.
The trade-off: with moov at the end, the file is less suited to progressive playback, where a player starts while the file is still downloading. Our users download the file and import it into a gallery or an editor, so we accepted that.
How we test it now
A unit test muxes a few seconds of fake H.264 packets through the real mediabunny muxer into an in-memory sink that honors chunk.position, then walks the top-level boxes and reads the mvhd duration. Here are the two helpers as plain JavaScript (the test version is TypeScript). They are enough for diagnosing your own trusted files; they are not a general MP4 validator:
function topLevelBoxes(bytes) {
const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
const boxes = [];
let offset = 0;
while (offset + 8 <= bytes.byteLength) {
let size = view.getUint32(offset);
const type = String.fromCharCode(...bytes.subarray(offset + 4, offset + 8));
if (size === 1) size = Number(view.getBigUint64(offset + 8)); // 64-bit size
if (size === 0) size = bytes.byteLength - offset; // box runs to end of file
if (size < 8) break; // malformed: stop
boxes.push({ type, offset, size });
offset += size;
}
return boxes;
}
// Assumes mvhd is the first box inside moov, which is true for the files we write.
function mvhdSeconds(bytes, moovOffset) {
const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
const mvhd = moovOffset + 8;
if (String.fromCharCode(...bytes.subarray(mvhd + 4, mvhd + 8)) !== 'mvhd') return null;
if (bytes[mvhd + 8] === 1) {
return Number(view.getBigUint64(mvhd + 32)) / view.getUint32(mvhd + 28); // version 1
}
return view.getUint32(mvhd + 24) / view.getUint32(mvhd + 20); // version 0
}The test asserts four things: the file has ftyp, mdat and moov; there is no moof; the duration in mvhd matches the input; and mdat ends exactly where moov begins, which proves the backwards size patch landed. Switching the setting back to 'fragmented' makes it fail. A second test reopens the output with mediabunny and checks the computed duration.
The end-to-end export test in Chromium, with real OPFS writes, checks that the file starts with ftyp, contains moov and has no moof. Inspecting its saved output by hand showed ftyp → mdat → moov and 1.045 seconds. (That test also has an outdated cleanup assertion, unrelated to this fix, that we have not updated yet.)
After release, I exported a 30-second sample on the live site: ftyp → mdat → moov, no moof, and mvhd reported 30.08 seconds (1732608 / 57600), matching ffprobe. Before the release, the same sample had come out with an mvhd duration of 0 and 16 moof boxes.
To check your own file: on any page with an <input type="file">, select the file, paste both helpers into the browser console, then run:
const file = document.querySelector('input[type="file"]').files[0];
const bytes = new Uint8Array(await file.arrayBuffer());
const boxes = topLevelBoxes(bytes);
const moov = boxes.find((b) => b.type === 'moov');
console.log(boxes.map((b) => b.type).join(' '), 'mvhd:', moov && mvhdSeconds(bytes, moov.offset));On the two ffmpeg test files above this prints ftyp free mdat moov mvhd: 5 and ftyp moov moof mdat mfra mvhd: 0. A moof does not mean a file is broken. But our old fragmented files had an mvhd duration of 0, and MediaStore on the tested phone recorded them as 0 ms too.
What this does not cover
- After the fix, the tested files had real MediaStore durations, and the new 41-second file showed up first in CapCut's picker. I did not separately retest the system photo picker, and I have not re-run the phone test since release.
- I have not exported directly in Android Chrome and imported the result. The phone readings come from files written by the same muxer and from a desktop Chromium export.
- No iPhone test, and TikTok was not retested with the new format.
- Export time and storage for 30 to 60 minute videos on phones were not re-measured after the change.
- Files exported before the fix are still fragmented. The fix only changes new exports.
The lesson
For this export path, "it plays" was not enough evidence that the file works. The file also has to be indexed and listed by whatever the user opens next, and those tools read metadata a player can work around. We now check the container and the duration metadata in tests. We still need real device import checks, because metadata tests cannot tell us what each picker does.
If you write MP4 from the browser, check what ends up in mvhd before a user's phone does it for you. Have you run into other apps that hide or reject fragmented MP4?
Frequently asked questions
My video exported from SubtitleGenerator does not show up in my Android gallery or CapCut. What should I do?
Export it again. Exports made before November 22, 2026 were written as fragmented MP4, which the Android phone we tested recorded as 0 seconds long, so some pickers hid it. New exports are regular MP4 files with a real duration. Files you already downloaded do not change on their own.
Why did a fragmented MP4 show as 0 seconds?
In the fragmented files we wrote, the total duration in the movie header (mvhd) was 0 and there was no optional mehd box carrying the total. Players can work the length out from the fragments, but the Android media library on our test phone stored 0 ms.
Does the new MP4 format change export quality?
No. Only the container layout changed: the media is written first and the index (moov) goes at the end. The video and audio encoding are the same.
Put the workflow on a video
Inspect a local file or open the built-in sample to preview caption styles and export formats. Your video stays on your device.
Upload your video