pub struct NativeDecoder { /* private fields */ }decode only.Expand description
A software decoder, fed one coded frame at a time — the same interface as
videotoolbox_decode::VideoToolboxDecoder.
Implementations§
Source§impl NativeDecoder
impl NativeDecoder
Sourcepub fn new(track: &VideoTrack) -> Result<Self, String>
pub fn new(track: &VideoTrack) -> Result<Self, String>
Open a decoder for track’s codec and configuration.
Examples found in repository?
9fn main() {
10 let a: Vec<String> = std::env::args().collect();
11 if a.len() < 3 {
12 eprintln!("usage: video_yuv_dump IN OUT.yuv");
13 std::process::exit(2);
14 }
15 let data = std::fs::read(&a[1]).expect("read");
16 let track = demux_video(&data).expect("demux");
17 let mut dec = NativeDecoder::new(&track).expect("decoder");
18 // Each sample's picture is decoded on push and queued under its pts.
19 let mut frames = std::collections::BTreeMap::new();
20 for s in &track.samples {
21 let bytes = &data[s.offset as usize..s.offset as usize + s.size as usize];
22 dec.push(bytes, s.pts, s.dts, s.duration as i64)
23 .expect("decode");
24 if let Some(f) = dec.take_frame(s.pts) {
25 frames.insert(s.pts, f);
26 }
27 }
28 let mut out = Vec::new();
29 let mut n = 0;
30 for f in frames.values() {
31 for plane in [&f.y, &f.u, &f.v] {
32 if f.bit_depth == 8 {
33 out.extend(plane.iter().map(|&v| v as u8));
34 } else {
35 out.extend(plane.iter().flat_map(|&v| v.to_le_bytes()));
36 }
37 }
38 n += 1;
39 }
40 eprintln!(
41 "{n} frames of {} samples, {}x{}",
42 track.samples.len(),
43 track.width,
44 track.height
45 );
46 std::fs::write(&a[2], out).expect("write");
47}Sourcepub fn from_config(
codec: TrackCodec,
config: &[u8],
width: u32,
height: u32,
) -> Result<Self, String>
pub fn from_config( codec: TrackCodec, config: &[u8], width: u32, height: u32, ) -> Result<Self, String>
Open a decoder from a decoder configuration alone — an avcC or
hvcC payload — for streams that do not come from
demux_video: RTSP, a
container of your own. width and height are what
size reports.
Sourcepub fn push(
&mut self,
sample: &[u8],
pts: i64,
_dts: i64,
_duration: i64,
) -> Result<(), String>
pub fn push( &mut self, sample: &[u8], pts: i64, _dts: i64, _duration: i64, ) -> Result<(), String>
Hand one coded frame to the decoder, in decode order: the bytes
the demuxer pointed at, length-prefixed NAL units as they sit in the
file. The picture it carries is decoded before this returns and
queued under pts.
Examples found in repository?
9fn main() {
10 let a: Vec<String> = std::env::args().collect();
11 if a.len() < 3 {
12 eprintln!("usage: video_yuv_dump IN OUT.yuv");
13 std::process::exit(2);
14 }
15 let data = std::fs::read(&a[1]).expect("read");
16 let track = demux_video(&data).expect("demux");
17 let mut dec = NativeDecoder::new(&track).expect("decoder");
18 // Each sample's picture is decoded on push and queued under its pts.
19 let mut frames = std::collections::BTreeMap::new();
20 for s in &track.samples {
21 let bytes = &data[s.offset as usize..s.offset as usize + s.size as usize];
22 dec.push(bytes, s.pts, s.dts, s.duration as i64)
23 .expect("decode");
24 if let Some(f) = dec.take_frame(s.pts) {
25 frames.insert(s.pts, f);
26 }
27 }
28 let mut out = Vec::new();
29 let mut n = 0;
30 for f in frames.values() {
31 for plane in [&f.y, &f.u, &f.v] {
32 if f.bit_depth == 8 {
33 out.extend(plane.iter().map(|&v| v as u8));
34 } else {
35 out.extend(plane.iter().flat_map(|&v| v.to_le_bytes()));
36 }
37 }
38 n += 1;
39 }
40 eprintln!(
41 "{n} frames of {} samples, {}x{}",
42 track.samples.len(),
43 track.width,
44 track.height
45 );
46 std::fs::write(&a[2], out).expect("write");
47}Sourcepub fn take(&mut self, pts: i64) -> Option<Vec<u8>>
pub fn take(&mut self, pts: i64) -> Option<Vec<u8>>
Take the picture for presentation time pts as tightly packed BGRA,
width * height * 4, if it has been decoded. Frames before pts are
dropped on the way past: they have been shown.
Sourcepub fn take_frame(&mut self, pts: i64) -> Option<DecodedFrame>
pub fn take_frame(&mut self, pts: i64) -> Option<DecodedFrame>
take, but the decoded planes rather than BGRA.
Examples found in repository?
9fn main() {
10 let a: Vec<String> = std::env::args().collect();
11 if a.len() < 3 {
12 eprintln!("usage: video_yuv_dump IN OUT.yuv");
13 std::process::exit(2);
14 }
15 let data = std::fs::read(&a[1]).expect("read");
16 let track = demux_video(&data).expect("demux");
17 let mut dec = NativeDecoder::new(&track).expect("decoder");
18 // Each sample's picture is decoded on push and queued under its pts.
19 let mut frames = std::collections::BTreeMap::new();
20 for s in &track.samples {
21 let bytes = &data[s.offset as usize..s.offset as usize + s.size as usize];
22 dec.push(bytes, s.pts, s.dts, s.duration as i64)
23 .expect("decode");
24 if let Some(f) = dec.take_frame(s.pts) {
25 frames.insert(s.pts, f);
26 }
27 }
28 let mut out = Vec::new();
29 let mut n = 0;
30 for f in frames.values() {
31 for plane in [&f.y, &f.u, &f.v] {
32 if f.bit_depth == 8 {
33 out.extend(plane.iter().map(|&v| v as u8));
34 } else {
35 out.extend(plane.iter().flat_map(|&v| v.to_le_bytes()));
36 }
37 }
38 n += 1;
39 }
40 eprintln!(
41 "{n} frames of {} samples, {}x{}",
42 track.samples.len(),
43 track.width,
44 track.height
45 );
46 std::fs::write(&a[2], out).expect("write");
47}Auto Trait Implementations§
impl !RefUnwindSafe for NativeDecoder
impl !Send for NativeDecoder
impl !Sync for NativeDecoder
impl !UnwindSafe for NativeDecoder
impl Forget for NativeDecoder
impl Freeze for NativeDecoder
impl Unpin for NativeDecoder
impl UnsafeUnpin for NativeDecoder
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more