From: Kostya Shishkov Date: Tue, 31 Mar 2026 16:04:00 +0000 (+0200) Subject: rawvideoenc: check that the input data is in the same format as on init X-Git-Url: https://git.nihav.org/?a=commitdiff_plain;h=6dfa619750952d424ac062a6ed9a55ed4455e483;p=nihav.git rawvideoenc: check that the input data is in the same format as on init --- diff --git a/nihav-commonfmt/src/codecs/rawvideoenc.rs b/nihav-commonfmt/src/codecs/rawvideoenc.rs index b484a9b..423dbec 100644 --- a/nihav-commonfmt/src/codecs/rawvideoenc.rs +++ b/nihav-commonfmt/src/codecs/rawvideoenc.rs @@ -4,6 +4,7 @@ use nihav_core::io::byteio::*; struct RawEncoder { stream: Option, pkt: Option, + vinfo: NAVideoInfo, } impl RawEncoder { @@ -11,6 +12,7 @@ impl RawEncoder { Self { stream: None, pkt: None, + vinfo: NAVideoInfo::new(0, 0, false, YUV420_FORMAT), } } } @@ -35,7 +37,8 @@ impl NAEncoder for RawEncoder { match encinfo.format { NACodecTypeInfo::None => Err(EncoderError::FormatError), NACodecTypeInfo::Audio(_) => Err(EncoderError::FormatError), - NACodecTypeInfo::Video(_) => { + NACodecTypeInfo::Video(vinfo) => { + self.vinfo = vinfo; let info = NACodecInfo::new("rawvideo", encinfo.format, None); let mut stream = NAStream::new(StreamType::Video, stream_id, info, encinfo.tb_num, encinfo.tb_den, 0); stream.set_num(stream_id as usize); @@ -48,6 +51,12 @@ impl NAEncoder for RawEncoder { fn encode(&mut self, frm: &NAFrame) -> EncoderResult<()> { let buf = frm.get_buffer(); let mut dbuf; + if let Some(vinfo) = buf.get_video_info() { + if vinfo != self.vinfo { + println!("Input format differs from the initial one"); + return Err(EncoderError::FormatError); + } + } match buf { NABufferType::Video(ref vbuf) => { let vinfo = vbuf.get_info();