Skip to content

Commit 1d88b1f

Browse files
committed
update readme working code
1 parent 1922952 commit 1d88b1f

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

README.md

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,20 @@ For the uninitiated, the std includes lots of convenient ffi related utilities.
3535
let ifmt_ctx: AVFormatContext = *ifmt_ctx;
3636
let nb_streams = (*ifmt_ctx).nb_streams as usize;
3737

38-
// Extract video/audio/etc. streams from our mp4 file
39-
let streams: Vec<AVStream> = std::slice::from_raw_parts((*ifmt_ctx).streams, nb_streams)
38+
// Extract video/audio/etc. streams from our mp4 file.
39+
let streams = std::slice::from_raw_parts((*ifmt_ctx).streams, nb_streams)
4040
.iter()
41-
.map(|x| *(*x))
42-
.collect::<Vec<AVStream>>();
43-
44-
// C bindings require zero for loops 😌 - instead turn C dynamic arrays into Rust array refs
45-
for stream_ptr in std::slice::from_raw_parts((*ifmt_ctx).streams, nb_streams) {
46-
// ...
41+
.map(|x| (*x).as_ref().expect("not null"))
42+
.collect::<Vec<&AVStream>>();
43+
44+
// C bindings require zero for loops 😌.
45+
for (index, stream_ptr) in streams.iter().enumerate() {
46+
let codecpar = *stream_ptr.codecpar;
47+
if codecpar.codec_type == AVMEDIA_TYPE_AUDIO {
48+
println!("found audio stream at index {}", index);
49+
} else if codecpar.codec_type == AVMEDIA_TYPE_VIDEO {
50+
println!("found video stream at index {}", index);
51+
}
4752
}
4853
```
4954

0 commit comments

Comments
 (0)