warb 0.1.0

Unofficial Rust bindings compatible with Blackmagic Design Blackmagic RAW. Not affiliated with or endorsed by Blackmagic Design.
Documentation
// Decode a .braw clip to a raw RGBA stream on stdout.
//
// Usage:
//   BRAW_RUNTIME_DIR=/path/to/BlackmagicRawAPI \
//   cargo run --release --example to_rgba -- clip.braw > out.rgba
//
// A ready-to-use ffmpeg command is printed on stderr — copy it verbatim.

use std::{
    env,
    io::{self, Write},
    path::PathBuf,
};

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let input = env::args()
        .nth(1)
        .map(PathBuf::from)
        .unwrap_or_else(|| PathBuf::from("/tmp/braw-sample/A001_09091040_C068.braw"));
    // Optional second arg caps the frame count (useful for smoke-testing).
    let limit: Option<u64> = env::args().nth(2).and_then(|s| s.parse().ok());

    let mut decoder = warb::Decoder::new()?;
    decoder.open(&input)?;
    let w = decoder.width();
    let h = decoder.height();
    let n = limit.unwrap_or_else(|| decoder.frame_count());
    let fps = decoder.frame_rate();

    eprintln!("{w}x{h} @ {fps} fps, {n} frames → raw RGBA on stdout");
    eprintln!("Pipe into ffmpeg with:");
    eprintln!(
        "    ffmpeg -f rawvideo -pixel_format rgba -video_size {w}x{h} \
         -framerate {fps} -i - -c:v libx264 -pix_fmt yuv420p out.mp4"
    );

    // Frames are multi-MB, already larger than any reasonable BufWriter
    // buffer, so buffering would be a no-op — write to the raw stdout.
    let mut out = io::stdout().lock();

    for idx in 0..n {
        let image = decoder.decode_frame(idx, warb::ResourceFormat::RgbaU8)?;
        out.write_all(&image)?;
        if idx % 24 == 0 {
            eprint!("\r  frame {}/{}", idx + 1, n);
        }
    }
    eprintln!("\r  frame {n}/{n} done");
    out.flush()?;
    Ok(())
}