media: the short video class refuses sources above 1080p
At 4 vCPU the spike converted 4K HDR at 0.27 times real time and 4K SDR at 0.71, so not even 5 minutes of 4K HDR fits the short class's budget. The class table now says which class takes a source above 1080p (only the long video class). The short video class's payload sets Above1080pNeedsLong, and the codec answers needs_long_class for such a source after the duration maximum and before the granted duration: the mechanism the class already used for a source over its granted length. The console names the reason from the result's source facts with a new deck row, media.job.needs_long_class_hi, pending Luna pass 6.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
10 files changed,
+142
−26
docs/superpowers/notes/media-conversion-copy-deck.md+4 −0internal/console/apimedia_test.go+19 −0internal/console/media_copy.go+18 −2internal/media/media.go+13 −8internal/media/media_test.go+8 −5internal/media/payload.go+13 −6internal/mediahandler/probe.go+9 −3internal/mediahandler/probe_test.go+25 −1internal/mediajobs/dispatch.go+5 −1internal/mediajobs/jobs_test.go+28 −0
diff --git a/docs/superpowers/notes/media-conversion-copy-deck.md b/docs/superpowers/notes/media-conversion-copy-deck.md| index a05ffc701..bd8fe7377 100644 |
| --- a/docs/superpowers/notes/media-conversion-copy-deck.md |
| +++ b/docs/superpowers/notes/media-conversion-copy-deck.md |
| @@ -81,6 +81,9 @@ object. Placeholders: `source_too_long` and `needs_long_class` take the |
| limit as `mediaDuration` writes it (`2 hours`, `30 minutes`, `10 minutes`); |
| `source_dimensions` takes the maximum as `3840x2160`; `source_frame_rate` takes the maximum frames a second. Codes |
| marked "door copy" reuse the door's message for the same code. |
| +`needs_long_class_hi` has no placeholder: it is `needs_long_class`'s |
| +message when the result's source facts are above 1080p, which the short |
| +video class refuses whatever the length (spec §11 A7). |
| | Key | Message | |
| |---|---| |
| @@ -93,6 +96,7 @@ marked "door copy" reuse the door's message for the same code. |
| | `media.job.source_frame_rate` | `the video has more than %d frames a second` | |
| | `media.job.source_too_long` | `the file is longer than %s, the maximum for this preset` | |
| | `media.job.needs_long_class` | `the file is longer than %s, the most the short class converts. submit it again in the long class` | |
| +| `media.job.needs_long_class_hi` | `the video is larger than 1080p, which only the long class converts. submit it again in the long class` (pending Luna pass 6) | |
| | `media.job.allowance_exceeded` | `this account's media allowance for the month does not cover this file. buy a media pack or move to a larger plan to convert it` | |
| | `media.job.unreadable` | `the file could not be read. it may be damaged or cut short` | |
| | `media.job.output_too_large` | `a converted file would be over 5 GB, the maximum for one output` | |
diff --git a/internal/console/apimedia_test.go b/internal/console/apimedia_test.go| index f0ec2710e..9a1c04b5b 100644 |
| --- a/internal/console/apimedia_test.go |
| +++ b/internal/console/apimedia_test.go |
| @@ -644,6 +644,25 @@ func TestGetFailedMessageComesFromTheDeck(t *testing.T) { |
| r.job.Error.Message != "the file is longer than 10 minutes, the most the short class converts. submit it again in the long class" { |
| t.Fatalf("needs_long_class: %s", r.raw) |
| } |
| + // A short-class job whose source is above 1080p (spec §11 A7): the |
| + // handler's own failure result for a 30-second 2160p source, and the |
| + // deck's row that names the picture size, not a length. |
| + hiProbe := []byte(`{"streams":[{"index":0,"codec_type":"video","codec_name":"hevc","width":3840,"height":2160,` + |
| + `"avg_frame_rate":"30/1","r_frame_rate":"30/1"}],"format":{"duration":"30.000000"}}`) |
| + hi, refused := mediahandler.ProbeFailure("0123456789abcdef0123456789abcdef", media.PresetVideo720p, media.JobLimits{ |
| + SourceBytes: l.VideoBytes, GrantedMS: (10 * time.Minute).Milliseconds(), GrantedBy: "class", |
| + MaxMS: l.VideoMax.Milliseconds(), MaxHiMS: l.VideoMaxHi.Milliseconds(), OutputBytes: media.MaxPutBytes, |
| + Above1080pNeedsLong: true, |
| + }, hiProbe) |
| + if !refused || hi.Error != media.CodeNeedsLongClass { |
| + t.Fatalf("the handler's probe check answered %+v, refused %v", hi, refused) |
| + } |
| + fail("needs_long_class", hi) |
| + if want := mediaCopy["media.job.needs_long_class_hi"]; want == "" { |
| + t.Fatal("the deck has no media.job.needs_long_class_hi row") |
| + } else if r := f.get(sub.job.ID); r.job.Error == nil || r.job.Error.Message != want { |
| + t.Fatalf("needs_long_class above 1080p: %s", r.raw) |
| + } |
| } |
| // TestMediaDoorsRefuseOnHostClaim (spec §11 A1, pre-flight F22): both doors |
diff --git a/internal/console/media_copy.go b/internal/console/media_copy.go| index 6597303c6..1ecbb92f6 100644 |
| --- a/internal/console/media_copy.go |
| +++ b/internal/console/media_copy.go |
| @@ -67,6 +67,7 @@ var mediaCopy = map[string]string{ |
| "media.job.source_frame_rate": "the video has more than %d frames a second", |
| "media.job.source_too_long": "the file is longer than %s, the maximum for this preset", |
| "media.job.needs_long_class": "the file is longer than %s, the most the short class converts. submit it again in the long class", |
| + "media.job.needs_long_class_hi": "the video is larger than 1080p, which only the long class converts. submit it again in the long class", |
| "media.job.allowance_exceeded": "this account's media allowance for the month does not cover this file. buy a media pack or move to a larger plan to convert it", |
| "media.job.unreadable": "the file could not be read. it may be damaged or cut short", |
| "media.job.output_too_large": "a converted file would be over 5 GB, the maximum for one output", |
| @@ -148,14 +149,29 @@ func mediaJobMessage(j mediajobs.Job, l media.Limits) string { |
| return mediaText(key, media.MaxFPS) |
| case media.CodeSourceTooLong: |
| w, h := 0, 0 |
| - if j.Result != nil && j.Result.Source != nil { |
| - w, h = j.Result.Source.Width, j.Result.Source.Height |
| + if s := jobSource(j); s != nil { |
| + w, h = s.Width, s.Height |
| } |
| return mediaText(key, mediaDuration(l.MaxDuration(j.Preset, w, h))) |
| case media.CodeNeedsLongClass: |
| + // The short video class refuses a source above 1080p whatever |
| + // its length (spec §11 A7); the result's facts say which. |
| + if s := jobSource(j); j.Preset == media.PresetVideo720p && s != nil && media.Above1080p(s.Width, s.Height) { |
| + return mediaText("media.job.needs_long_class_hi") |
| + } |
| return mediaText(key, mediaDuration(l.Granted(media.ClassKey{Preset: j.Preset, Class: media.ClassShort}))) |
| case media.CodeSourceTooLarge: |
| return mediaText(key, billingBytes(j.Bytes), j.Preset, billingBytes(l.MaxBytes(j.Preset))) |
| } |
| return mediaText(key) |
| } |
| + |
| +// jobSource is the source facts a job's stored result carries: the |
| +// probe's, on a done job or a failure the probe refused; nil when there |
| +// are none. |
| +func jobSource(j mediajobs.Job) *media.SourceFacts { |
| + if j.Result == nil { |
| + return nil |
| + } |
| + return j.Result.Source |
| +} |
diff --git a/internal/media/media.go b/internal/media/media.go| index 07c5c421c..179484d6a 100644 |
| --- a/internal/media/media.go |
| +++ b/internal/media/media.go |
| @@ -36,19 +36,24 @@ func (k ClassKey) String() string { return k.Preset + "/" + k.Class } |
| // PickUpTo is the largest source the short class takes when no class is |
| // asked for (0 on a long row: any size). CPU is in ECS CPU units (1024 per |
| // vCPU) and MemoryMiB in MiB, as RunTask's overrides take them. Granted 0 |
| -// means the preset maximum (Limits.Granted). |
| +// means the preset maximum (Limits.Granted). TakesAbove1080p is whether |
| +// the class converts a video source above 1080p (Above1080p): only the |
| +// long video class does; on the short one the codec answers |
| +// needs_long_class (spec §11 A7: at 4 vCPU the spike converted 4K HDR at |
| +// 0.27 times real time). Audio rows never meet one and leave it false. |
| type ClassSpec struct { |
| - Key ClassKey |
| - PickUpTo int64 |
| - CPU int |
| - MemoryMiB int |
| - Deadline time.Duration |
| - Granted time.Duration |
| + Key ClassKey |
| + PickUpTo int64 |
| + CPU int |
| + MemoryMiB int |
| + Deadline time.Duration |
| + Granted time.Duration |
| + TakesAbove1080p bool |
| } |
| var classes = map[ClassKey]ClassSpec{ |
| {PresetVideo720p, ClassShort}: {Key: ClassKey{PresetVideo720p, ClassShort}, PickUpTo: 1 << 30, CPU: 4 * 1024, MemoryMiB: 8 * 1024, Deadline: 15 * time.Minute, Granted: 10 * time.Minute}, |
| - {PresetVideo720p, ClassLong}: {Key: ClassKey{PresetVideo720p, ClassLong}, CPU: 16 * 1024, MemoryMiB: 32 * 1024, Deadline: 50 * time.Minute}, |
| + {PresetVideo720p, ClassLong}: {Key: ClassKey{PresetVideo720p, ClassLong}, CPU: 16 * 1024, MemoryMiB: 32 * 1024, Deadline: 50 * time.Minute, TakesAbove1080p: true}, |
| {PresetAudioAAC, ClassShort}: {Key: ClassKey{PresetAudioAAC, ClassShort}, PickUpTo: 256 << 20, CPU: 1 * 1024, MemoryMiB: 2 * 1024, Deadline: 10 * time.Minute, Granted: 2 * time.Hour}, |
| {PresetAudioAAC, ClassLong}: {Key: ClassKey{PresetAudioAAC, ClassLong}, CPU: 2 * 1024, MemoryMiB: 4 * 1024, Deadline: 50 * time.Minute}, |
| } |
diff --git a/internal/media/media_test.go b/internal/media/media_test.go| index 245092289..c5999afce 100644 |
| --- a/internal/media/media_test.go |
| +++ b/internal/media/media_test.go |
| @@ -115,14 +115,17 @@ func TestClassTable(t *testing.T) { |
| key ClassKey |
| cpu, mem int |
| deadline, granted time.Duration |
| + hi bool |
| }{ |
| - {ClassKey{PresetVideo720p, ClassShort}, 4096, 8192, 15 * time.Minute, 10 * time.Minute}, |
| - {ClassKey{PresetVideo720p, ClassLong}, 16384, 32768, 50 * time.Minute, 2 * time.Hour}, |
| - {ClassKey{PresetAudioAAC, ClassShort}, 1024, 2048, 10 * time.Minute, 2 * time.Hour}, |
| - {ClassKey{PresetAudioAAC, ClassLong}, 2048, 4096, 50 * time.Minute, 8 * time.Hour}, |
| + // Above 1080p converts on the long video class only (spec §11 A7): |
| + // at 4 vCPU 4K HDR ran at 0.27 times real time. |
| + {ClassKey{PresetVideo720p, ClassShort}, 4096, 8192, 15 * time.Minute, 10 * time.Minute, false}, |
| + {ClassKey{PresetVideo720p, ClassLong}, 16384, 32768, 50 * time.Minute, 2 * time.Hour, true}, |
| + {ClassKey{PresetAudioAAC, ClassShort}, 1024, 2048, 10 * time.Minute, 2 * time.Hour, false}, |
| + {ClassKey{PresetAudioAAC, ClassLong}, 2048, 4096, 50 * time.Minute, 8 * time.Hour, false}, |
| } { |
| s, ok := Class(c.key) |
| - if !ok || s.Key != c.key || s.CPU != c.cpu || s.MemoryMiB != c.mem || s.Deadline != c.deadline { |
| + if !ok || s.Key != c.key || s.CPU != c.cpu || s.MemoryMiB != c.mem || s.Deadline != c.deadline || s.TakesAbove1080p != c.hi { |
| t.Errorf("Class(%s) = %+v, %v", c.key, s, ok) |
| } |
| if s.Deadline > MaxDeadline { |
diff --git a/internal/media/payload.go b/internal/media/payload.go| index e97124aef..443803c24 100644 |
| --- a/internal/media/payload.go |
| +++ b/internal/media/payload.go |
| @@ -98,13 +98,20 @@ func SplitPresigned(raw string) (base, shared, rest string, err error) { |
| } |
| // JobLimits are the limits the codec enforces on one execution. |
| +// |
| +// Above1080pNeedsLong is set on a video class that does not take a source |
| +// above 1080p (ClassSpec.TakesAbove1080p false: the short video class). |
| +// The codec then answers needs_long_class for such a source, after the |
| +// duration maximum and before the granted duration (spec §11 A7). It is |
| +// omitted when false, so a payload without it reads as before. |
| type JobLimits struct { |
| - SourceBytes int64 `json:"b"` |
| - GrantedMS int64 `json:"g"` |
| - GrantedBy string `json:"gb"` // "class" | "allowance" |
| - MaxMS int64 `json:"d"` |
| - MaxHiMS int64 `json:"dh"` // video sources above 1080p; 0 for audio |
| - OutputBytes int64 `json:"o"` |
| + SourceBytes int64 `json:"b"` |
| + GrantedMS int64 `json:"g"` |
| + GrantedBy string `json:"gb"` // "class" | "allowance" |
| + MaxMS int64 `json:"d"` |
| + MaxHiMS int64 `json:"dh"` // video sources above 1080p; 0 for audio |
| + OutputBytes int64 `json:"o"` |
| + Above1080pNeedsLong bool `json:"hl,omitempty"` |
| } |
| // Payload is the codec's whole input, one environment variable |
diff --git a/internal/mediahandler/probe.go b/internal/mediahandler/probe.go| index f76045e37..0481b654c 100644 |
| --- a/internal/mediahandler/probe.go |
| +++ b/internal/mediahandler/probe.go |
| @@ -539,9 +539,11 @@ func allDigits(s string) bool { |
| // 5. (video-720p) over media.MaxFPS: source_frame_rate; |
| // 6. longer than MaxHiMS (video above 1080p, media.Above1080p) or |
| // MaxMS: source_too_long (no positive duration: unreadable); |
| -// 7. longer than GrantedMS: needs_long_class when the class granted |
| +// 7. (video-720p) above 1080p when Above1080pNeedsLong (the short |
| +// class, spec §11 A7): needs_long_class; |
| +// 8. longer than GrantedMS: needs_long_class when the class granted |
| // it, else allowance_exceeded; |
| -// 8. Dolby Vision profile 5, only when refuseDolbyVision5: |
| +// 9. Dolby Vision profile 5, only when refuseDolbyVision5: |
| // unsupported_hdr. |
| // |
| // An unknown preset is engine_failed: the payload was validated. |
| @@ -574,13 +576,17 @@ func check(f probeFacts, preset string, l media.JobLimits) error { |
| if f.DurationMS <= 0 { |
| return jobError{media.CodeUnreadable} |
| } |
| + hi := video && media.Above1080p(f.Width, f.Height) |
| maxMS := l.MaxMS |
| - if video && media.Above1080p(f.Width, f.Height) { |
| + if hi { |
| maxMS = l.MaxHiMS |
| } |
| if f.DurationMS > maxMS { |
| return jobError{media.CodeSourceTooLong} |
| } |
| + if hi && l.Above1080pNeedsLong { |
| + return jobError{media.CodeNeedsLongClass} |
| + } |
| if f.DurationMS > l.GrantedMS { |
| if l.GrantedBy == grantedByClass { |
| return jobError{media.CodeNeedsLongClass} |
diff --git a/internal/mediahandler/probe_test.go b/internal/mediahandler/probe_test.go| index 6b20eb4d9..8cad4fb55 100644 |
| --- a/internal/mediahandler/probe_test.go |
| +++ b/internal/mediahandler/probe_test.go |
| @@ -290,6 +290,29 @@ func TestCheckTable(t *testing.T) { |
| {"audio has no hi maximum", audio, func(f *probeFacts, l *media.JobLimits) { |
| f.Width, f.Height, f.DurationMS = 3840, 2160, l.MaxMS |
| }, ""}, |
| + // The short video class takes nothing above 1080p (spec §11 A7). |
| + {"short class: above 1080p needs the long class", video, func(f *probeFacts, l *media.JobLimits) { |
| + l.Above1080pNeedsLong = true |
| + f.Width, f.Height = 3840, 2160 |
| + }, media.CodeNeedsLongClass}, |
| + {"short class: 1920x1081 needs the long class", video, func(f *probeFacts, l *media.JobLimits) { |
| + l.Above1080pNeedsLong = true |
| + f.Width, f.Height = 1920, 1081 |
| + }, media.CodeNeedsLongClass}, |
| + {"short class: 1080p converts", video, func(_ *probeFacts, l *media.JobLimits) { l.Above1080pNeedsLong = true }, ""}, |
| + {"short class: 1080p portrait converts", video, func(f *probeFacts, l *media.JobLimits) { |
| + l.Above1080pNeedsLong = true |
| + f.Width, f.Height = 1080, 1920 |
| + }, ""}, |
| + {"short class: over the hi maximum is too long first", video, func(f *probeFacts, l *media.JobLimits) { |
| + l.Above1080pNeedsLong = true |
| + f.Width, f.Height, f.DurationMS = 3840, 2160, l.MaxHiMS+1 |
| + }, media.CodeSourceTooLong}, |
| + {"long class: above 1080p converts", video, func(f *probeFacts, _ *media.JobLimits) { f.Width, f.Height = 3840, 2160 }, ""}, |
| + {"audio ignores the short-class rule", audio, func(f *probeFacts, l *media.JobLimits) { |
| + l.Above1080pNeedsLong = true |
| + f.Width, f.Height = 3840, 2160 |
| + }, ""}, |
| {"over the class grant", video, func(f *probeFacts, l *media.JobLimits) { l.GrantedMS = 600000; f.DurationMS = 600001 }, media.CodeNeedsLongClass}, |
| {"at the class grant", video, func(f *probeFacts, l *media.JobLimits) { l.GrantedMS = 600000; f.DurationMS = 600000 }, ""}, |
| {"over the allowance", audio, func(f *probeFacts, l *media.JobLimits) { |
| @@ -361,7 +384,7 @@ func TestCheckOrder(t *testing.T) { |
| // Every check fails: no audio stream, wrong codecs, too big, |
| // too fast, too long for everything, Dolby Vision 5. |
| return probeFacts{VideoIndex: -1, AudioIndex: 2, Width: 30000, Height: 30000, FPS: 240, VideoCodec: "mpeg4", AudioCodec: "ac3", DurationMS: 99999999, DolbyVisionProfile: 5, HDR: true}, |
| - media.JobLimits{GrantedMS: 600000, GrantedBy: grantedByClass, MaxMS: 7200000, MaxHiMS: 1800000} |
| + media.JobLimits{GrantedMS: 600000, GrantedBy: grantedByClass, MaxMS: 7200000, MaxHiMS: 1800000, Above1080pNeedsLong: true} |
| } |
| old := refuseDolbyVision5 |
| refuseDolbyVision5 = true |
| @@ -376,6 +399,7 @@ func TestCheckOrder(t *testing.T) { |
| {media.CodeSourceDimensions, func(f *probeFacts, _ *media.JobLimits) { f.Width, f.Height = 3840, 2160 }}, |
| {media.CodeSourceFrameRate, func(f *probeFacts, _ *media.JobLimits) { f.FPS = 30 }}, |
| {media.CodeSourceTooLong, func(f *probeFacts, _ *media.JobLimits) { f.DurationMS = 1800000 }}, |
| + {media.CodeNeedsLongClass, func(_ *probeFacts, l *media.JobLimits) { l.Above1080pNeedsLong = false }}, |
| {media.CodeNeedsLongClass, func(f *probeFacts, _ *media.JobLimits) { f.DurationMS = 600000 }}, |
| {media.CodeUnsupportedHDR, func(f *probeFacts, _ *media.JobLimits) { f.DolbyVisionProfile = 8 }}, |
| {"", nil}, |
diff --git a/internal/mediajobs/dispatch.go b/internal/mediajobs/dispatch.go| index 55761eb16..614fdc31c 100644 |
| --- a/internal/mediajobs/dispatch.go |
| +++ b/internal/mediajobs/dispatch.go |
| @@ -361,9 +361,11 @@ func (j *Jobs) launch(ctx context.Context, l *Launch, now time.Time) (started bo |
| } |
| return false, ErrLaunchStale |
| } |
| - maxMS, maxHiMS := j.d.Limits.AudioMax.Milliseconds(), int64(0) |
| + maxMS, maxHiMS, hiNeedsLong := j.d.Limits.AudioMax.Milliseconds(), int64(0), false |
| if job.Preset == media.PresetVideo720p { |
| maxMS, maxHiMS = j.d.Limits.VideoMax.Milliseconds(), j.d.Limits.VideoMaxHi.Milliseconds() |
| + spec, _ := media.Class(media.ClassKey{Preset: job.Preset, Class: job.Class}) |
| + hiNeedsLong = !spec.TakesAbove1080p |
| } |
| p := media.Payload{ |
| V: media.PayloadVersion, Execution: job.Execution, Preset: job.Preset, |
| @@ -374,6 +376,8 @@ func (j *Jobs) launch(ctx context.Context, l *Launch, now time.Time) (started bo |
| MaxMS: maxMS, |
| MaxHiMS: maxHiMS, |
| OutputBytes: media.MaxPutBytes, |
| + // The short video class takes nothing above 1080p (A7). |
| + Above1080pNeedsLong: hiNeedsLong, |
| }, |
| Expiry: expiry.Unix(), |
| Transfers: transfers, |
diff --git a/internal/mediajobs/jobs_test.go b/internal/mediajobs/jobs_test.go| index 64d96317c..8af8b808f 100644 |
| --- a/internal/mediajobs/jobs_test.go |
| +++ b/internal/mediajobs/jobs_test.go |
| @@ -1801,3 +1801,31 @@ func TestPassStopsTheClassAfterAFailedLaunch(t *testing.T) { |
| t.Fatalf("%d Runs in one pass, want 1", n) |
| } |
| } |
| + |
| +// TestShortVideoRefusesAbove1080p (spec §11 A7): the short video class's |
| +// payload asks the codec to refuse a source above 1080p with |
| +// needs_long_class; the long video class and both audio classes do not. |
| +func TestShortVideoRefusesAbove1080p(t *testing.T) { |
| + h := newHarness(t, "account_short=4,account_long=4,long=4", nil) |
| + for _, c := range []struct { |
| + key, preset, class string |
| + size int64 |
| + want bool |
| + }{ |
| + {"uploads/short.mov", video, "", 10 << 20, true}, |
| + {"uploads/long.mov", video, media.ClassLong, 10 << 20, false}, |
| + {"uploads/short.m4a", audio, "", 10 << 20, false}, |
| + {"uploads/long.m4a", audio, media.ClassLong, 10 << 20, false}, |
| + } { |
| + j := h.submit("acct1", "shop", c.key, c.preset, c.class, c.size) |
| + r, _ := h.run(j) |
| + req := h.eng.Requests(r.Execution) |
| + var p media.Payload |
| + if len(req) != 1 || json.Unmarshal(req[0].Payload, &p) != nil { |
| + t.Fatalf("%s: no payload", c.key) |
| + } |
| + if p.Limits.Above1080pNeedsLong != c.want { |
| + t.Errorf("%s (%s): Above1080pNeedsLong %v, want %v", c.key, r.Class, p.Limits.Above1080pNeedsLong, c.want) |
| + } |
| + } |
| +} |