Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error while creating and feeding Frames from raw data #2460

Closed
Urhengulas opened this issue Jul 20, 2020 · 1 comment
Closed

Error while creating and feeding Frames from raw data #2460

Urhengulas opened this issue Jul 20, 2020 · 1 comment

Comments

@Urhengulas
Copy link
Contributor

Urhengulas commented Jul 20, 2020

I am trying to create a new api::Frame<u8> from raw pixel data, but am getting the following panic:

thread '<unnamed>' panicked at 'assertion failed: cfg.xorigin as isize + rect.x + rect.width as isize <= cfg.stride as isize', $HOME/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libstd/macros.rs:13:23
Full output
Frame 0 in
---
Frame 1 in
---
Frame 2 in
---
Frame 3 in
---
Frame 4 in
---
Frame 5 in
---
Frame 6 in
---
Frame 7 in
---
Frame 8 in
---
Frame 9 in
---
Frame 10 in
Start compute_motion_vectors
[src/tiling/plane_region.rs:352] cfg = PlaneConfig {
    stride: 480,
    alloc_height: 456,
    width: 456,
    height: 456,
    xdec: 0,
    ydec: 0,
    xpad: 0,
    ypad: 0,
    xorigin: 0,
    yorigin: 0,
}
[src/tiling/plane_region.rs:352] rect = Rect {
    x: 0,
    y: 0,
    width: 640,
    height: 480,
}
thread '<unnamed>' panicked at 'assertion failed: cfg.xorigin as isize + rect.x + rect.width as isize <= cfg.stride as isize', /home/urhengulas/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libstd/macros.rs:13:23
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

The panic originates from src/tiling/plane_region.rs#L154.

code

I am using following code, which is inspired by src/bin/decoder/y4m.rs#L47

use rav1e::prelude::*;

fn main() {
  let width = 450;
  let height = 450;

  // mock data
  let buf = {
    let len = width * height;
    let mut buf = Vec::with_capacity(len);
    buf.resize(len, 0_u8);
    buf
  };
  let data = vec![buf.clone(), buf.clone(), buf];

  let chroma_sampling = ChromaSampling::Cs444;
  let (chroma_width, _) = chroma_sampling.get_chroma_dimensions(width, height);

  let mut f: Frame<u8> = Frame::new_with_padding(width, height, chroma_sampling, 0);
  f.planes[0].copy_from_raw_u8(data[0].as_slice(), width, 1);
  f.planes[1].copy_from_raw_u8(data[1].as_slice(), chroma_width, 1);
  f.planes[2].copy_from_raw_u8(data[2].as_slice(), chroma_width, 1);

  let mut conf = EncoderConfig::default();
  conf.color_description = Some(ColorDescription {
    color_primaries: ColorPrimaries::BT709,
    transfer_characteristics: TransferCharacteristics::BT709,
    matrix_coefficients: MatrixCoefficients::BT709,
  });
  let mut ctx = Config::new().with_encoder_config(conf).new_context().unwrap();
  for _ in 0..70 {
    ctx.send_frame(f.clone()).unwrap();
  }
  ctx.flush();
  loop {
    match ctx.receive_packet() {
      Ok(p) => eprintln!("{:?}", p),
      Err(e) => {
        eprintln!("{}", e);
        match e {
          EncoderStatus::LimitReached => break,
          EncoderStatus::Encoded => {}
          _ => {
            panic!(e);
          }
        }
      }
    }
  }
}

(You can check the code out at here)

mocking

The data normally comes from fn Canvas.data_i444() -> [Vec<u8>; 3], which is the underlying pixel data (RGBA) from an <img></img> converted to I444, Bt709. I mocked it with the same dimensions for this example for easier reproducability.

status of debugging

The error occurs during the call of ctx.send_frame(...) and I am quite sure it originates from fn rav1e::api::lookahead::compute_motion_vectors(...), but because I don't really understand what is going on in there I have a hard time fixing.

I am sitting on figuring this out since 3 days. Please someone give me a good hint 🥺

@lu-zero
Copy link
Collaborator

lu-zero commented Jul 20, 2020

Probably it is this line:

  let mut f: Frame<u8> = Frame::new_with_padding(width, height, chroma_sampling, 0);

Never use directly Frame::new_with_padding, Context::new_frame() uses the right value for the padding.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants