Skip to content

Commit 196d62f

Browse files
jedwards27Carl
andauthored
fix(media): accept portrait video resolutions (block#6058)
## Summary - apply the existing 2160×3840 video resolution envelope independent of orientation - accept portrait recordings whose short/long edges fit that envelope - retain rejection coverage for either edge exceeding its limit - make the relay error describe the orientation-independent limits ## Why The iOS simulator produces portrait H.264 recordings such as 1206×2622. The relay previously checked `width <= 3840 && height <= 2160`, so the equivalent portrait dimensions were rejected while landscape dimensions were accepted. ## Validation - `bin/just ci` - `cargo test -p buzz-media` (120 passed; one MinIO integration test ignored by its existing live-service guard) - `cargo clippy -p buzz-media --all-targets -- -D warnings` - exact blocked artifact `/Users/judeedwards/.buzz/.scratch/pr5874-mongo-evidence/native/head-20260816T050317Z/video-bitexact.mp4` validated through `validate_video_file`: 1206×2622 accepted Signed-off-by: Carl <5f365698229751c0461f57bb03a4e93134e6e936bd7039ebe7b737282a43c754@buzz.block.builderlab.xyz> Co-authored-by: Carl <5f365698229751c0461f57bb03a4e93134e6e936bd7039ebe7b737282a43c754@buzz.block.builderlab.xyz>
1 parent fe7c680 commit 196d62f

2 files changed

Lines changed: 48 additions & 5 deletions

File tree

‎crates/buzz-media/src/error.rs‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,10 @@ pub enum MediaError {
7272
/// Video duration exceeds the 600-second limit.
7373
#[error("video too long: duration exceeds 600 seconds")]
7474
DurationTooLong,
75-
/// Video resolution exceeds 3840×2160.
76-
#[error("video resolution too high: maximum is 3840x2160")]
75+
/// Video resolution exceeds the 2160 short-edge / 3840 long-edge envelope.
76+
#[error(
77+
"video resolution too high: maximum is 2160 on the short edge and 3840 on the long edge"
78+
)]
7779
ResolutionTooHigh,
7880
/// MP4 moov atom appears after mdat — not fast-start.
7981
#[error("moov atom not at front of file (not fast-start)")]

‎crates/buzz-media/src/validation.rs‎

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ pub fn validate_content(bytes: &[u8], config: &MediaConfig) -> Result<String, Me
294294
/// - Exactly one video track using `avc1` (H.264 only — rejects HEVC, VP9, AV1)
295295
/// - At most one audio track, using `mp4a` (AAC)
296296
/// - Duration ≤ 600 seconds (from mvhd timescale, not edit lists)
297-
/// - Resolution ≤ 3840×2160
297+
/// - Resolution: short edge ≤ 2160 and long edge ≤ 3840 (portrait or landscape)
298298
/// - moov atom precedes mdat (fast-start / web-optimised)
299299
///
300300
/// Returns [`VideoMeta`] on success.
@@ -370,10 +370,14 @@ pub fn validate_video_file(path: &Path, config: &MediaConfig) -> Result<VideoMet
370370
return Err(MediaError::DurationTooLong);
371371
}
372372

373-
// Resolution check.
373+
// Resolution check. Apply the 2160×3840 envelope independent
374+
// of orientation so equivalent portrait and landscape videos
375+
// receive the same treatment.
374376
let width = track.width() as u32;
375377
let height = track.height() as u32;
376-
if width > 3840 || height > 2160 {
378+
let short_edge = width.min(height);
379+
let long_edge = width.max(height);
380+
if short_edge > 2160 || long_edge > 3840 {
377381
return Err(MediaError::ResolutionTooHigh);
378382
}
379383

@@ -2547,6 +2551,43 @@ mod tests {
25472551
);
25482552
}
25492553

2554+
#[test]
2555+
fn test_validate_video_accepts_portrait_resolution() {
2556+
let mp4_bytes = build_mp4_bytes(true, b"avc1", 1_000, 2160, 3840, false);
2557+
let tmp = tempfile::NamedTempFile::new().unwrap();
2558+
std::fs::write(tmp.path(), &mp4_bytes).unwrap();
2559+
2560+
let meta = validate_video_file(tmp.path(), &test_config())
2561+
.expect("portrait video within the 2160x3840 envelope should be accepted");
2562+
assert_eq!((meta.width, meta.height), (2160, 3840));
2563+
}
2564+
2565+
#[test]
2566+
fn test_validate_video_rejects_resolution_above_short_edge_limit() {
2567+
let mp4_bytes = build_mp4_bytes(true, b"avc1", 1_000, 2161, 3840, false);
2568+
let tmp = tempfile::NamedTempFile::new().unwrap();
2569+
std::fs::write(tmp.path(), &mp4_bytes).unwrap();
2570+
2571+
let result = validate_video_file(tmp.path(), &test_config());
2572+
assert!(
2573+
matches!(result, Err(MediaError::ResolutionTooHigh)),
2574+
"expected ResolutionTooHigh, got {result:?}"
2575+
);
2576+
}
2577+
2578+
#[test]
2579+
fn test_validate_video_rejects_resolution_above_long_edge_limit() {
2580+
let mp4_bytes = build_mp4_bytes(true, b"avc1", 1_000, 2160, 3841, false);
2581+
let tmp = tempfile::NamedTempFile::new().unwrap();
2582+
std::fs::write(tmp.path(), &mp4_bytes).unwrap();
2583+
2584+
let result = validate_video_file(tmp.path(), &test_config());
2585+
assert!(
2586+
matches!(result, Err(MediaError::ResolutionTooHigh)),
2587+
"expected ResolutionTooHigh, got {result:?}"
2588+
);
2589+
}
2590+
25502591
#[test]
25512592
fn test_validate_video_resolution_too_high() {
25522593
let config = test_config();

0 commit comments

Comments
 (0)