Repository navigation
Convert banner videos on upload, cap the served file at 10 MB, fix the hero markup (#1468) - #1477
jonfroehlich wants to merge 6 commits into
Conversation
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
left a comment
There was a problem hiding this comment.
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
6688489such 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
mediagate andpreload="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_probetakes the first video stream that is not an attached picture; both ffmpeg commands map0:v:0, which does not make that exception.- Reproduce: an MP4 with an attached picture whose
udtabox precedestrakinsidemoov. ffprobe listspng(attached picture) as stream 0 andh264as stream 1.probereports the 640×360 H.264;convertreturnsmode='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 withVcopied 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 thecommit=Truebranch.BannerAdminusescommit=Falseand the wrappedsave_m2m. - Mutation: replace
self.save_m2m = save_m2m_then_queuewithpass. 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)fromclean_video. All 111 targeted tests pass. - That call is the only check on the convert path:
video_originalhas no validators and takes its extension from the upload's name. Without it, by my reading of the code (not run), a real video namedclip.htmlwould 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. Theaptlayer 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 ffmpegreports 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 300has no-k. If ffmpeg does not exit on SIGTERM,timeoutwaits, Python killstimeoutat 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 300ends it;timeoutthen dies by SIGKILL itself (return code −9), so treat that as a timeout too.- No-ffmpeg mode.
- A direct upload leaves the earlier
video_originaland 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.
- A direct upload leaves the earlier
aria-describedby. Django putsaria-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_BYTESis kept equal toMAX_SERVED_BYTESby a comment only, and removingvalidate_banner_video_sizefromBanner.videofails 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_originaland 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 1is reported as timed out and no ffmpeg process is left. - Commands: argv lists, demuxer forced,
-protocol_whitelist fileon 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
currentSrcset andreadyState 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-runon this head reports the three added fields and the alteredvideofield, 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
-knit used a stand-in).
🤖 Review by Claude Code — Fable 5.2, claude-fable-5-2
…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
Response to review 1 (head
|
| 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
left a comment
There was a problem hiding this comment.
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
timeoutalso ends with −9 when something else kills ffmpeg, because it re-raises the child's signal. - Reproduce: start a slow encode through
run_ffmpeg, thenpkill -9 -x ffmpeg1.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
040349ethis read "ffmpeg exited with status -9". - Fix: time the run, and call −9 or 137 a timeout only when at least
FFMPEG_TIMEOUT_SECONDShave passed. - I never saw 137 from Python: both the
-kkill 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.mp4is 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
preloadattribute on its inactive slides, wheremasterhadautoplayon 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
Response to review 2 (head
|
| 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
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 byBannerAdminand by the project page'sBannerInline) checks it inclean_video: extension and signature, the 250 MB ceiling, thenffprobe(a real video stream, at most 60 s, frame at most 4096 px, landscape, not PQ HDR).clean_videochanges nothing. The form'ssave()stores the upload asBanner.video_originalunder a server-generated name, setsvideo_conversion_started, and registers the job withtransaction.on_commit. After the commit, a daemon thread in the Gunicorn worker converts it (one job at a time across workers, viafcntl.flock) and setsBanner.videowith oneUPDATEfiltered 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.264yuv420p, 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 onelibx264pass:-maxrate min(2500, 72000/duration)kbit/s;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 fileand-map 0:V:0(so cover art is never picked), and runs undertimeout -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
2.3 MB .mp4,14.2 MB .mov (over 10 MB),converting…,interrupted(started more than 30 minutes ago and never finished) orconversion failed: <reason>.banner_video_size_check.js,role="alert").Without ffmpeg (the checkout can be ahead of the image during a deploy), an upload of 10 MB or less is stored as
Banner.videoexactly as before and a larger one is refused. The help text says so, and/version.jsonreports"ffmpeg": false.validate_banner_video_sizeonBanner.videois 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 claimvideo/quicktimeand would skip a file it can play.preload="none"and each<source>is gated withmedia="(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.jslifts the gate (and callsload()) insetVideoPlaybackwhenever 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
Bannercolumns (video_original,video_conversion_started,video_conversion_error), plus help text and validators onvideo. In a copy of this branch, starting from migrations generated offmaster,makemigrations --check --dry-runreports only those three added fields and the alteredvideofield.Image, CI and docs.
ffmpeg, which grows the image's apt layer by about 560 MB (132 MB to 692 MB).testjob installs ffmpeg and setsREQUIRE_FFMPEG=1. Thee2ejob runs the new hero module.CLAUDE.mdgets a "Banner videos" section and a testing note, anddocs/DEPLOYMENT.mdcovers ffmpeg as an image dependency, the/version.jsonfield and the test-server checks.Tests (written first)
Commit 69c6b8c adds the tests alone; 040349e adds the code.
On the pre-change code:
BannerAdminForm(29 tests),video_utils(the wholetest_video_utilsmodule and 1 more), andvalidate_banner_video_size(2).test_hero_motion:type="video/mp4"on.webmand.movsources (2 tests);autoplayon every slide:[True, True, True] != [True, False, False];preload="none";mediagate.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.test_form_save_after_finished_conversion_keeps_new_videoand the three existingtest_hero_motiontests.Suite results.
RealFfmpegTests, 17 Playwright)REQUIRE_FFMPEG=1RealFfmpegTestsran(These counts are after review 2; the table of failures above is for the first tests-only commit.)
RealFfmpegTestschecks four things with the real commands:yuv420p, no audio, the index at the front, and a frame inside 1600×900;locationtag;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.
-an/+faststart/-map_metadata -1/-pix_fmt yuv420ptest_command_drops_audio_strips_metadata_and_sets_faststart(alsoRealFfmpegTestsfor faststart and metadata)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-maxrate; maxrate ignores durationtest_bitrate_ceiling_follows_duration,test_retry_runs_once_when_result_is_over_capBanner.videotest_failed_conversion_keeps_original_and_records_error,test_result_over_cap_is_never_served,test_superseded_job_changes_nothingtest_original_name_is_server_generatedtest_failed_conversion_keeps_original_and_records_errorvideo_originalinbase.htmltest_public_pages_never_reference_originaltest_superseded_job_changes_nothing(sub-cases)on_commit, inclean_videotest_invalid_other_field_stores_nothing_and_registers_no_jobtest_cleared_video_cancels_running_joband 2 moretest_unchanged_video_is_not_probed_again, the guardtest_without_ffmpeg_small_upload_is_kept_and_large_one_rejectedBannerInline.formtest_inline_form_is_banner_admin_formtest_stream_copy_refused_when_not_h264,_over_10mbtimeoutwrappertest_command_is_wrapped_in_timeouttest_job_older_than_30_minutes_reads_as_interrupted,test_video_column_shows_size_converting_failed_and_interruptedvideo/mp4;autoplayon every slide; drop themediagatetest_hero_motionadditionscarousel.jsungates only the slide active when Play is pressedtest_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.
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.The public hero looks the same as before; only what it downloads changes.
Provisional decisions (plan section 13; implemented on its recommendations)
GUNICORN_TIMEOUTis unchanged. Decide after the test-server upload checks; the alternative is a lower ceiling.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
docs/DEPLOYMENT.mdlists the 100, 200 and 250 MB uploads to try on the test server before tagging.mediagate,preload="none", the no-image first frame and the Play behaviour were checked in Chromium only.🤖 Generated with Claude Code — Opus 5.5, claude-opus-5-5