examples/avi-to-ppm: allow more than one stream in the input file

Only decode packets in the best video stream.

See #17.
This commit is contained in:
Zhiming Wang
2020-07-22 20:45:50 +08:00
parent 5d74df996d
commit 3e9c83ec4e

View File

@ -16,6 +16,7 @@ fn main() -> Result<(), ffmpeg::Error> {
.streams()
.best(Type::Video)
.ok_or_else(|| ffmpeg::Error::StreamNotFound)?;
let video_stream_index = input.index();
let mut decoder = input.codec().decoder().video()?;
@ -29,9 +30,12 @@ fn main() -> Result<(), ffmpeg::Error> {
Flags::BILINEAR,
)?;
for (i, (_, p)) in ictx.packets().enumerate() {
for (i, (stream, packet)) in ictx.packets().enumerate() {
if stream.index() != video_stream_index {
continue;
}
let mut frame = Video::empty();
match decoder.decode(&p, &mut frame) {
match decoder.decode(&packet, &mut frame) {
Ok(_) => {
let mut rgb_frame = Video::empty();
scaler.run(&frame, &mut rgb_frame)?;