ffmpeg-rs
ffmpeg-rs copied to clipboard
dump_frames example is assuming stride has no line padding.
The dump frames example is assuming that frame.width() * frame.height() == frame.stride(0) which is not necessarily true. A fixed version of the save_file function looks like this.
fn save_file(frame: &Video, index: usize) -> std::result::Result<(), std::io::Error> {
let mut file = File::create(format!("frame{}.ppm", index))?;
file.write_all(format!("P6\n{} {}\n255\n", frame.width(), frame.height()).as_bytes())?;
let byt = frame.data(0);
for y in 0..frame.height() {
let start = y as usize * (frame.stride(0) as usize);
let end = start + frame.width() as usize * 3;
file.write_all(&byt[start..end])?;
}
Ok(())
}
I am sorry that I cannot open a pull request right now, I am on limited internet. But this method works for my data.
Thanks @SirVer! I'll see if I can have a closer look and push this soon.