Skip to content

Convert banner videos on upload, cap the served file at 10 MB, fix the hero markup (#1468) - #1477

Open
jonfroehlich wants to merge 6 commits into
masterfrom
1468-video-upload-reencode
Open

jonfroehlich wants to merge 6 commits into
masterfrom
1468-video-upload-reencode

Conversation

@jonfroehlich

@jonfroehlich jonfroehlich commented Dec 2, 2026 •

Copy link
Copy Markdown
Member

Closes #1468

Implements the plan posted on the issue (#1468 (comment)).

What changes

Upload and conversion. An editor may upload a banner video of up to 250 MB and 60 s. BannerAdminForm (now used by BannerAdmin and by the project page's BannerInline) checks it in clean_video: extension and signature, the 250 MB ceiling, then ffprobe (a real video stream, at most 60 s, frame at most 4096 px, landscape, not PQ HDR). clean_video changes nothing. The form's save() stores the upload as Banner.video_original under a server-generated name, sets video_conversion_started, and registers the job with transaction.on_commit. After the commit, a daemon thread in the Gunicorn worker converts it (one job at a time across workers, via fcntl.flock) and sets Banner.video with one UPDATE filtered on the banner id, the original's name and the start time. A superseded job (a new upload, "Convert again", the video cleared, or the banner deleted) therefore changes nothing and deletes its own output.

Encoder (website/utils/video_utils.py, which holds all the limits). A file that is already H.264 yuv420p, at most 1920×1080 and at most 10 MB is stream-copied, which still strips audio and metadata such as a recorded location. Any other file gets one libx264 pass:

  • fits inside 1600×900, never cropped or enlarged;
  • at most 30 fps;
  • CRF 27 with -maxrate min(2500, 72000/duration) kbit/s;
  • one retry at three quarters of that ceiling if the result is over 10 MB. If it is still over, nothing is served and the error is recorded.

HLG HDR is tone-mapped to BT.709. Every command is an argv list (no shell) with the demuxer forced from the file's signature, -protocol_whitelist file and -map 0:V:0 (so cover art is never picked), and runs under timeout -k 10 300 nice -n 10. On failure, the tail of ffmpeg's stderr is logged with file paths removed. The 60 s limit allows 0.5 s of slack, because a real 60 s clip probes as 60.03 s.

The original is kept on success and on failure, linked only from the admin, deleted with the banner, and deleted when a new upload replaces it. Public pages never reference it, and a test pins that.

Admin

  • A Video column on the banner list: 2.3 MB .mp4, 14.2 MB .mov (over 10 MB), converting…, interrupted (started more than 30 minutes ago and never finished) or conversion failed: <reason>.
  • The same status as a read-only row on the form, with a link to the original upload.
  • A Convert video again from the original upload action.
  • A save message, which also asks for an image when the banner has none.
  • A pre-upload size check in the browser (banner_video_size_check.js, role="alert").
  • New help text on the video field.

Without ffmpeg (the checkout can be ahead of the image during a deploy), an upload of 10 MB or less is stored as Banner.video exactly as before and a larger one is refused. The help text says so, and /version.json reports "ffmpeg": false. validate_banner_video_size on Banner.video is the 10 MB backstop for new uploads; existing files are never re-checked.

Hero markup

  • <source type> follows the file. It is omitted for .mov, because Chromium does not claim video/quicktime and would skip a file it can play.
  • Only the first slide autoplays.
  • For a banner with an image (its poster), the other slides are preload="none" and each <source> is gated with media="(prefers-reduced-motion: no-preference)". A banner with no image is never gated, because its paused first frame is all that can fill the hero; gated, it would be black under reduced motion or after Pause (review 1, finding 1).
  • carousel.js lifts the gate (and calls load()) in setVideoPlayback whenever a video is about to play, so after a reduced-motion visitor presses Play, every slide they see loads its video.

Public carousels. Banner.objects.displayable() leaves out a banner whose only media is an unconverted original (landing and project pages). Title-only banners are unaffected.

Model: three new Banner columns (video_original, video_conversion_started, video_conversion_error), plus help text and validators on video. In a copy of this branch, starting from migrations generated off master, makemigrations --check --dry-run reports only those three added fields and the altered video field.

Image, CI and docs.

  • The Dockerfile installs ffmpeg, which grows the image's apt layer by about 560 MB (132 MB to 692 MB).
  • CI's test job installs ffmpeg and sets REQUIRE_FFMPEG=1. The e2e job runs the new hero module.
  • Docs: CLAUDE.md gets a "Banner videos" section and a testing note, and docs/DEPLOYMENT.md covers ffmpeg as an image dependency, the /version.json field and the test-server checks.
  • Version bumped to 2.36.0.

Tests (written first)

Commit 69c6b8c adds the tests alone; 040349e adds the code.

On the pre-change code:

  • 33 errors, from imports of the new code: BannerAdminForm (29 tests), video_utils (the whole test_video_utils module and 1 more), and validate_banner_video_size (2).
  • 5 failures in test_hero_motion:
    • type="video/mp4" on .webm and .mov sources (2 tests);
    • autoplay on every slide: [True, True, True] != [True, False, False];
    • no preload="none";
    • no media gate.
  • 4 of 5 browser tests fail. On load, all three slide videos are requested, with or without reduced motion. The fifth, test_after_play_under_reduced_motion_the_next_slide_also_loads, was then tightened to assert that nothing is requested before Play, which fails on master for the same reason.
  • Guards (pass on master and after): test_form_save_after_finished_conversion_keeps_new_video and the three existing test_hero_motion tests.

Suite results.

Run Result
Current image, no ffmpeg 931 tests OK; 23 skipped (6 RealFfmpegTests, 17 Playwright)
New image with ffmpeg 5.1.9, REQUIRE_FFMPEG=1 931 tests OK; 17 skipped (Playwright only), so RealFfmpegTests ran
Playwright (Chromium) the 9 hero and admin e2e tests and the 8 existing member e2e tests pass

(These counts are after review 2; the table of failures above is for the first tests-only commit.)

RealFfmpegTests checks four things with the real commands:

  • the encode gives H.264, yuv420p, no audio, the index at the front, and a frame inside 1600×900;
  • a stream copy drops a location tag;
  • an HLG source comes out 8-bit, tagged BT.709;
  • garbage and a renamed playlist are rejected;
  • cover art stored ahead of the video is never served.

Mutation check: 29 mutations covering all 18 targets in the plan's table, each run against the targeted modules. All 29 were killed; none survived. After review 1, a re-run of 87 mutations (these 29, the reviewer's 42 and 16 that undo the review fixes) killed all 87.

# Mutation Killed by
1 drop -an / +faststart / -map_metadata -1 / -pix_fmt yuv420p test_command_drops_audio_strips_metadata_and_sets_faststart (also RealFfmpegTests for faststart and metadata)
2 skip the size check after encoding; retry compares against the wrong constant; job skips its own size check test_retry_runs_once_when_result_is_over_cap, test_conversion_fails_when_retry_is_still_over_cap, test_result_over_cap_is_never_served
3 drop -maxrate; maxrate ignores duration test_bitrate_ceiling_follows_duration, test_retry_runs_once_when_result_is_over_cap
4 store the upload as Banner.video test_failed_conversion_keeps_original_and_records_error, test_result_over_cap_is_never_served, test_superseded_job_changes_nothing
5 original keeps the uploader's filename test_original_name_is_server_generated
6 delete the original after a failure test_failed_conversion_keeps_original_and_records_error
7 render video_original in base.html test_public_pages_never_reference_original
8 drop the original-name filter; drop the start-time filter test_superseded_job_changes_nothing (sub-cases)
9 store the original, or register on_commit, in clean_video test_invalid_other_field_stores_nothing_and_registers_no_job
10 start the job before the commit test_cleared_video_cancels_running_job and 2 more
11 probe a committed file test_unchanged_video_is_not_probed_again, the guard
12 accept over 10 MB without ffmpeg test_without_ffmpeg_small_upload_is_kept_and_large_one_rejected
13 remove BannerInline.form test_inline_form_is_banner_admin_form
14 stream-copy a non-H.264 or over-10 MB file test_stream_copy_refused_when_not_h264, _over_10mb
15 remove the timeout wrapper test_command_is_wrapped_in_timeout
16 treat an old job as still converting test_job_older_than_30_minutes_reads_as_interrupted, test_video_column_shows_size_converting_failed_and_interrupted
17 hard-code video/mp4; autoplay on every slide; drop the media gate the test_hero_motion additions
18 carousel.js ungates only the slide active when Play is pressed test_after_play_under_reduced_motion_the_next_slide_also_loads (browser)

Screenshots

Captured with Playwright against seeded local data. I can't attach images from the command line, so they are described here; they are available to add by hand.

  • Banner list, before: columns Preview, Title, Project, Landing page, Favorite, Date added, Media.
  • Banner list, after: a new Video column between Date added and Media. Its values: 2.3 MB .mp4, 14.2 MB .mov (over 10 MB), converting…, interrupted, conversion failed: ffmpeg timed out after 300 s, and — for a banner with no video.
  • Banner form, Video fieldset, before: the file input, with "Ideally, video should be 10MB or less".
  • Banner form, Video fieldset, after: the new help text, plus a Video status row reading "2.3 MB .mp4 · original upload (48.0 MB)", where "original upload" is a link.

The public hero looks the same as before; only what it downloads changes.

Provisional decisions (plan section 13; implemented on its recommendations)

  1. Convert HLG HDR and refuse PQ (HDR10).
  2. Refuse portrait uploads (taller than wide, after rotation).
  3. Delete the superseded original when a banner's video is replaced.
  4. One encoder pass with a bitrate ceiling, not the CRF ladder.
  5. Leave a banner out of the public carousels while its only media is an unconverted original.
  6. GUNICORN_TIMEOUT is unchanged. Decide after the test-server upload checks; the alternative is a lower ceiling.
  7. Release number 2.36.0.

Also by plan: 250 MB and 60 s limits; a thread, not a task queue; existing oversized banners are left as they are (the Video column flags them).

Not verified

  • The CSE proxy: its body limit, its timeouts, and whether it streams or buffers uploads. docs/DEPLOYMENT.md lists the 100, 200 and 250 MB uploads to try on the test server before tagging.
  • Firefox and Safari. The media gate, preload="none", the no-image first frame and the Play behaviour were checked in Chromium only.
  • A real iPhone HLG clip. Only a synthetic HLG-tagged clip was converted, and its colours were not inspected.
  • The production host's encode speed. Timings were measured locally only.

🤖 Generated with Claude Code — Opus 5.5, claude-opus-5-5

jonfroehlich and others added 2 commits December 1, 2026 17:30
Tests for converting banner video uploads on the server and for the
hero's video loading. On the pre-change code every new test fails (or
cannot import what it tests); the guards pass:

- test_video_utils.py: probe parsing, upload checks, stream-copy rule,
  bitrate and frame-rate rules, exact ffmpeg command lines, the one
  retry; RealFfmpegTests runs the real commands, skipped without ffmpeg
  unless REQUIRE_FFMPEG=1.
- test_banner_video_upload.py: the form keeps the upload as the
  original, the background job, superseded jobs, clearing, the no-ffmpeg
  mode, public pages, logging; one guard (admin re-reads on POST).
- test_hero_carousel_e2e.py: Playwright counts video requests (active
  slide only, reduced motion, Play).
- Additions to test_hero_motion, test_banner_admin,
  test_upload_validators and test_version_endpoint.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HFUXRa2hBVnK4hXzY8dK68
…#1468)

An editor may now upload a banner video of up to 250 MB and 60 s. The
banner form keeps the upload as Banner.video_original (server-generated
name, admin-only link) and, after the commit, a daemon thread converts
it with ffmpeg to a web-ready MP4 of at most 10 MB, which becomes
Banner.video. A small H.264 file is stream-copied; anything else gets
one libx264 pass with a bitrate ceiling that follows the clip length,
plus one retry. HLG HDR is tone-mapped; PQ HDR, portrait, over 60 s and
unreadable files are field errors.

- Dockerfile and CI: ffmpeg; REQUIRE_FFMPEG=1 in the test job; the hero
  e2e module in the e2e job.
- Banner: video_original, video_conversion_started,
  video_conversion_error; video_mime_type; video_status (a job older
  than 30 minutes reads as interrupted); objects.displayable() hides a
  banner whose only media is an unconverted original.
- Admin: BannerAdminForm (also on the project page's inline), a Video
  column and status row, a 'Convert video again' action, a save message,
  and a pre-upload size check in the browser.
- Without ffmpeg, uploads of 10 MB or less are stored as before and
  larger ones refused; /version.json reports "ffmpeg".
- Hero: <source type> follows the file (none for .mov), only the first
  slide autoplays, others preload="none", sources are gated on
  prefers-reduced-motion and carousel.js lifts the gate when a video is
  about to play.
- Docs (CLAUDE.md, docs/DEPLOYMENT.md, help text); version 2.36.0.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HFUXRa2hBVnK4hXzY8dK68

@jonfroehlich jonfroehlich left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review (reviewer 1) — head 040349e5a0fda65608352683ad261ca90a901d65 (base 6688489)

No blocking defect found. The conversion pipeline, the job identity and the clear/replace/delete paths held up under real ffmpeg and real threads. There are three should-fix items in the code, two in the tests, and some nits. The PR's numbers all reproduce, with one small arithmetic slip in the description.

What I ran

Everything ran in Docker against a throwaway Postgres 16, on scratch copies of the head and base commits.

Run Image Result
Base 6688489, full suite site image, no ffmpeg (Python 3.13) 829 OK, 8 skipped
Head, full suite site image, no ffmpeg 907 OK, 18 skipped
Head, full suite, REQUIRE_FFMPEG=1 image with ffmpeg 5.1.9 907 OK, 13 skipped
Head, hero + member browser tests Playwright image, Chromium 13 OK
Tests-only commit 69c6b8c, full suite site image, no ffmpeg 33 errors, 5 failures; the 5 hero browser tests all fail
CI on this head ubuntu-24.04, ffmpeg 6.1.1 test (907 OK, 13 skipped), e2e, a11y all pass

I also wrote probe tests (not in the PR) that post real clips through the real admin views with real ffmpeg, run the job in a real thread, and drive the hero and the admin form in Chromium. The findings below come from those.

Should fix

1. A video banner with no image is now a black hero for reduced-motion visitors, and for anyone who pauses.

  • On 6688489 such a banner shows its paused first frame. On this head the gated source is never selected, so nothing is painted: a black box with the title over it.
  • Reproduce: two landing banners with a video and no image; Chromium with reduced_motion="reduce", video requests answered with a real MP4. Head: no request, readyState 0, currentSrc ''. Base: readyState 4, paused, frame visible.
  • Same result with no preference set: press Pause, then go to slide 2. Head readyState 0 (black); base shows the frame.
  • The save message asks for an image on new uploads, but existing banners change silently on deploy.
  • Options: apply the media gate and preload="none" only when the banner has an image, or flag "video, no image" in the Video column so they can be fixed first.
  • Severity: should-fix. I would hold the production tag on it if any live banner has a video and no image. I did not check production data.

2. -map 0:v:0 can select cover art that parse_probe deliberately skips.

  • parse_probe takes the first video stream that is not an attached picture; both ffmpeg commands map 0:v:0, which does not make that exception.
  • Reproduce: an MP4 with an attached picture whose udta box precedes trak inside moov. ffprobe lists png (attached picture) as stream 0 and h264 as stream 1. probe reports the 640×360 H.264; convert returns mode='copy', size=973, and the stored file's only stream is a one-frame 320×180 PNG.
  • So a file that is not H.264 gets served as the banner video. It needs an unusual file from a signed-in editor, and the result is a broken banner, nothing worse.
  • Fix: -map 0:V:0. On ffmpeg 5.1.9 the same command with V copied the H.264 stream (60 frames).
  • Severity: should-fix.

3. A clip at the 60-second limit is refused with a message that contradicts itself.

  • Reproduce: a real 60 s clip at 29.97 fps probes as 60.027 s and is refused with "This clip is 60 seconds long; banner videos can be at most 60 seconds."
  • The size messages round the same way. A 250.4 MB file gets "This file is 250 MB; a banner video upload can be at most 250 MB" from the browser check (seen in Chromium); the server message uses the same format.
  • Fix: allow a small tolerance (say 60.5 s), or print one decimal.
  • Severity: should-fix (small).

4. No test sends an upload through an admin view.

  • Every upload test calls form.save() directly, which is the commit=True branch. BannerAdmin uses commit=False and the wrapped save_m2m.
  • Mutation: replace self.save_m2m = save_m2m_then_queue with pass. All 111 targeted tests still pass, while the banner page would store the original and never start the job.
  • The project inline is pinned only by issubclass(BannerInline.form, BannerAdminForm).
  • Both paths do work on this head: I posted real clips to the banner add view and to the project change view inside captureOnCommitCallbacks(execute=True), and each came back 302 with the video converted and the save message present.
  • Severity: should-fix (tests). Two tests of that shape would close it.

5. The extension allowlist on the convert path is not pinned.

  • Mutation: delete validate_video_upload(value) from clean_video. All 111 targeted tests pass.
  • That call is the only check on the convert path: video_original has no validators and takes its extension from the upload's name. Without it, by my reading of the code (not run), a real video named clip.html would be stored with that extension.
  • Severity: should-fix (tests). One test: a valid header under a disallowed extension is a field error.

Nits

  • Image size. "About 330 MB" (Dockerfile comment, docs/DEPLOYMENT.md, description) is low. The apt layer is 692 MB in the new image against 132 MB in the current one, so about 560 MB more. In a throwaway container from the current image, apt-get install --no-install-recommends ffmpeg reports 361 MB of additional space (136 new packages, 17 upgraded), and disk use grows by 557 MB, because the upgraded packages are stored again in the new layer.
  • timeout 300 has no -k. If ffmpeg does not exit on SIGTERM, timeout waits, Python kills timeout at 330 s, and ffmpeg is left running with no parent. Shown with a stand-in child that ignores SIGTERM (not a real ffmpeg hang): it survived at nice 10. timeout -k 10 300 ends it; timeout then dies by SIGKILL itself (return code −9), so treat that as a timeout too.
  • No-ffmpeg mode.
    • A direct upload leaves the earlier video_original and error in place. Reproduced: upload A with ffmpeg, upload B without, then "Convert again" replaces B with a conversion of A.
    • The help text contradicts itself: the "cannot convert" sentence is added in front of the unchanged "up to 250 MB … the server converts it" text.
    • The browser check still allows 250 MB.
  • aria-describedby. Django puts aria-describedby="id_video_helptext" on the input. The size-check script replaces it with the error's id and never restores it, so after a valid file is chosen it points at a hidden, empty element. Append the id, and remove it when the error clears.
  • ffmpeg's stderr is captured and dropped. A failure records only "ffmpeg exited with status N". A short tail in the log line would make a failure on the servers diagnosable.
  • Description arithmetic. The 33 errors are 29 (BannerAdminForm) + 2 (video_utils: the module and one more, not two) + 2 (validate_banner_video_size).
  • Two unpinned constants. BANNER_VIDEO_MAX_BYTES is kept equal to MAX_SERVED_BYTES by a comment only, and removing validate_banner_video_size from Banner.video fails no test.

Mutations

  • The PR's table: I re-ran all 29. All 29 are killed, as claimed.
  • My own: 42 more, 28 killed, 14 survived. The 14:
Survivor Note
Admin commit=False branch never queues the job finding 4
clean_video skips the extension and signature validator finding 5
Thread never closes its DB connection works on this head: connections 1 before, 1 after the thread ends
No flock works on this head: two real jobs ran 0.00–1.08 s and 1.18–2.25 s, no overlap
Landing favourites query without displayable() the test's pending banner is not a favourite
"Convert again" without the ffmpeg guard
"Convert again" without permissions=['change']
"Convert again" keeps a running job's start time the test clears the start time first, so superseding a running job is unpinned
No early "superseded" check in the job an optimisation; the final UPDATE still decides
Size backstop removed from Banner.video nit above
Inline save message removed message seen in the real response
BannerAdmin save message removed message seen in the real response
convert() accepts an over-cap stream copy the job's own size check still refuses it
Size-check script does not stop the submit no JS test; see below

Checked and found sound

  • Thread and commit. With inline conversion off and a real commit, a daemon thread named banner-video-<id> starts after the save, converts with real ffmpeg and sets the video. Deleting the banner mid-job leaves no files behind.
  • Replace and clear through the admin change view: the superseded original is deleted, and Clear empties video, video_original and the start time.
  • Uploads of 0.2 MB (held in memory) and 198 MB (temp file) both probe and convert. The 198 MB one took 6.3 s end to end and came out 1.5 MB at 1600×900, 30 fps.
  • Checks with real files: WebM accepted; audio-only refused ("no video track"); PQ refused; stored 1280×720 with rotation 90 refused as portrait; stored 720×1280 with rotation 90 accepted, its stream copy keeps the display matrix, and its encode comes out 1280×720 with none.
  • Timeout: real ffmpeg under timeout 1 is reported as timed out and no ffmpeg process is left.
  • Commands: argv lists, demuxer forced, -protocol_whitelist file on both ffprobe and ffmpeg; mutating any of these is killed.
  • Hero in Chromium with real video bytes: on load only the active slide's file is requested; the inactive slide has currentSrc set and readyState 0.
  • Admin size check in Chromium: the error appears with role="alert", Save sends no POST and focus moves to the input, and it works on the project inline including a row added later.
  • Migrations: from migrations generated at the base, makemigrations --check --dry-run on this head reports the three added fields and the altered video field, as claimed.

Confidentiality

I checked every added line in the diff, and the description, against this repository's rules for public text. Nothing needs to change.

Not verified

  • Firefox and Safari (the Playwright image has Chromium only).
  • The CSE proxy, and a real iPhone HLG clip.
  • Whether any production banner has a video and no image (finding 1).
  • A real ffmpeg hang (the -k nit used a stand-in).

🤖 Review by Claude Code — Fable 5.2, claude-fable-5-2

jonfroehlich and others added 3 commits December 1, 2026 18:35
…review)

A video banner with no image has no poster, so gating its <source> on
prefers-reduced-motion (and preload="none" on inactive slides) left the
hero black for reduced-motion visitors and after Pause, where master
showed the paused first frame. The gate and preload="none" now apply
only when the banner has an image; with no image the markup loads as on
master. Chosen over flagging such banners in the admin because the black
hero would appear on deploy, before anyone could act on a flag.

Browser tests: a no-image video banner paints its first frame under
reduced motion and on the next slide after Pause (served real MP4 bytes
from a 9 KB fixture, since CI's e2e job has no ffmpeg). The gated-loading
tests now use banners with images. Also browser tests for the admin size
check (submit blocked, alert, focus) and its aria-describedby handling,
which fail until the next commit fixes the script.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HFUXRa2hBVnK4hXzY8dK68
…eg mode (#1477 review)

- ffmpeg maps 0:V:0, so an attached picture stored ahead of the video is
  never stream-copied as the banner video (same rule as parse_probe).
  RealFfmpegTests builds such a file and checks the output is the H.264.
- 0.5 s of slack on the 60 s limit (a real 60 s clip probes as 60.03 s);
  the duration and size messages print one decimal, in Python and JS.
- timeout -k 10, and 137 / -9 read as a timeout; on failure the tail of
  ffmpeg's stderr is logged with file paths removed.
- No-ffmpeg mode: a directly stored upload drops the kept original, job
  and error (so Convert again can't resurrect an older upload); the help
  text is replaced, not prefixed; the browser check uses 10 MB.
- Size-check script appends to aria-describedby and removes its id when
  the error clears, keeping Django's help-text link.
- Tests: uploads through the real banner add view and the project page
  inline (the commit=False path and both save messages); a disallowed
  extension with a video header is refused; the thread closes its DB
  connection; jobs take the lock; a job superseded before it starts does
  no work; Convert again needs ffmpeg, the change permission, and
  supersedes a running job; the landing favourites query hides pending
  banners; an over-cap stream copy falls back to an encode; the 10 MB
  backstop is wired and equal to the cap.
- Image size corrected: the apt layer grows by about 560 MB, not 330.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HFUXRa2hBVnK4hXzY8dK68
Without ffmpeg the browser check now advertises 10 MB, so this test failed
in the no-ffmpeg image (CI's test job has ffmpeg and missed it).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HFUXRa2hBVnK4hXzY8dK68
@jonfroehlich

Copy link
Copy Markdown
Member Author

Response to review 1 (head 040349e → eed6bd9)

Every finding reproduced, and all 12 are fixed; I disagree with none of them. I wrote each test first and watched it fail on 040349e before changing the code. Three commits:

  • 141903d: the hero fix (finding 1) and the new browser tests.
  • 05f6356: everything else.
  • eed6bd9: a test fix. The widget size-limit test now pins ffmpeg as available, because it failed in the no-ffmpeg image once that mode advertised 10 MB. CI's test job has ffmpeg, so it couldn't have caught this.

CLAUDE.md's updates for both are in 141903d.

Should fix

1. Black hero for a video banner with no image. Fixed in 141903d.

  • What changed: the media gate and preload="none" now apply only when the banner has an image. A video-only banner renders as it did on master: it is never gated, and its inactive slides preload as before.
  • Why this rather than a Video-column flag: a flag still ships the black hero on the day of the deploy, before anyone has acted on it. Nobody has checked whether production has such banners, so the template has to be safe on its own.
  • The cost: a reduced-motion visitor still downloads a video-only banner's video, as on master. For banners with an image, the saving is unchanged.
  • Browser tests (HeroVideoWithoutImageE2ETests), which serve real MP4 bytes from a 9 KB fixture because CI's e2e job has no ffmpeg:
    • test_first_frame_is_painted_under_reduced_motion: the active video reaches readyState >= 2 and stays paused.
    • test_next_slide_has_a_frame_after_pause: Pause, go to slide 2, and slide 2 has a frame.
    • Both timed out on 040349e, waiting for a frame.
  • The gated-loading browser tests now use banners with images. test_hero_motion adds test_banner_without_image_is_not_gated_and_preloads, and test_only_first_slide_autoplays covers both cases.

2. -map 0:v:0 can pick cover art. Fixed in 05f6356.

  • Both commands now use -map 0:V:0.
  • New test RealFfmpegTests.test_cover_art_ahead_of_the_video_is_not_served uses your construction: an attached picture with udta reordered ahead of trak, so ffprobe lists the PNG as stream 0. It asserts that the output's only stream is the 640-wide H.264.
  • On 040349e it failed: the output was the PNG. The command-line test also pins 0:V:0.

3. A 60 s clip refused with a self-contradicting message. Fixed in 05f6356.

  • DURATION_TOLERANCE_SECONDS = 0.5, so 60.027 s is accepted and 60.6 s is refused.
  • The duration message, the server's size message and the browser's size message print one decimal (for example "60.6 seconds" or "250.4 MB").
  • New tests: test_clip_at_60_seconds_with_container_overhang_is_accepted (it raised on 040349e), the tightened test_rejects_clip_over_60_seconds, and test_size_messages_use_one_decimal.

4. No upload went through an admin view. Fixed (tests) in 05f6356.
BannerVideoAdminViewTests covers both admin save paths. Each test asserts one on_commit callback, the converted .mp4 and the save message:

  • test_banner_add_view_queues_conversion_and_says_so posts to the banner add view, which exercises the commit=False / wrapped save_m2m path.
  • test_project_inline_upload_queues_conversion_and_says_so scrapes the project change form, as a browser would submit it, and posts a video in banner_set-0.

Both pass on 040349e: as you found, the paths work, and they had no tests. Your O1, O43 and O44 are now killed.

5. Extension allowlist on the convert path not pinned. Fixed (test) in 05f6356.
test_disallowed_extension_with_video_header_is_refused: a valid ISO-BMFF header named .html, .svg or .avi is a field error, and the probe is never called. O2 is now killed.

Nits

Nit Result
Image size Fixed. Re-measured: the apt layer is 692 MB against 132 MB, so about 560 MB more. The Dockerfile comment and docs/DEPLOYMENT.md now say so (with your 361 MB apt figure, and the upgraded packages stored again), and the PR body is corrected.
timeout without -k Fixed. The command is now timeout -k 10 300 nice -n 10 ffmpeg …. Return codes 124, 137 and −9 all read as a timeout, and the Python-side limit allows for the extra 10 s. Tests: test_command_is_wrapped_in_timeout and test_conversion_fails_on_ffmpeg_error_and_on_timeout.
No-ffmpeg mode Fixed, all three. (a) A directly stored upload now drops the kept original, the job and the error, and deletes the old original after the commit. test_without_ffmpeg_direct_upload_drops_the_stale_original reproduces your A-then-B case and failed on 040349e. (b) The help text is replaced, not prefixed. (c) The browser check uses 10 MB. Both (b) and (c) are covered by test_without_ffmpeg_help_text_says_so.
aria-describedby Fixed. The script adds its error id to the existing ids and removes it when the error clears, so Django's id_video_helptext link survives. Browser test test_valid_file_restores_aria_describedby failed on 040349e with 'id_video_helptext' not found in ['id_video-size-error'].
stderr dropped Fixed. On failure, run_ffmpeg logs the last 5 non-empty stderr lines. Every path in the command is replaced with <file>, and those paths are server-generated anyway. The error shown in the admin stays short. Test: test_failure_logs_stderr_tail_without_paths.
Description arithmetic Fixed in the PR body: video_utils accounts for the module plus 1 more, not 2.
Unpinned constants Fixed. test_size_backstop_is_wired_and_matches_the_cap asserts BANNER_VIDEO_MAX_BYTES == MAX_SERVED_BYTES and that validate_banner_video_size is on Banner.video.

Your 14 surviving mutations: all now killed

Survivor Killed by
O1 admin commit=False never queues test_banner_add_view_queues_conversion_and_says_so
O2 no extension and signature validator test_disallowed_extension_with_video_header_is_refused
O3 thread never closes its connection test_thread_closes_its_database_connection
O4 no flock test_jobs_take_an_exclusive_lock (counts only the calls on the job's lock file; Django's storage also calls flock)
O10 favourites query without displayable() test_banner_with_only_unconverted_original_is_not_shown, which now has a pending favourite
O23 Convert again without the ffmpeg guard test_convert_again_needs_ffmpeg
O24 without permissions=['change'] test_convert_again_requires_change_permission
O26 keeps a running job's start time test_convert_again_supersedes_a_running_job
O29 no early superseded check test_job_superseded_before_it_starts_does_no_work (neither probe nor convert runs)
O30 backstop removed test_size_backstop_is_wired_and_matches_the_cap
O43, O44 save messages removed the two admin-view tests
O45 over-cap stream copy accepted test_over_cap_stream_copy_falls_back_to_encode
O58 script doesn't stop submit browser test test_oversized_file_blocks_submit_and_is_announced (no POST, role="alert", focus back on the input)

The full mutation run. I re-ran your runner against this head, with patterns updated where this round changed the code, plus 16 new mutations that each undo one of this round's fixes:

  • 87 mutations in all: the PR's 29, your 42 and the 16 new ones.
  • All 87 are killed. O58 needed the browser module, which your runner's entry didn't include.

Suites

Run Result
Current image, no ffmpeg 928 OK, 23 skipped (6 RealFfmpegTests, 17 Playwright)
makelab-1468 (ffmpeg 5.1.9), REQUIRE_FFMPEG=1 928 OK, 17 skipped (Playwright only)
Playwright Chromium: hero, no-image hero, admin size check and member e2e 17 OK
CI on eed6bd9 test, e2e and a11y pass

The browser size-check tests run against the real admin add page. They shrink data-max-upload-bytes in the page so that a 500-byte file stands in for an oversized one.

🤖 Generated with Claude Code — Opus 5.5, claude-opus-5-5

@jonfroehlich jonfroehlich left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review 2 (reviewer 1) — head eed6bd90641ac265a353450300aecc1d2cbe2270, range 040349e..eed6bd9

All 12 findings from review 1 are closed, and I found nothing broken by the fixes. One new nit comes out of the timeout -k change, and five of my new mutations survive (two worth a test). Nothing here is blocking.

Is each finding closed?

Checked on this head with my own probes (real ffmpeg 5.1.9, the real admin views, Chromium), not only with the new tests.

# Finding Closed? What I saw
1 Black hero for a video banner with no image Yes Reduced motion: readyState 4, paused, frame painted. Same after Pause then slide 2, and after moving to slide 2 under reduced motion. In a mixed carousel only the banners with an image are gated and preload="none".
2 -map 0:v:0 picks cover art Yes The crafted file now gives 640×360 H.264, 60 frames, on the copy path, on the encode path (an HEVC source with the picture first), and through the banner add view.
3 60 s clip refused, contradictory message Yes A real 60 s 29.97 fps clip (60.027 s) is accepted. A 60.8 s clip gets "This clip is 60.8 seconds long; … at most 60 seconds." A 250.4 MB file gets "250.4 MB" from the browser (seen in Chromium) and from the server (by its new test).
4 No upload through an admin view Yes The two new view tests kill the three mutations they were written for.
5 Extension allowlist unpinned Yes Mutation killed by test_disallowed_extension_with_video_header_is_refused.
— Image size Yes Dockerfile comment, docs/DEPLOYMENT.md and the description say about 560 MB.
— timeout without -k Yes The prefix is timeout -k 10 300 nice -n 10 ffmpeg. A real encode under a 1 s limit is reported as timed out and leaves no ffmpeg process. See the new nit below.
— No-ffmpeg mode (three parts) Yes A direct upload drops the earlier original, job and error, and deletes the old file. A late job from the earlier upload changes nothing, and "Convert again" reports "had no original upload". The help text is replaced, and the browser limit is 10 MB.
— aria-describedby Yes id_video_helptext → id_video_helptext id_video-size-error → id_video_helptext, also after choosing no file.
— stderr dropped Yes A truncated file logs "moov atom not found | <file>: Invalid data found when processing input". No path appears in the line.
— Description arithmetic Yes
— Unpinned constants Yes Mutation killed by test_size_backstop_is_wired_and_matches_the_cap.

New in this range

Nit: a killed ffmpeg is now reported as a timeout.

  • Return code −9 is treated as "timed out", but timeout also ends with −9 when something else kills ffmpeg, because it re-raises the child's signal.
  • Reproduce: start a slow encode through run_ffmpeg, then pkill -9 -x ffmpeg 1.5 s in. The error is "ffmpeg timed out after 300 s" after 1.54 s, and the log line is "ffmpeg failed with status -9:" with an empty tail.
  • An out-of-memory kill looks the same, so the editor is told to expect a timeout for a job that died in seconds. On 040349e this read "ffmpeg exited with status -9".
  • Fix: time the run, and call −9 or 137 a timeout only when at least FFMPEG_TIMEOUT_SECONDS have passed.
  • I never saw 137 from Python: both the -k kill and an outside kill arrive as −9.

Nit: a test class leaks a temp directory. HeroVideoLoadingTests uses override_settings(MEDIA_ROOT=tempfile.mkdtemp()) at class level, so the directory is created at import and never removed. The other new classes clean up per test.

Nit: description typo. "forced from the file's signature -protocol_whitelist file" is missing a comma.

Mutations

Set Run Killed Survived
The fixer's 16 new (all of them, not a sample) 16 16 0
My 14 survivors from review 1 14 14 0
Earlier ones whose patterns changed in this range (P15, P17b, O14, O20, O27, O39, O61) 7 7 0
My own, new for this range 14 9 5

The five survivors:

Survivor Note
stored_directly = bool(cleaned_data.get('video')) Worth a test. With this slip, any save of a banner that has a video would drop its kept original and cancel its running job. No test edits another field on a banner that has an original. The head is correct: I edited a title mid-conversion through the change view, and the original, the start time and the job's result all survived.
Python-side timeout set below the wrapper's (FFMPEG_TIMEOUT_SECONDS - 30) Worth a test. Python would then kill timeout first and leave ffmpeg running, which is what -k was added to prevent. Nothing asserts the timeout= passed to subprocess.run.
stderr tail keeps every line, not the last 5 minor
Failure log line without the return code minor
Browser size message in whole MB (toFixed(0)) minor; the server's message is pinned, the script's is not

Suites

Run Image Result
Head, full suite site image, no ffmpeg 928 OK, 23 skipped (matches)
Head, full suite, REQUIRE_FFMPEG=1 image with ffmpeg 5.1.9 928 OK, 17 skipped (matches)
Head, hero, admin size check and member browser tests Playwright image, Chromium 17 OK (matches)
This head's tests on 040349e's code ffmpeg image; Playwright image 11 of 128 targeted tests and 3 of 9 browser tests fail, each for a fix it covers
CI on eed6bd9 ubuntu-24.04 test, e2e, a11y pass
  • In that fourth row, the tests added without a code change (admin views, extension, job runner) pass on the old code, as the reply says.
  • The new 9 KB fixture hero_frame.mp4 is what it claims: one H.264 stream, 320×160, 1 s, no tags beyond the encoder's.
  • The added lines and the updated description still meet this repository's rules for public text.

Not verified

  • Firefox and Safari. A banner with no image now has no preload attribute on its inactive slides, where master had autoplay on every slide. Chromium paints the first frame; I could not check that the others do.
  • The CSE proxy, a real iPhone HLG clip, and whether production has video banners with no image (no longer a risk for the tag, since the template is safe either way).

🤖 Review by Claude Code — Fable 5.2, claude-fable-5-2

…1477)

- run_ffmpeg reads 137 / -9 as a timeout only once FFMPEG_TIMEOUT_SECONDS
  have passed. timeout re-raises its child's signal, so an OOM kill or an
  operator's kill seconds in was reported as "timed out after 300 s"; it
  now reads "ffmpeg exited with status -9". 124 is always a timeout.
- Tests: a title edit mid-conversion keeps the kept original and the
  running job (pins stored_directly to real uploads); Python's subprocess
  limit outlasts timeout plus its -k grace; the failure log keeps only
  the last 5 stderr lines and the status; the browser size message has
  one decimal.
- HeroVideoLoadingTests makes and removes its MEDIA_ROOT per test instead
  of leaking one created at import.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HFUXRa2hBVnK4hXzY8dK68
@jonfroehlich

Copy link
Copy Markdown
Member Author

Response to review 2 (head eed6bd9 → 97e8bf1)

All three nits are fixed, and the two survivors worth a test are now pinned. So are the three minor ones, since each took only a few lines. Everything is in one commit, 97e8bf1.

Nits

Nit Result
A killed ffmpeg is reported as a timeout Fixed. run_ffmpeg now times the run. A return code of 124 is always a timeout. A return code of 137 or −9 counts as a timeout only once FFMPEG_TIMEOUT_SECONDS have passed. A SIGKILL seconds in (an OOM kill, or an operator) now reads "ffmpeg exited with status -9". test_conversion_fails_on_ffmpeg_error_and_on_timeout covers both cases, with the clock patched at 1.5 s and at the limit plus 10 s.
HeroVideoLoadingTests leaks a temp dir Fixed. It now creates its MEDIA_ROOT in setUp and removes it with addCleanup, like the other new classes. The method-level mkdtemp() on test_video_banner_with_image_emits_poster predates this PR, so I left it alone.
PR body: missing comma before -protocol_whitelist file Fixed (body updated).

Surviving mutations

Survivor Killed by
stored_directly = bool(cleaned_data.get('video')) test_editing_another_field_mid_conversion_keeps_the_job: a title edit on a banner that has a video, a kept original and a running job keeps the original file, the start time and the video, and registers no callback
Python's subprocess limit set below the wrapper's test_python_limit_outlasts_the_timeout_wrapper: the timeout= passed to subprocess.run must exceed FFMPEG_TIMEOUT_SECONDS + FFMPEG_KILL_AFTER_SECONDS
The stderr tail keeps every line test_failure_log_keeps_only_the_last_lines_and_the_status: 8 lines in, only the last 5 logged
The failure log line has no return code same test: status 3 must be in the line
The browser message uses toFixed(0) the browser test test_oversized_file_blocks_submit_and_is_announced now asserts the exact text "This file is 0.0 MB; … at most 0.0 MB"

I ran these five mutations, plus one that undoes the −9 fix, against this head with your runner. All 6 were killed.

Suites on 97e8bf1

Run Result
Current image, no ffmpeg 931 OK, 23 skipped
makelab-1468 (ffmpeg 5.1.9), REQUIRE_FFMPEG=1 931 OK, 17 skipped
Playwright Chromium: hero, admin size check and member e2e 17 OK
CI test, e2e and a11y pass

🤖 Generated with Claude Code — Opus 5.5, claude-opus-5-5

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Banner videos: enforce size/format at upload (reject or re-encode oversized videos)

1 participant