Skip to content

perf: media-io: let video_scaler_scale write straight into the output frame #3192

Closed

Description

@zackees

What

libobs/media-io/video-scaler-ffmpeg.c.h:234-260 runs sws_scale into its own buffer, then memcpys each plane into the caller's preallocated frame (video-io.c.h:98-105). About 1.2 ms per frame at 4K NV12.

Proposed change

Pass output[]/out_linesize to sws_scale; keep the internal buffer only for mismatched linesizes.

Acceptance criteria

  • Before/after numbers (Criterion bench of video_scaler_scale at 1080p and 4K (BGRA to NV12, 4K to 1080p)) in the PR; nothing lands unmeasured.
  • RED then GREEN; Tier 3 parity stays bit-exact unless this issue says otherwise.

Found by a read-only code scout and not yet measured. Parent: #3176.

Activity

  1. added
    enhancement
    P2
    size:S
    on Oct 31, 2026
  2. zackees commented on Oct 31, 2026

    @zackees
    MemberAuthor

    /ready

  3. added
    ready
    on Oct 31, 2026
  4. zackees commented on Nov 1, 2026

    @zackees
    MemberAuthor

    Claiming: perf: media-io: let video_scaler_scale write straight into the output frame

    Plan, one PR:

    1. RED: a new cmocka test scales BGRA→NV12 (1080p, and 4K→1080p) twice. Once into a frame whose planes match the scaler's internal layout (32-byte aligned pointers, linesizes ≥ the av_image_alloc linesizes and multiples of 32), and once into a frame with an odd linesize (+16). It requires identical visible bytes from both, which pins bit-exactness between the direct and the fallback path. A timing line per case (ns per frame, median of N) goes into the PR. The C oracle's copy of video_scaler_scale (rust/obs-c-oracle/oracle/video_io.c) stays the reference and is not changed, so a Criterion bench through the oracle would measure the old code. The before/after numbers therefore come from the same C test binary built on master and on the branch.
    2. GREEN: when every output plane meets that layout, sws_scale writes into output[]/out_linesize directly. Rows then have the same padding as the internal buffer, so swscale's SIMD row writes stay inside each row and the bytes are identical. Otherwise the internal buffer and plane copy stay as today. Frames from video_frame_init use the 32-byte base alignment, so the common 1080p/720p NV12 and I420 cases take the direct path.
    3. Tiers: libobs C only, Tier 2 (the new test and the existing scaler tests). Tier 3 is unchanged, since the oracle copy is untouched.

    First PR next tick.

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

Metadata

Metadata

Assignees

Labels

P2enhancementreadysize:S

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions