Four ways an old clip fails
- The container. AVI, MPEG program streams (.MPG, .MOD), AVCHD transport streams (.MTS) and ASF are not MP4. iPhone Photos does not import them.
- The video codec. Motion JPEG, MPEG-2, H.263, DV and early MPEG-4 variants. Phones ship decoders for H.264 and HEVC.
- The audio codec. 8-bit PCM, IMA and Microsoft ADPCM, AC-3, MP2, AMR. The picture plays and the sound is silent.
- The picture layout. Interlaced fields show as comb lines on a phone screen. A 720 x 480 frame with a 16:9 flag looks squashed when the player ignores the flag.
Format by format
| Format | Container and codecs | What breaks | What the converter does |
|---|---|---|---|
| Pocket camera .AVI | AVI, Motion JPEG, sound as pcm_u8, adpcm_ima_wav or adpcm_ms | Phone galleries do not open AVI. ADPCM sound plays silent. | Decodes the JPEG frames, keeps the full-range colour flag, encodes H.264. Sound becomes AAC. |
| Pocket camera .MOV | QuickTime, Motion JPEG or H.263, sound often adpcm_ima_qt | ADPCM sound plays silent. H.263 was dropped by modern players. | Same path as AVI. Applies the rotation flag to the pixels. |
| JVC Everio .MOD | MPEG program stream, MPEG-2 at 720 x 480 or 720 x 576, AC-3 | No MPEG-2 player on iPhone. Interlaced. The 16:9 flag gets ignored. | Deinterlaces, then resamples to square pixels: 720 x 480 becomes 854 x 480. |
| AVCHD .MTS | MPEG transport stream, H.264, usually interlaced, AC-3 | iPhone Photos does not import it. Comb lines. AC-3 is silent on many phones. | Deinterlaces at the same frame rate. Sound becomes AAC. |
| Early .3GP and .ASF | H.263 or MPEG-4 Part 2 with AMR; WMV with WMA | Modern players dropped these codecs. | Decodes and re-encodes both tracks. |
All sound is re-encoded to AAC at 48 kHz stereo, 160 kb/s, whatever the source was. I wrote separate guides with tested ffmpeg commands for JVC MOD files, AVCHD, Kodak MOV, interlace lines and silent AVI sound. The rest of this page is about the engineering.
The pipeline
- Mount. A Web Worker mounts the file with Emscripten's WORKERFS. FFmpeg reads it in slices, so the source is never copied whole into memory. The worker contains no upload code. The 4.1 MB wasm file comes from the same origin as the page.
- Decode and filter. FFmpeg 7.1.3, compiled to WebAssembly, demuxes, decodes, deinterlaces and scales. It hands out I420 frames with square pixels.
- Encode video. Each frame is copied out of the wasm heap and passed to the browser's WebCodecs VideoEncoder. The output is H.264 with a keyframe every 60 frames.
- Encode audio. FFmpeg's native AAC encoder runs inside the wasm module.
- Mux. mp4-muxer, a JavaScript library, writes the MP4 into an ArrayBuffer with the index at the front. The page wraps it in a Blob for download.
Why the browser encodes the H.264
My FFmpeg build is LGPL. It is configured with --disable-gpl --disable-version3 --disable-nonfree. x264 is GPL, and FFmpeg has no H.264 encoder of its own, so the only encoder in the build is AAC. The browser already ships an H.264 encoder. The engine runs on one thread, and I did not want a software H.264 encoder on that thread.
The cost is that WebCodecs behaves differently in each browser. Safari's encoder produced no output in the default quality latency mode, so Safari gets realtime. Firefox ignored the row stride I passed with each frame. An 854 px wide picture with a stride of 864 came out sheared, and the job still reported success. I now repack every plane to stride equals width first. The encoder config tries High profile, then Main, then Baseline.
The worker pumps 8 frames per step and waits when the encoder queue is longer than 6. Deinterlacing uses yadif in send_frame mode. When the stream does not state its field order, idet runs first and yadif only touches frames detected as interlaced.
What I cut from FFmpeg
- Almost everything. The build starts from
--disable-everythingand adds back 10 demuxers, 35 decoders, 13 filters and 1 encoder. - Threads.
--disable-pthreads. WebAssembly threads need SharedArrayBuffer, which needs cross-origin isolation headers. The site does not send them. - Assembly and SIMD.
--disable-asm, plain C at-O3, no-msimd128. It is slower, and it runs on every wasm engine. - Network code.
--disable-network. The only protocol left isfile. - Modern decoders. No HEVC, VP9 or AV1, and no MKV demuxer. Those files are refused with a sentence that names the format.
- The source is published. The FFmpeg tarball, the configure line and build.sh sit next to the binary, with the engine source.
Memory limits
The wasm heap starts at 64 MB and may grow to 4 GB. It never shrinks, so every job gets a fresh worker that is terminated afterwards. The input stays on disk. The output does not: the whole MP4 sits in memory until it is finished. That is why the page caps the input at 500 MB on the free tier and 2 GB on the paid one. If the browser runs out of memory, the page says so and gives the file size. The picture can be at most 4096 px on each side.
What does not work yet
- The .MOI sidecar is not read. The engine has a function that accepts a display aspect from it. Nothing in the page calls it. A .MOD whose video header says 4:3 while the .MOI says 16:9 comes out 4:3.
- Frame rate is not doubled. 50 or 60 fields a second become 25 or 30 frames. Half of the motion samples are dropped.
- .TOD is untested. I have not had a real HD Everio file to try.
- No WebCodecs, no converter. The page checks for VideoEncoder and VideoFrame, and asks for a recent Chrome or Edge on a computer if they are missing.
- It is slow on long clips. Decoding and deinterlacing run on one thread without SIMD.
- Damaged files give partial results. The first pass is strict. On invalid data a second pass skips the damage and stops at the first unreadable packet.
Price and free limits
Free: 3 conversions a day, files up to 500 MB, output at most 1280 px wide at two thirds of the full bitrate, and a small Camport mark in the bottom right corner. A one-time $6.99 purchase removes all four and raises the file limit to 2 GB. The daily counter is a date and a number in the browser's localStorage.