Page MenuHomePhabricator

TimedMediaHandler: Improve video quality on older iPhones (MPEG-4 Visual)
Open, LowPublicFeature

Description

Background

An iOS 18 device playing back one of our WebM videos at a nice sharp HD 1080p resolution:

train-1080p.jpeg (739×1 px, 94 KB)

Playback of our WebM video output files is unavailable on older iPhones, until about iOS 17.4. All iPhones running iOS 18 can play back WebM; all on 17.3 or earlier cannot. Older devices currently get our fallback compatibility track, which is a blurry 144p Motion-JPEG .mov:

train-144p.jpeg (739×1 px, 62 KB)

While we have a shim ogv.js that can play back WebM on those iOS versions, we've been migrating off it to the native fallback track because the shim is slow and janky on older phones. Using a format that's natively supported by the phone is cleaner, faster, and supports use cases like fullscreen, picture-in-picture, and casting to a TV.

The initial fallback transcode we added last year is using Motion-JPEG, which is supported by all iPhone versions and unpatented, but very inefficient in terms of compression; this means that the 1-megabit stream is a very low resolution 144p, and appears quite blurry on a phone much less being casted to a big TV.

Per Wikimedia's traditional codec patents policy we continue to avoid h.264/AVC, the most common generic video codec today, but its older cousin MPEG-4 Visual has fallen out of patent in recent years and is well-supported by every old model of iPhone. This compresses much better than Motion-JPEG and should support 240p, 360p, and 480p standard-definition transcodes within the data rate constraints we spent on MJPEG.

These will look fairly clean on a phone, up to as good as our current WebM 480p but with a higher data rate:

train-480p.jpeg (739×1 px, 83 KB)

We can either pair it with its matching AAC-LC audio codec, also expired of patents, or we can continue to use MP3 for the audio track if we are conservative.

Work proposed

  • Add QuickTime MPEG-4 Visual + AAC-LC transcode tiers to WebVideoTranscodes.php:
    • (video bitrates are provisional -- test these on some files and compare them visually against the WebMs)
    • 240p.mpeg4.mov - 500 kbits
    • 360p.mpeg4.mov - 1000 kbits
    • 480p.mpeg4.mov - 2000 kbits
    • all with 128 kbits for audio
    • Use codec string video/quicktime
  • Add any necessary strings/setup to describe the tracks
  • enable them in config once in production
    • this is enough to start them generating on new uploads
  • (optional) Start a batch encode of all missing .mpeg4.mov files with maintenance/requeueTranscode.php
    • this may be a larger task to monitor it as the tools are not very good and should themselves be improved, cf T362123. Consider breaking this out and adding dependencies.
    • Disable and remove the old MJPEG tracks when done, they won't be needed and it'll free disk space.

Benefits

Anybody who's rocking an older-model iPhone with our mobile web site or app will appreciate the much clearer videos. :)

iOS 16 and below are a fraction of total iOS hits according to stats, and will continue to shrink, but that's still several percent of our total hits potentially seeing a very blurry video right now:

image.png (1×2 px, 218 KB)

Once it's set up and the backfill is run, no ongoing engineering or maintenance effort will be required.

Risks

Legal: As far as I know we have not gotten formal legal sign-off on acceptability of MPEG-4 Visual video or AAC-LC audio codecs, but both are believed to be out of patent and their use is consistent with our traditional policy (adopting GIF, MP3, and MPEG-1 and MPEG-2 video/audio when they came out of patent protection).

Tools: A batch run may take time and require some babysitting. The maintenance script requeueTranscodes.php has not been extensively tested under the new kubernetes production maintenance system, and it's known to sometimes get lost when using its --throttle mode which is meant to be self-moderating on enqueuing speed.

Additionally the frontend tool for seeing the state of transcodes on Special:Transcodes is very broken on Commons due to the inefficiently laid out transcodes table, making it hard to review ongoing state.

It may be necessary to perform some cleanup on the maintenance tools before doing a batch run, and that's a whole separate task or two (cf T362123, )

Event Timeline

bvibber renamed this task from 125. to Use MPEG-4 Visual for iOS back-compatibility video tracks to replace lower-quality MJPEG.Feb 22 2024, 7:19 PM
bvibber claimed this task.
bvibber updated the task description. (Show Details)

Change 1004794 had a related patch set uploaded (by Bvibber; author: Bvibber):

[mediawiki/extensions/TimedMediaHandler@master] Optional MPEG-4 Visual streaming video tracks

https://gerrit.wikimedia.org/r/1004794

Also adding this to Wikipedia-iOS-App-Backlog since it affects both mobile web & app views, which is why I'm concentrating on it as low-hanging fruit. If this can go through, video quality on older iOS devices will go up in both. :)

[Deployment will remain stalled pending legal approval for MPEG-4 Part 2 Visual video codec. If we get that, it's just a config merge and running the backfill in maintenance; no new development work needed.]

Change #1004794 merged by jenkins-bot:

[mediawiki/extensions/TimedMediaHandler@master] Optional MPEG-4 Visual streaming video tracks

https://gerrit.wikimedia.org/r/1004794

Ok, the definitions have landed so we can switch them in whenever we get legal approval. The wheels are being set in motion. :)

The video of the "SD 360p" option seems to work for all files, but its audio no longer does for certain WebM and OGG videos. The audio still works for OGV files. My iPad's OS version is now iPadOS 17.7; not yet ready for iPadOS 18. Perhaps this task must have been something to do with that?

Examples:

I tested out freer ones listed in T354502#9643748. Their "SD 360p" options still have sounds, but:

I also tested out files listed in T354502#9643748, and seems that "SD 360p" have no sound. Switching to "Low 240p" must have done wonders.

bvibber renamed this task from Use MPEG-4 Visual for iOS back-compatibility video tracks to replace lower-quality MJPEG to TimedMediaHandler: Improve video quality on older iPhones (MPEG-4 Visual).Oct 24 2025, 8:19 PM
bvibber removed bvibber as the assignee of this task.
bvibber updated the task description. (Show Details)
bvibber updated the task description. (Show Details)
bvibber raised the priority of this task from Low to Needs Triage.Oct 24 2025, 8:45 PM

I'm gonna bump this back to Needs Triage just in case we want to re-evaluate it in the current Reader Growth team situation. iOS 16 and below are a fraction of total iOS hits according to stats, and should continue to shrink, but that's still several percent of our total hits potentially seeing a very blurry video:

image.png (1×2 px, 218 KB)

egardner moved this task from Incoming/Inbox to Backlog on the Reader Growth Team board.

Cross-referencing T413031#11547604, it's hard to see exactly what number of requests are coming to mjpeg 144px since we are sending out a lot of partial responses (HTTP‌ status 206). But it still it looks like we are serving a LOT of mjpegs and better to switch it to something slightly better?

Something to note: Top UA‌ for mjpeg is iPhone on iOS 26.2 (released on December 2025): https://w.wiki/HZrR This doesn't sound right. Aren't they supporting VP9 already?

We *shouldn't* see much MJPEG usage on iOS 26 unless something's very weird going on (like an individual page doesn't have a VP8 or VP9 WebM available) or individuals are switching sources manually. :D Those should all show the VP9 by default in both Safari and our app.

Something to note: Top UA‌ for mjpeg is iPhone on iOS 26.2 (released on December 2025): https://w.wiki/HZrR This doesn't sound right. Aren't they supporting VP9 already?

It looks like there's two separate things going on:

  • web browsers with WebKit browser user-agents and clear referers
  • views in apps, labeled as either "AppleCoreMedia" for those that don't customize the User-Agent, or for our app, "WikipediaApp", with blank referers

The biggest set of views in this data set, naturally, is to Debbie Does Dallas.ogv (sigh), which does have both VP9 and VP8 transcodes as well as an MJPEG.

I wonder if somebody's made a silly Wikipedia scraper app that is funneling specifically to these videos and preferring the MJPEG (either by accident or on purpose)?

But I see some iOS 18 and iOS 26 in the webkit list too and I'm not sure why. Might be something funky in the markup that bears testing; might be false requests from scrapers. :D

There are requests to vp9 on an iOS 26 UA‌ but the number is basically peanuts: https://w.wiki/HaJS i.e. 5%‌ of hits to mjpeg (of course the partial requests could be the reason for this discrepancy)‌

There are requests to vp9 on an iOS 26 UA‌ but the number is basically peanuts: https://w.wiki/HaJS i.e. 5%‌ of hits to mjpeg (of course the partial requests could be the reason for this discrepancy)‌

I‌ wonder if apple is preferring mjpeg because of HLS files that haven't been cleaned up? I'll look into it a bit later.

Legal has got back to me and said this:

the last patent for MPEG-4 Part 2 expires July 19th, 2026.

We can move forward with this after that date.