diff --git a/src/demux/flv.rs b/src/demux/flv.rs index fbba638..f9c2785 100644 --- a/src/demux/flv.rs +++ b/src/demux/flv.rs @@ -48,7 +48,11 @@ impl FLVReader { fn read_packet(&mut self) -> Result<(FLVTagType, Vec), Box> { let mut tag_head = [0u8; 11]; - self.stdin.read_exact(&mut tag_head)?; + match self.stdin.read_exact(&mut tag_head) { + Ok(_) => (), + Err(err) if err.kind() == io::ErrorKind::UnexpectedEof => return Err(Box::new(util::DemuxerError::EOF)), + Err(err) => return Err(Box::new(err)) + }; let tag_type = FLVTagType::try_from(tag_head[0])?; let tag_data_len = (u32::from_be_bytes(tag_head[..4].try_into()?) & 0xffffff) as usize; let mut packet_data = vec![0u8; tag_data_len]; diff --git a/src/util/mod.rs b/src/util/mod.rs index 78550b1..cb92b51 100644 --- a/src/util/mod.rs +++ b/src/util/mod.rs @@ -98,6 +98,7 @@ pub enum DemuxerError { FLVUnexpectedTag, MetadataValNotSet, CodecNotImplemented, + EOF, } impl Error for DemuxerError {} @@ -115,6 +116,7 @@ impl fmt::Debug for DemuxerError { DemuxerError::CodecNotImplemented => write!(f, "Input file has unrecognized codec"), DemuxerError::MetadataValNotSet => write!(f, "One or more metadata values failed to init"), DemuxerError::FLVUnexpectedTag => write!(f, "Expected data tag, found metadata"), + DemuxerError::EOF => write!(f, "Failed to read tag header, expected EOF"), _ => write!(f, "Error not described yet") } }