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

Video frame dump and alloc issue related to alignment #198

Open
zhen9910 opened this issue Jul 11, 2024 · 0 comments
Open

Video frame dump and alloc issue related to alignment #198

zhen9910 opened this issue Jul 11, 2024 · 0 comments

Comments

@zhen9910
Copy link

  • Issue

examples/dump-frames works fine if frame width and height are multiple of 32 bytes. But I find it generated corrupted image if input or output size is 300*300 pixels.

I used 300*300 in the test is because many pre-trained object detection models are typically designed to accept inputs of a specific size that is not multiple of 32. For example, ssd_mobilenet_v1_1's the expected input size is 300x300 pixels.

  • Reproduce
    run dump-frames example with a video with format 300*300 pixels, then you find the output ppm images are corrupted.
cargo run --example dump-frames ../sample-300x300.mp4 
  • Analysis
    After some check, it looks video function alloc() calls "av_frame_get_buffer" with fixed alignment 32 bytes, so it created frame with linesize[0] = 960, but it should be 900.

I then tried a test to set this alignment to 1, and it worked fine to dump 300*300 pixel images.

av_frame_get_buffer(self.as_mut_ptr(), 32);

  • Suggestion
    So I am asking could you please modify this alloc() function to add an additional argument "align" ? or add a new version of alloc2() function, such as
pub unsafe fn alloc2(&mut self, format: format::Pixel, width: u32, height: u32, align: u32) {
        self.set_format(format);
        self.set_width(width);
        self.set_height(height);

        av_frame_get_buffer(self.as_mut_ptr(), align as c_int);
    }

thanks

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

1 participant