Realm

tu_viewer_video · Native GPU video playback

Current source-owned tutorial. API availability differs by language.

Rust · Python

Start the walkthrough · Jump to complete source

Play an H.264, H.265, VP9, or AV1 file end to end: OA's own demuxer and codec parsers feed Vulkan Video decode sessions, and the decoded frames are presented through the GPU pipeline · no external codec library is linked anywhere in the path.

Decoded poster frame

Frame 30 of the bundled Shibuya fixture, decoded by OA and written to PNG by this tutorial's --poster mode.

What this tutorial covers

  • Level 0 · oa::Viewer in ViewerMode::Video: one config struct, one call, a complete player window.
  • Level 1 · oa::video::VideoPlayer: the session API underneath, used here to capture a decoded frame headlessly and save it.
  • The codec/profile/bit-depth matrix the native path qualifies, and how unsupported profiles fail.

How a packet becomes a pixel

Every stage below is OA code running inside one Runtime:

StageOwnerWhat it does
Container demuxoa::video::VideoDemuxerMP4/MKV/TS packetization; codec + stream metadata
Bitstream parseoa::video::{h264, h265, av1, vp9}SPS/PPS/slice/frame-header parsing against the specs
Decode sessionoa::runtime device videoVulkan Video session, std parameter objects, DPB/reference management
Presentationcvt_yuv420_to_rgba8 Slang kernelOn-device YUV→RGBA conversion honoring matrix/range metadata
Displayoa::Viewer video modeTimeline, scrub bar, and the GPU blit to the swapchain

Decoded planes stay on the device the whole way. A decoded frame is a lease-protected DPB slot · presentation converts it into a Texture and releases the lease so the decoder can recycle the slot.

Qualified codec matrix (Intel ADL GT2 / Mesa ANV)

The checked-in fixture set in sdk/asset/video/clip/ covers every admitted decode profile · one shibuya 720p30 source re-encoded per profile:

CodecDecodeEncode
H.264Baseline, Main, High · 8-bit 4:2:0High · 8-bit
H.265Main, Main10 (10-bit)Main · 8-bit, Main10 + REx · 10-bit
VP9Profile 0 · 8-bit, Profile 2 · 10-bit·
AV1Main · 8-bit and 10-bit 4:2:0·

Profiles the device does not expose (H.264 High10, 12-bit variants) are rejected by an exact capability query with MissingCapability · the API fails closed rather than pretending to decode.

Walkthrough

Level 0: the whole player

ViewerConfig selects ViewerMode::Video, a media path, and a window title. run_standalone owns the window, the timeline, input handling, and the render loop:

1let config = ViewerConfig {
2 mode: ViewerMode::Video,
3 path: path.to_owned(),
4 title: title.to_owned(),
5 loop_media: false,
6 ..ViewerConfig::default()
7};
8
9Viewer::new(config).run_standalone()
10

That is the entire application · the viewer composes the demuxer, player, presentation, and blit internally.

Level 1: capturing a frame

--poster uses the session API directly. VideoPlayer::new_native opens the container and the native decoder, keeping decoded planes on the GPU:

1let mut player = VideoPlayer::new_native(
2 &runtime,
3 std::path::Path::new(input),
4 VideoPlayerConfig {
5 start_playing: false,
6 loop_playback: false,
7 ..VideoPlayerConfig::default()
8 },
9)?;
10player.seek_frame(frame)?;
11let texture = player.current_frame_texture()?;
12

seek_frame positions the decode cursor; current_frame_texture converts the current native frame into an RGBA Texture and · the important part · re-seats the presented frame on the texture, so the decoder slot underneath is freed for reuse.

From there the frame is ordinary image data:

1let rgba = texture.read_rgba8()?;
2oa::image::save_rgba_file(&rgba, width, height, output, 90)?;
3

asset/poster-frame.png in this directory was produced by exactly this path · OA decode, OA presentation, OA PNG encode.

Run

# default fixture (H.264 High)
cargo run -p sdk --release --example tu_viewer_video
# any supported clip
cargo run -p sdk --release --example tu_viewer_video -- <file.mp4>
# headless poster capture of frame 30
cargo run -p sdk --release --example tu_viewer_video -- \
sdk/asset/video/clip/shibuya_720p_30fps_h264_high_8bit_420.mp4 \
--poster asset/poster-frame.png --frame 30

Controls: Space play/pause, arrow keys step/seek, +/- zoom, 0 fit, Q/Esc quit.

Assets

  • asset/poster-frame.png · tutorial-local, generated by --poster (regenerate with the command above).
  • sdk/asset/video/clip/shibuya_720p_30fps_*.mp4 · shared fixture set, kept at the repo asset root because many tests, benchmarks, and tutorials consume the same clips.

Where to go next

  • tu_viewer_image · the same level-0 Viewer for still images.
  • tu_viewer_image_headless · headless render/sink without a window.
  • tu_ml_audio_commands · media + ML end to end.

Example

1// ═══════════════════════════════════════════════════════════════════════════
2// OA Tutorial: oa::Viewer · Video playback (H.264 / H.265 / VP9 / AV1)
3// Level-0 API · oa::Viewer, ViewerMode::Video
4// ═══════════════════════════════════════════════════════════════════════════
5//
6// Opens a video file in the Viewer's video mode, which renders frames using
7// the GPU blit path with pan/zoom navigation and a timeline scrub bar.
8//
9// Controls:
10// Space · play/pause Left/Right arrow · step frame Q/Esc · quit
11// +/- · zoom 0/F · fit to window
12//
13// usage:
14// cargo run --example tu_viewer_video -- [file.mp4]
15// cargo run --example tu_viewer_video -- [file.mp4] <title>
16// cargo run --example tu_viewer_video -- <file.mp4> --poster out.png [--frame N]
17//
18// To exercise specific codec fixtures (SDK asset paths):
19// cargo run --example tu_viewer_video -- asset/video/clip/shibuya_720p_30fps_h264_high_8bit_420.mp4
20// cargo run --example tu_viewer_video -- asset/video/clip/shibuya_720p_30fps_h265_main_8bit_420.mp4
21// cargo run --example tu_viewer_video -- asset/video/clip/shibuya_720p_30fps_vp9_profile0_8bit_420.mp4
22// cargo run --example tu_viewer_video -- asset/video/clip/shibuya_720p_30fps_av1_main_8bit_420.mp4
23//
24// Donor: sdk/cpp/tutorials/vision/tuViewerVideo{H264,H265,VP9,AV1}.cpp
25// ═══════════════════════════════════════════════════════════════════════════
26
27use oa::video::{VideoPlayer, VideoPlayerConfig};
28use oa::{Result, Runtime, Viewer, ViewerConfig, ViewerMode};
29
30fn main() -> Result<()> {
31 let args: Vec<String> = std::env::args().collect();
32 let positional = |index: usize| args.get(index).filter(|arg| !arg.starts_with("--"));
33 let flag_value = |flag: &str| {
34 args
35 .iter()
36 .position(|arg| arg == flag)
37 .and_then(|index| args.get(index + 1))
38 };
39
40 // Headless capture mode: decode one frame through the level-1 player and
41 // save it · the same native decode + GPU presentation path the Viewer
42 // uses, without opening a window. Documentation assets are generated this
43 // way (see asset/poster-frame.png).
44 if let Some(output) = flag_value("--poster") {
45 let frame = flag_value("--frame")
46 .and_then(|value| value.parse().ok())
47 .unwrap_or(30_u64);
48 let default_path = oa::Path::asset_rel("clip/shibuya_720p_30fps_h264_high_8bit_420.mp4");
49 let default_str = default_path.to_string_lossy().into_owned();
50 let input = positional(1).map(String::as_str).unwrap_or(&default_str);
51 return write_poster(input, output, frame);
52 }
53
54 // Default to the H.264 fixture when no path is supplied.
55 let default_path = oa::Path::asset_rel("clip/shibuya_720p_30fps_h264_high_8bit_420.mp4");
56 let default_str = default_path.to_string_lossy().into_owned();
57 let path = positional(1).map(String::as_str).unwrap_or(&default_str);
58 let title = positional(2)
59 .map(String::as_str)
60 .unwrap_or("oa::Viewer · Video");
61
62 let config = ViewerConfig {
63 mode: ViewerMode::Video,
64 path: path.to_owned(),
65 title: title.to_owned(),
66 loop_media: false,
67 ..ViewerConfig::default()
68 };
69
70 Viewer::new(config).run_standalone()
71}
72
73/// Decode `frame` of `input` through the native Vulkan Video path, convert
74/// the decoded YUV planes to an RGBA texture on-device, and write a PNG.
75fn write_poster(input: &str, output: &str, frame: u64) -> Result<()> {
76 let runtime = Runtime::current()?;
77 let mut player = VideoPlayer::new_native(
78 &runtime,
79 std::path::Path::new(input),
80 VideoPlayerConfig {
81 start_playing: false,
82 loop_playback: false,
83 ..VideoPlayerConfig::default()
84 },
85 )?;
86 player.seek_frame(frame)?;
87 let texture = player.current_frame_texture()?;
88 let rgba = texture.read_rgba8()?;
89 let width = u32::try_from(texture.width())
90 .map_err(|_| oa::Error::out_of_range("video frame width exceeds u32"))?;
91 let height = u32::try_from(texture.height())
92 .map_err(|_| oa::Error::out_of_range("video frame height exceeds u32"))?;
93 oa::image::save_rgba_file(&rgba, width, height, output, 90)?;
94 player.close();
95 Ok(())
96}
97

Run Rust tutorials from the OA SDK 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.