    assert bytes_read == sz, (bytes_read, sz)
    return buff
  
  
  def rgb24toyuv420(rgb):
    yuv_from_rgb = np.array([[ 0.299     ,  0.587     ,  0.114      ],
                             [-0.14714119, -0.28886916,  0.43601035 ],
                             [ 0.61497538, -0.51496512, -0.10001026 ]])
    img = np.dot(rgb.reshape(-1, 3), yuv_from_rgb.T).reshape(rgb.shape)
  
 
</s> remove   y_len = img.shape[0] * img.shape[1]
  uv_len = y_len // 4
 </s> add  </s> remove   yuv420 = np.empty(y_len + 2 * uv_len, dtype=img.dtype)
 </s> add   return ys, us, vs


def rgb24toyuv420(rgb):
  ys, us, vs = rgb24toyuv(rgb)

  y_len = rgb.shape[0] * rgb.shape[1]
  uv_len = y_len // 4

  yuv420 = np.empty(y_len + 2 * uv_len, dtype=rgb.dtype) </s> remove     if pix_fmt not in ("yuv420p", "rgb24"):
 </s> add     if pix_fmt not in ("nv12", "yuv420p", "rgb24"): </s> remove           img = frs[msg.which()].get(frame_idxs[msg.which()], pix_fmt="yuv420p")[0]
 </s> add           img = frs[msg.which()].get(frame_idxs[msg.which()], pix_fmt="nv12")[0]
def rgb24toyuv(rgb):
    assert bytes_read == sz, (bytes_read, sz)
    return buff
  
  
def rgb24toyuv(rgb):
    yuv_from_rgb = np.array([[ 0.299     ,  0.587     ,  0.114      ],
                             [-0.14714119, -0.28886916,  0.43601035 ],
                             [ 0.61497538, -0.51496512, -0.10001026 ]])
    img = np.dot(rgb.reshape(-1, 3), yuv_from_rgb.T).reshape(rgb.shape)
  
keep keep keep keep replace keep keep keep keep keep
 nv12: encoderd avoids a full frame copy (#24519)

* rgb to nv12

* nv12 works (w memcpy)

* correct now

* no copy

* fix nv12 with fast debayer

* reverts of unused stuff

* ui use nv12

* comment out thumbnails for now

* rebase fix

* dm read nv12

* model read nv12

* fix ffmpeg encoder

* thumbnails from nv12

* replay to nv12

* python framereader support nv12

* remove hardcoded frame/buffer sizes

* fix build

* ffmpeg encoder fix buffers

* small cleanup

* reduce power usage test

* fix cpu usage test

* fix snapshot

* fix loggerd test

* bump cereal

Co-authored-by: Comma Device <device@comma.ai>
Co-authored-by: Joost Wooning <jwooning@gmail.com> 
tools/lib/framereader.py