Propagate errors in Input::packets().

This commit is contained in:
Nebojsa Sabovic 2023-04-15 22:44:12 +02:00 committed by Josh Holmer
parent fa2b8d13ad
commit 05bad6e9e0
5 changed files with 14 additions and 16 deletions

View File

@ -45,7 +45,7 @@ fn main() -> Result<(), ffmpeg::Error> {
Ok(()) Ok(())
}; };
for (stream, packet) in ictx.packets() { for (stream, packet) in ictx.packets().filter_map(Result::ok) {
if stream.index() == video_stream_index { if stream.index() == video_stream_index {
decoder.send_packet(&packet)?; decoder.send_packet(&packet)?;
receive_and_process_decoded_frames(&mut decoder)?; receive_and_process_decoded_frames(&mut decoder)?;

View File

@ -42,7 +42,7 @@ fn main() {
octx.set_metadata(ictx.metadata().to_owned()); octx.set_metadata(ictx.metadata().to_owned());
octx.write_header().unwrap(); octx.write_header().unwrap();
for (stream, mut packet) in ictx.packets() { for (stream, mut packet) in ictx.packets().filter_map(Result::ok) {
let ist_index = stream.index(); let ist_index = stream.index();
let ost_index = stream_mapping[ist_index]; let ost_index = stream_mapping[ist_index];
if ost_index < 0 { if ost_index < 0 {

View File

@ -225,7 +225,7 @@ fn main() {
octx.set_metadata(ictx.metadata().to_owned()); octx.set_metadata(ictx.metadata().to_owned());
octx.write_header().unwrap(); octx.write_header().unwrap();
for (stream, mut packet) in ictx.packets() { for (stream, mut packet) in ictx.packets().filter_map(Result::ok) {
if stream.index() == transcoder.stream { if stream.index() == transcoder.stream {
packet.rescale_ts(stream.time_base(), transcoder.in_time_base); packet.rescale_ts(stream.time_base(), transcoder.in_time_base);
transcoder.send_packet_to_decoder(&packet); transcoder.send_packet_to_decoder(&packet);

View File

@ -238,7 +238,7 @@ fn main() {
ost_time_bases[ost_index] = octx.stream(ost_index as _).unwrap().time_base(); ost_time_bases[ost_index] = octx.stream(ost_index as _).unwrap().time_base();
} }
for (stream, mut packet) in ictx.packets() { for (stream, mut packet) in ictx.packets().filter_map(Result::ok) {
let ist_index = stream.index(); let ist_index = stream.index();
let ost_index = stream_mapping[ist_index]; let ost_index = stream_mapping[ist_index];
if ost_index < 0 { if ost_index < 0 {

View File

@ -159,24 +159,22 @@ impl<'a> PacketIter<'a> {
} }
impl<'a> Iterator for PacketIter<'a> { impl<'a> Iterator for PacketIter<'a> {
type Item = (Stream<'a>, Packet); type Item = Result<(Stream<'a>, Packet), Error>;
fn next(&mut self) -> Option<<Self as Iterator>::Item> { fn next(&mut self) -> Option<<Self as Iterator>::Item> {
let mut packet = Packet::empty(); let mut packet = Packet::empty();
loop { match packet.read(self.context) {
match packet.read(self.context) { Ok(..) => unsafe {
Ok(..) => unsafe { Some(Ok((
return Some(( Stream::wrap(mem::transmute_copy(&self.context), packet.stream()),
Stream::wrap(mem::transmute_copy(&self.context), packet.stream()), packet,
packet, )))
)); },
},
Err(Error::Eof) => return None, Err(Error::Eof) => None,
Err(..) => (), Err(e) => Some(Err(e)),
}
} }
} }
} }