]> git.nihav.org Git - nihav.git/blobdiff - nihav-commonfmt/src/codecs/zmbvenc.rs
zmbvenc: handle I-frames that turned out to be skip frames
[nihav.git] / nihav-commonfmt / src / codecs / zmbvenc.rs
index ee40f494f3c171dad7e5c41014502b2d43f44daf..d7be6054ea184acdf2b4f02954c1923e22284150 100644 (file)
@@ -139,13 +139,14 @@ impl ZMBVEncoder {
         }
     }
     fn encode_intra(&mut self, bw: &mut ByteWriter, buf: NABufferType) -> EncoderResult<()> {
-        let bpp = buf_type_to_bpp(&buf);
+        let mut bpp = buf_type_to_bpp(&buf);
 
         if let NABufferType::None = buf {
             if self.bpp == 0 {
                 return Err(EncoderError::FormatError);
             }
             self.frm1.copy_from_slice(&self.frm2);
+            bpp = self.bpp;
         } else {
             if bpp == 0 {
                 return Err(EncoderError::FormatError);
@@ -374,9 +375,10 @@ impl NAEncoder for ZMBVEncoder {
     fn negotiate_format(&self, encinfo: &EncodeParameters) -> EncoderResult<EncodeParameters> {
         match encinfo.format {
             NACodecTypeInfo::None => {
-                let mut ofmt = EncodeParameters::default();
-                ofmt.format = NACodecTypeInfo::Video(NAVideoInfo::new(0, 0, true, YUV420_FORMAT));
-                Ok(ofmt)
+                Ok(EncodeParameters {
+                    format: NACodecTypeInfo::Video(NAVideoInfo::new(0, 0, true, YUV420_FORMAT)),
+                    ..Default::default()
+                })
             },
             NACodecTypeInfo::Audio(_) => Err(EncoderError::FormatError),
             NACodecTypeInfo::Video(vinfo) => {
@@ -397,6 +399,7 @@ impl NAEncoder for ZMBVEncoder {
             }
         }
     }
+    fn get_capabilities(&self) -> u64 { ENC_CAPS_SKIPFRAME }
     fn init(&mut self, stream_id: u32, encinfo: EncodeParameters) -> EncoderResult<NAStreamRef> {
         match encinfo.format {
             NACodecTypeInfo::None => Err(EncoderError::FormatError),
@@ -549,6 +552,7 @@ mod test {
     use nihav_codec_support::test::enc_video::*;
     use super::{RGB555_FORMAT, RGB24_0_FORMAT};
 
+    // samples are from https://samples.mplayerhq.hu/V-codecs/ZMBV/
     #[test]
     fn test_zmbv_encoder_8bit() {
         let mut dmx_reg = RegisteredDemuxers::new();
@@ -593,7 +597,7 @@ mod test {
             ];
         //test_encoding_to_file(&dec_config, &enc_config, enc_params, enc_options);
         test_encoding_md5(&dec_config, &enc_config, enc_params, enc_options,
-                          &[0x4bcdb816, 0x57d5d1b6, 0xc9412438, 0x9416c407]);
+                          &[0x18bd3754, 0x97007f81, 0xff2bcd07, 0x739c48dc]);
     }
 
     #[test]
@@ -640,7 +644,7 @@ mod test {
             ];
         //test_encoding_to_file(&dec_config, &enc_config, enc_params, enc_options);
         test_encoding_md5(&dec_config, &enc_config, enc_params, enc_options,
-                          &[0x1cff4116, 0x5926d91b, 0x60aac53f, 0x8a22bc7b]);
+                          &[0x00311257, 0xd26a0e9e, 0xfd4b003f, 0x7c962d7b]);
     }
 
     #[test]
@@ -687,7 +691,7 @@ mod test {
             ];
         //test_encoding_to_file(&dec_config, &enc_config, enc_params, enc_options);
         test_encoding_md5(&dec_config, &enc_config, enc_params, enc_options,
-                          &[0xb48aa633, 0x673539fe, 0xa312d45a, 0x76eee134]);
+                          &[0x4eea104f, 0x2ebe544b, 0x54deb0f9, 0xe5ca88f4]);
     }
 
     #[test]
@@ -734,6 +738,6 @@ mod test {
             ];
         //test_encoding_to_file(&dec_config, &enc_config, enc_params, enc_options);
         test_encoding_md5(&dec_config, &enc_config, enc_params, enc_options,
-                          &[0x0836152c, 0xfcd7e1fc, 0xf1e2f619, 0x874d3dbc]);
+                          &[0xffceb4bd, 0xb1beccd9, 0x4983e7f6, 0xf46e33ba]);
     }
 }