pub fn process_frame(
  ctx: &mut Context, output_file: &mut dyn Write,
  y4m_dec: &mut y4m::Decoder<'_, Box<dyn Read>>,
  mut y4m_enc: Option<&mut y4m::Encoder<'_, Box<dyn Write>>>
) -> bool {
  unsafe {
    av1_rtcd();
    aom_dsp_rtcd();
  }
  let width = y4m_dec.get_width();
  let height = y4m_dec.get_height();
  let y4m_bits = y4m_dec.get_bit_depth();
  let y4m_bytes = y4m_dec.get_bytes_per_sample();
  let bit_depth = y4m_dec.get_colorspace().get_bit_depth();

  let read_frame =
  match y4m_dec.read_frame() {
    Ok(y4m_frame) => {
      let y4m_y = y4m_frame.get_y_plane();
      let y4m_u = y4m_frame.get_u_plane();
      let y4m_v = y4m_frame.get_v_plane();
      let mut input = ctx.new_frame();
      {
        let input = Arc::get_mut(&mut input).unwrap();
        input.planes[0].copy_from_raw_u8(&y4m_y, width * y4m_bytes, y4m_bytes);
        input.planes[1].copy_from_raw_u8(
          &y4m_u,
          width * y4m_bytes / 2,
          y4m_bytes
        );
        input.planes[2].copy_from_raw_u8(
          &y4m_v,
          width * y4m_bytes / 2,
          y4m_bytes
        );
      }

      match y4m_bits {
        8 | 10 | 12 => {}
        _ => panic!("unknown input bit depth!")
      }

      let _ = ctx.send_frame(input);
      true
    }
    _ => {
      ctx.flush();
      false
    }
  };

  let mut has_data = true;
  while has_data {
    let pkt_wrapped = ctx.receive_packet();
    match pkt_wrapped {
    Ok(pkt) => {
      eprintln!("{}", pkt);
      write_ivf_frame(output_file, pkt.number as u64, pkt.data.as_ref());
      if let Some(y4m_enc_uw) = y4m_enc.as_mut() {
      if let Some(rec) = pkt.rec {
        let pitch_y = if bit_depth > 8 { width * 2 } else { width };
        let pitch_uv = pitch_y / 2;

        let (mut rec_y, mut rec_u, mut rec_v) = (
          vec![128u8; pitch_y * height],
          vec![128u8; pitch_uv * (height / 2)],
          vec![128u8; pitch_uv * (height / 2)]
        );

        let (stride_y, stride_u, stride_v) = (
          rec.planes[0].cfg.stride,
          rec.planes[1].cfg.stride,
          rec.planes[2].cfg.stride
        );

        for (line, line_out) in rec.planes[0]
          .data_origin()
          .chunks(stride_y)
          .zip(rec_y.chunks_mut(pitch_y))
        {
          if bit_depth > 8 {
            unsafe {
              line_out.copy_from_slice(slice::from_raw_parts::<u8>(
                line.as_ptr() as (*const u8),
                pitch_y
              ));
            }
          } else {
            line_out.copy_from_slice(
              &line.iter().map(|&v| v as u8).collect::<Vec<u8>>()[..pitch_y]
            );
          }
        }
        for (line, line_out) in rec.planes[1]
          .data_origin()
          .chunks(stride_u)
          .zip(rec_u.chunks_mut(pitch_uv))
        {
          if bit_depth > 8 {
            unsafe {
              line_out.copy_from_slice(slice::from_raw_parts::<u8>(
                line.as_ptr() as (*const u8),
                pitch_uv
              ));
            }
          } else {
            line_out.copy_from_slice(
              &line.iter().map(|&v| v as u8).collect::<Vec<u8>>()[..pitch_uv]
            );
          }
        }
        for (line, line_out) in rec.planes[2]
          .data_origin()
          .chunks(stride_v)
          .zip(rec_v.chunks_mut(pitch_uv))
        {
          if bit_depth > 8 {
            unsafe {
              line_out.copy_from_slice(slice::from_raw_parts::<u8>(
                line.as_ptr() as (*const u8),
                pitch_uv
              ));
            }
          } else {
            line_out.copy_from_slice(
              &line.iter().map(|&v| v as u8).collect::<Vec<u8>>()[..pitch_uv]
            );
          }
        }

        let rec_frame = y4m::Frame::new([&rec_y, &rec_u, &rec_v], None);
        y4m_enc_uw.write_frame(&rec_frame).unwrap();
      }
      }
    },
    _ => { has_data = false; }
    }
  }
  read_frame
}
/// Encode and write a frame.
/// returns wheter done with sequence
Encode and write a frame.
returns wheter done with sequence
Encode and write a frame . returns wheter done with sequence
pub fn process_frame(
  ctx: &mut Context, output_file: &mut dyn Write,
  y4m_dec: &mut y4m::Decoder<'_, Box<dyn Read>>,
  mut y4m_enc: Option<&mut y4m::Encoder<'_, Box<dyn Write>>>
) -> bool {
  unsafe {
    av1_rtcd();
    aom_dsp_rtcd();
  }
  let width = y4m_dec.get_width();
  let height = y4m_dec.get_height();
  let y4m_bits = y4m_dec.get_bit_depth();
  let y4m_bytes = y4m_dec.get_bytes_per_sample();
  let bit_depth = y4m_dec.get_colorspace().get_bit_depth();
  let read_frame =
  match y4m_dec.read_frame() {
    Ok(y4m_frame) => {
      let y4m_y = y4m_frame.get_y_plane();
      let y4m_u = y4m_frame.get_u_plane();
      let y4m_v = y4m_frame.get_v_plane();
      let mut input = ctx.new_frame();
      {
        let input = Arc::get_mut(&mut input).unwrap();
        input.planes[0].copy_from_raw_u8(&y4m_y, width * y4m_bytes, y4m_bytes);
        input.planes[1].copy_from_raw_u8(
          &y4m_u,
          width * y4m_bytes / 2,
          y4m_bytes
        );
        input.planes[2].copy_from_raw_u8(
          &y4m_v,
          width * y4m_bytes / 2,
          y4m_bytes
        );
      }
      match y4m_bits {
        8 | 10 | 12 => {}
        _ => panic!("unknown input bit depth!")
      }
      let _ = ctx.send_frame(input);
      true
    }
    _ => {
      ctx.flush();
      false
    }
  };
  let mut has_data = true;
  while has_data {
    let pkt_wrapped = ctx.receive_packet();
    match pkt_wrapped {
    Ok(pkt) => {
      eprintln!("{}", pkt);
      write_ivf_frame(output_file, pkt.number as u64, pkt.data.as_ref());
      if let Some(y4m_enc_uw) = y4m_enc.as_mut() {
      if let Some(rec) = pkt.rec {
        let pitch_y = if bit_depth > 8 { width * 2 } else { width };
        let pitch_uv = pitch_y / 2;
        let (mut rec_y, mut rec_u, mut rec_v) = (
          vec![128u8; pitch_y * height],
          vec![128u8; pitch_uv * (height / 2)],
          vec![128u8; pitch_uv * (height / 2)]
        );
        let (stride_y, stride_u, stride_v) = (
          rec.planes[0].cfg.stride,
          rec.planes[1].cfg.stride,
          rec.planes[2].cfg.stride
        );
        for (line, line_out) in rec.planes[0]
          .data_origin()
          .chunks(stride_y)
          .zip(rec_y.chunks_mut(pitch_y))
        {
          if bit_depth > 8 {
            unsafe {
              line_out.copy_from_slice(slice::from_raw_parts::<u8>(
                line.as_ptr() as (*const u8),
                pitch_y
              ));
            }
          } else {
            line_out.copy_from_slice(
              &line.iter().map(|&v| v as u8).collect::<Vec<u8>>()[..pitch_y]
            );
          }
        }
        for (line, line_out) in rec.planes[1]
          .data_origin()
          .chunks(stride_u)
          .zip(rec_u.chunks_mut(pitch_uv))
        {
          if bit_depth > 8 {
            unsafe {
              line_out.copy_from_slice(slice::from_raw_parts::<u8>(
                line.as_ptr() as (*const u8),
                pitch_uv
              ));
            }
          } else {
            line_out.copy_from_slice(
              &line.iter().map(|&v| v as u8).collect::<Vec<u8>>()[..pitch_uv]
            );
          }
        }
        for (line, line_out) in rec.planes[2]
          .data_origin()
          .chunks(stride_v)
          .zip(rec_v.chunks_mut(pitch_uv))
        {
          if bit_depth > 8 {
            unsafe {
              line_out.copy_from_slice(slice::from_raw_parts::<u8>(
                line.as_ptr() as (*const u8),
                pitch_uv
              ));
            }
          } else {
            line_out.copy_from_slice(
              &line.iter().map(|&v| v as u8).collect::<Vec<u8>>()[..pitch_uv]
            );
          }
        }
        let rec_frame = y4m::Frame::new([&rec_y, &rec_u, &rec_v], None);
        y4m_enc_uw.write_frame(&rec_frame).unwrap();
      }
      }
    },
    _ => { has_data = false; }
    }
  }
  read_frame
}
pub fn process_frame ( ctx : & mut Context , output_file : & mut dyn Write , y4m_dec : & mut y4m :: Decoder < ' _ , Box < dyn Read > > , mut y4m_enc : Option < & mut y4m :: Encoder < ' _ , Box < dyn Write > > > ) -> bool { unsafe { av1_rtcd ( ) ; aom_dsp_rtcd ( ) ; } let width = y4m_dec . get_width ( ) ; let height = y4m_dec . get_height ( ) ; let y4m_bits = y4m_dec . get_bit_depth ( ) ; let y4m_bytes = y4m_dec . get_bytes_per_sample ( ) ; let bit_depth = y4m_dec . get_colorspace ( ) . get_bit_depth ( ) ; let read_frame = match y4m_dec . read_frame ( ) { Ok ( y4m_frame ) => { let y4m_y = y4m_frame . get_y_plane ( ) ; let y4m_u = y4m_frame . get_u_plane ( ) ; let y4m_v = y4m_frame . get_v_plane ( ) ; let mut input = ctx . new_frame ( ) ; { let input = Arc :: get_mut ( & mut input ) . unwrap ( ) ; input . planes [ 0 ] . copy_from_raw_u8 ( & y4m_y , width * y4m_bytes , y4m_bytes ) ; input . planes [ 1 ] . copy_from_raw_u8 ( & y4m_u , width * y4m_bytes / 2 , y4m_bytes ) ; input . planes [ 2 ] . copy_from_raw_u8 ( & y4m_v , width * y4m_bytes / 2 , y4m_bytes ) ; } match y4m_bits { 8 | 10 | 12 => { } _ => panic ! ( " " ) } let _ = ctx . send_frame ( input ) ; true } _ => { ctx . flush ( ) ; false } } ; let mut has_data = true ; while has_data { let pkt_wrapped = ctx . receive_packet ( ) ; match pkt_wrapped { Ok ( pkt ) => { eprintln ! ( " " pkt ) ; write_ivf_frame ( output_file , pkt . number as u64 , pkt . data . as_ref ( ) ) ; if let Some ( y4m_enc_uw ) = y4m_enc . as_mut ( ) { if let Some ( rec ) = pkt . rec { let pitch_y = if bit_depth > 8 { width * 2 } else { width } ; let pitch_uv = pitch_y / 2 ; let ( mut rec_y , mut rec_u , mut rec_v ) = ( vec ! [ 128u8 pitch_y height ] , vec ! [ 128u8 pitch_uv ( height 2 ) ] , vec ! [ 128u8 pitch_uv ( height 2 ) ] ) ; let ( stride_y , stride_u , stride_v ) = ( rec . planes [ 0 ] . cfg . stride , rec . planes [ 1 ] . cfg . stride , rec . planes [ 2 ] . cfg . stride ) ; for ( line , line_out ) in rec . planes [ 0 ] . data_origin ( ) . chunks ( stride_y ) . zip ( rec_y . chunks_mut ( pitch_y ) ) { if bit_depth > 8 { unsafe { line_out . copy_from_slice ( slice :: from_raw_parts :: < u8 > ( line . as_ptr ( ) as ( * const u8 ) , pitch_y ) ) ; } } else { line_out . copy_from_slice ( & line . iter ( ) . map ( | & v | v as u8 ) . collect :: < Vec < u8 > > ( ) [ .. pitch_y ] ) ; } } for ( line , line_out ) in rec . planes [ 1 ] . data_origin ( ) . chunks ( stride_u ) . zip ( rec_u . chunks_mut ( pitch_uv ) ) { if bit_depth > 8 { unsafe { line_out . copy_from_slice ( slice :: from_raw_parts :: < u8 > ( line . as_ptr ( ) as ( * const u8 ) , pitch_uv ) ) ; } } else { line_out . copy_from_slice ( & line . iter ( ) . map ( | & v | v as u8 ) . collect :: < Vec < u8 > > ( ) [ .. pitch_uv ] ) ; } } for ( line , line_out ) in rec . planes [ 2 ] . data_origin ( ) . chunks ( stride_v ) . zip ( rec_v . chunks_mut ( pitch_uv ) ) { if bit_depth > 8 { unsafe { line_out . copy_from_slice ( slice :: from_raw_parts :: < u8 > ( line . as_ptr ( ) as ( * const u8 ) , pitch_uv ) ) ; } } else { line_out . copy_from_slice ( & line . iter ( ) . map ( | & v | v as u8 ) . collect :: < Vec < u8 > > ( ) [ .. pitch_uv ] ) ; } } let rec_frame = y4m :: Frame :: new ( [ & rec_y , & rec_u , & rec_v ] , None ) ; y4m_enc_uw . write_frame ( & rec_frame ) . unwrap ( ) ; } } } , _ => { has_data = false ; } } } read_frame }
Encode and write a frame.
Encode and write a frame .
ctx
&mut Context
output_file
&mut dyn Write
y4m_dec
&mut y4m::Decoder<'_, Box<dyn Read>>
y4m_enc
Option<&mut y4m::Encoder<'_, Box<dyn Write>>>