Video viewer
Source-owned programs from the current OA SDK. Rust and Python examples follow their respective public APIs.
Rust · Python
Example
1use oa::video::{VideoPlayer, VideoPlayerConfig};2use oa::{Engine, Result, Viewer, ViewerConfig, ViewerMode};34fn main() -> Result<()> {5 let args: Vec<String> = std::env::args().collect();6 let positional = |index: usize| args.get(index).filter(|arg| !arg.starts_with("--"));7 let flag_value = |flag: &str| {8 args9 .iter()10 .position(|arg| arg == flag)11 .and_then(|index| args.get(index + 1))12 };1314 // Headless capture mode: decode one frame through the level-1 player and15 // save it — the same native decode + GPU presentation path the Viewer16 // uses, without opening a window. Documentation assets are generated this17 // way (see asset/poster-frame.png).18 if let Some(output) = flag_value("--poster") {19 let frame = flag_value("--frame")20 .and_then(|value| value.parse().ok())21 .unwrap_or(30_u64);22 let default_path = oa::Path::asset_rel("clip/shibuya_720p_30fps_h264_high_8bit_420.mp4");23 let default_str = default_path.to_string_lossy().into_owned();24 let input = positional(1).map(String::as_str).unwrap_or(&default_str);25 return write_poster(input, output, frame);26 }2728 // Default to the H.264 fixture when no path is supplied.29 let default_path = oa::Path::asset_rel("clip/shibuya_720p_30fps_h264_high_8bit_420.mp4");30 let default_str = default_path.to_string_lossy().into_owned();31 let path = positional(1).map(String::as_str).unwrap_or(&default_str);32 let title = positional(2)33 .map(String::as_str)34 .unwrap_or("oa::Viewer · Video");3536 let config = ViewerConfig {37 mode: ViewerMode::Video,38 path: path.to_owned(),39 title: title.to_owned(),40 loop_media: false,41 ..ViewerConfig::default()42 };4344 Viewer::new(config).run_standalone()45}4647/// Decode `frame` of `input` through the native Vulkan Video path, convert48/// the decoded YUV planes to an RGBA texture on-device, and write a PNG.49fn write_poster(input: &str, output: &str, frame: u64) -> Result<()> {50 let engine = Engine::new()?;51 Engine::set_default(engine.clone());52 let mut player = VideoPlayer::new_native(53 &engine,54 std::path::Path::new(input),55 VideoPlayerConfig {56 start_playing: false,57 loop_playback: false,58 ..VideoPlayerConfig::default()59 },60 )?;61 player.seek_frame(frame)?;62 let texture = player.current_frame_texture()?;63 let rgba = texture.read_rgba8()?;64 let width = u32::try_from(texture.width())65 .map_err(|_| oa::Error::out_of_range("video frame width exceeds u32"))?;66 let height = u32::try_from(texture.height())67 .map_err(|_| oa::Error::out_of_range("video frame height exceeds u32"))?;68 oa::image::save_rgba_file(&rgba, width, height, output, 90)?;69 player.close();70 Ok(())71}72
Run Rust tutorials from the OA checkout with cargo run --release --example <name>. Run Python with the environment containing the OA native extension. Consult each program's arguments and capability checks before running it.