File tree Expand file tree Collapse file tree 1 file changed +13
-8
lines changed Expand file tree Collapse file tree 1 file changed +13
-8
lines changed Original file line number Diff line number Diff line change @@ -35,15 +35,20 @@ For the uninitiated, the std includes lots of convenient ffi related utilities.
3535let ifmt_ctx : AVFormatContext = * ifmt_ctx ;
3636let 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
You can’t perform that action at this time.
0 commit comments