1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
//! A library for hardware video coding using Vulkan Video, with [`wgpu`] integration.
//!
//! # Overview
//!
//! The goal of this library is to provide easy access to hardware video coding. You can use it to decode a video frame into a `Vec<u8>` with pixel data, or into a [`wgpu::Texture`]. Currently, we only support H.264 (aka AVC or MPEG 4 Part 10) decoding, but we plan to support at least H.264 encoding and hopefully other codecs supported by Vulkan Video.
//!
//! An advantage of using this library with wgpu is that decoded video frames never leave the GPU memory. There's no copying the frames to RAM and back to the GPU, so it should be quite fast if you want to use them for rendering.
//!
//! This library was developed as a part of [smelter, a tool for video composition](https://smelter.dev/).
//!
//! # Usage
//!
//! ```ignore
//! fn decode_video(
//! window: &winit::window::Window,
//! mut encoded_video_reader: impl std::io::Read,
//! ) {
//! let instance = vk_video::VulkanInstance::new().unwrap();
//! let surface = instance.wgpu_instance.create_surface(window).unwrap();
//! let device = instance
//! .create_device(
//! wgpu::Features::empty(),
//! wgpu::Limits::default(),
//! Some(&surface),
//! )
//! .unwrap();
//!
//! let mut decoder = device.create_wgpu_textures_decoder().unwrap();
//! let mut buffer = vec![0; 4096];
//!
//! while let Ok(n) = encoded_video_reader.read(&mut buffer) {
//! if n == 0 {
//! return;
//! }
//!
//! let decoded_frames = decoder.decode(&buffer[..n], None).unwrap();
//!
//! for frame in decoded_frames {
//! // Each frame contains a wgpu::Texture you can sample for drawing.
//! // device.wgpu_device() will give you a wgpu::Device and device.wgpu_queue()
//! // a wgpu::Queue. You can use these for interacting with the frames.
//! }
//! }
//! }
//! ```
//!
//! # Compatibility
//!
//! On Linux, the library should work on NVIDIA and AMD GPUs out of the box with recent Mesa drivers. For AMD GPUs with a bit older Mesa drivers, you may need to set the `RADV_PERFTEST=video_decode` environment variable:
//!
//! ```sh
//! RADV_PERFTEST=video_decode cargo run
//! ```
//!
//! It should work on Windows with recent drivers out of the box. Be sure to submit an issue if it doesn't.
//!
//! # Smelter toolkit
//!
//! <a href="https://swmansion.com" style="margin: 20px">
//! <img height="60" alt="Smelter" src="https://logo.swmansion.com/logo?color=white&variant=desktop&width=150&tag=smelter-vk-video">
//! </a>
//! <a href="https://smelter.dev" style="margin: 20px">
//! <picture>
//! <source media="(prefers-color-scheme: dark)" srcset="https:///github.com/software-mansion/smelter/raw/master/assets/smelter-logo-transparent.svg">
//! <source media="(prefers-color-scheme: light)" srcset="https:///github.com/software-mansion/smelter/raw/master/assets/smelter-logo-background.svg">
//! <img height="60" alt="Smelter" src="https:///github.com/software-mansion/smelter/raw/master/assets/smelter-logo-background.svg">
//! </picture>
//! </a>
//!
//! `vk_video` is part of the [Smelter toolkit](https://smelter.dev) created by [Software Mansion](https://swmansion.com).
//!
use Parser;
use ;
pub use ParserError;
pub use ;
/// Represents a chunk of encoded video data.
///
/// If `pts` is [`Option::Some`], it is inferred that the chunk contains bytestream that belongs to
/// one output frame.
/// If `pts` is [`Option::None`], the chunk can contain bytestream from multiple consecutive
/// frames.
/// Represents a single decoded frame.
/// A decoder that outputs frames stored as [`wgpu::Texture`]s
/// A decoder that outputs frames stored as [`Vec<u8>`] with the raw pixel data.