Repository navigation
feat: render WebP on request, a fifth the size of the PNG - #3
Merged
Merged
Conversation
The Python stack (librosa, numba, OpenCV, matplotlib) is replaced by one ffmpeg command: showspectrumpic draws the spectrogram as intensity and pseudocolor applies matplotlib's viridis, which showspectrumpic's own palette does not match. The image is sized from the decoded sample count so tiles keep the archive's width, and the dB window is converted to ffmpeg's full-scale reference by an offset fitted against a production image. On the same segment the result has production's luminance distribution to within 0.01 and the same width. The request now carries presigned GET and PUT URLs and explicit render parameters, echoed back in the response, so the function knows nothing about S3. The previous bucket/key shape still works, via boto3 from the base image, until orcasite has switched. Image 2.27 GB -> 773 MB, no caches to seed, render 2 s at 1024 MB. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
A spectrogram tile is drawn at a fraction of its pixel size in orcasite's timeline, and the browser downloads every tile it scrolls past, so the archive's RGB PNGs cost far more than they show. The caller can now ask for WebP with `format` and set `quality`, where 100 is lossless. On a production segment, at Lambda's CPU share: PNG 552 KB in 0.90 s, WebP at quality 80 113 KB in 0.88 s, lossless WebP 328 KB in 1.20 s. PNG stays the default so nothing changes for callers that do not ask. The image is stored with the matching Content-Type and the response reports it. The smoke test renders all three. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
WebP sides are at most 16,383 px, which a clip of about 87 seconds reaches at the default hop length. Say so before rendering instead of letting ffmpeg fail obscurely. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The bout page loads every spectrogram tile it scrolls past, and each tile is drawn at a fraction of its pixel size: a 10 s tile is 1877 px wide and the timeline shows it at 267 px by default. The 541 tiles of one bout come to about 420 MB of PNG. This lets the caller ask for WebP instead, which is about a fifth of the size at no visible cost.
What changes
parameters.formatispng(the default, so nothing changes for a caller that does not ask) orwebp, andparameters.qualitysets WebP's quality, with 100 meaning lossless. The image is stored with the matchingContent-Typeand the response reports it ascontent_type. The caller picks the key's extension, since the function writes to whatever key it is given; the orcasite side is orcasound/orcasite#1086.On the production segment in
events/spectrogram_job.json, rendered at Lambda's CPU share:Left is the PNG, right the WebP at quality 80. The top row is each at the size the timeline draws a tile; the bottom row is 160×120 px from the middle of each at 3×, where the WebP's smoothing of the noise floor shows.
What I ruled out
A 256-colour paletted PNG, through ffmpeg's
palettegenandpaletteuse, was 349 KB but shifted some pixels by one level, so it is neither lossless nor as small as lossless WebP. Lossless WebP decodes pixel-identical to the PNG. libwebp's slowest effort level saved another 8% for a tenth of a second more per tile, which is not worth a knob.Verification
tests/smoke.pynow renders the synthetic clip as PNG, WebP and lossless WebP inside the built image as Lambda runs it, checks each file's header for its type and dimensions, and checks that the stored and reported content types agree. On pink noise the lossy and lossless WebPs come out about the same size, since noise is the worst case for a lossy encoder, so the test only requires both to beat the PNG. I also rendered the real segment through the handler in all three formats and confirmed an unknown format is refused with a clear error.WebP sides are at most 16,383 px, which at the default hop length is a clip of about 87 s. A longer clip asked for as WebP is refused before rendering, which I checked on a 90 s clip; the same clip renders as PNG. CodeRabbit's local review raised this; its other suggestion, to fall back to PNG for such a clip, I declined because the caller has already named a
.webpkey.This stacks on #2 and should merge after it. Merging deploys, and orcasite keeps getting PNGs until it asks for WebP.
🤖 Generated with Claude Code