예제 #1
0
int y4m_write_fields(int fd, y4m_stream_info_t *si, y4m_frame_info_t *fi,
                     unsigned char *upper_field[3], 
                     unsigned char *lower_field[3])
{
  int i, y, err;
  int width = si->width;
  int height = si->height;

  /* Write frame header */
  if ((err = y4m_write_frame_header(fd, fi)) != Y4M_OK) return err;
  /* Write Y', Cb, and Cr planes */
  for (i = 0; i < 3; i++) {
    unsigned char *srctop = upper_field[i];
    unsigned char *srcbot = lower_field[i];
    /* alternately write one line from each */
    for (y = 0; y < height; y += 2) {
      if (y4m_write(fd, srctop, width)) return Y4M_ERR_SYSTEM;
      srctop += width;
      if (y4m_write(fd, srcbot, width)) return Y4M_ERR_SYSTEM;
      srcbot += width;
    }
    /* for chroma, width/height are half as big */
    if (i == 0) {
      width /= 2;
      height /= 2;
    }
  }
  return Y4M_OK;
}
예제 #2
0
int y4m_write_fields(int fd, const y4m_stream_info_t *si,
		     const y4m_frame_info_t *fi,
		     uint8_t * const *upper_field, 
		     uint8_t * const *lower_field)
{
  int p, err;
  int planes = y4m_si_get_plane_count(si);
  int numwbuf=0;
  const int maxwbuf=32*1024;
  uint8_t *wbuf;
  
  /* Write frame header */
  if ((err = y4m_write_frame_header(fd, si, fi)) != Y4M_OK) return err;
  /* Write each plane */
  wbuf=_y4m_alloc(maxwbuf);
  for (p = 0; p < planes; p++) {
    uint8_t *srctop = upper_field[p];
    uint8_t *srcbot = lower_field[p];
    int height = y4m_si_get_plane_height(si, p);
    int width = y4m_si_get_plane_width(si, p);
    int y;
    /* alternately write one line from each field */
    for (y = 0; y < height; y += 2) {
      if( width*2 >= maxwbuf ) {
        if (y4m_write(fd, srctop, width)) goto y4merr;
        if (y4m_write(fd, srcbot, width)) goto y4merr;
      } else {
        if (numwbuf + 2 * width > maxwbuf) {
          if(y4m_write(fd, wbuf, numwbuf)) goto y4merr;
          numwbuf=0;
        }

        memcpy(wbuf+numwbuf,srctop,width); numwbuf += width;
        memcpy(wbuf+numwbuf,srcbot,width); numwbuf += width;
      }
      srctop  += width;
      srcbot  += width;
    }
  }
  if( numwbuf )
    if( y4m_write(fd, wbuf, numwbuf) )
      goto y4merr;
  _y4m_free(wbuf);
  return Y4M_OK;

 y4merr:
  _y4m_free(wbuf);
  return Y4M_ERR_SYSTEM;
}
예제 #3
0
int y4m_write_frame(int fd, y4m_stream_info_t *si, 
		    y4m_frame_info_t *fi, unsigned char *yuv[3])
{
  int err;
  int w = si->width;
  int h = si->height;

  /* Write frame header */
  if ((err = y4m_write_frame_header(fd, fi)) != Y4M_OK) return err;
  /* Write luminance,chrominance scanlines */
  if (y4m_write(fd, yuv[0], w*h) ||
      y4m_write(fd, yuv[1], w*h/4) ||
      y4m_write(fd, yuv[2], w*h/4))
    return Y4M_ERR_SYSTEM;
  return Y4M_OK;
}
예제 #4
0
int y4m_write_frame_header(int fd, y4m_frame_info_t *i)
{
  char s[Y4M_LINE_MAX+1];
  int n;
  int err;
  
  n = snprintf(s, sizeof(s), "%s", Y4M_FRAME_MAGIC);
  if ((n < 0) || (n > Y4M_LINE_MAX)) return Y4M_ERR_HEADER;
  if ((err = y4m_snprint_xtags(s + n, sizeof(s) - n - 1, &(i->x_tags))) 
      != Y4M_OK) 
    return err;
  /* non-zero on error */
  return (y4m_write(fd, s, strlen(s)) ? Y4M_ERR_SYSTEM : Y4M_OK);
}
예제 #5
0
int y4m_write_frame(int fd, const y4m_stream_info_t *si, 
		    const y4m_frame_info_t *fi, uint8_t * const *frame)
{
  int planes = y4m_si_get_plane_count(si);
  int err, p;

  /* Write frame header */
  if ((err = y4m_write_frame_header(fd, si, fi)) != Y4M_OK) return err;
  /* Write each plane */
  for (p = 0; p < planes; p++) {
    int w = y4m_si_get_plane_width(si, p);
    int h = y4m_si_get_plane_height(si, p);
    if (y4m_write(fd, frame[p], w*h)) return Y4M_ERR_SYSTEM;
  }
  return Y4M_OK;
}
예제 #6
0
int y4m_write_stream_header(int fd, const y4m_stream_info_t *i)
{
  char s[Y4M_LINE_MAX+1];
  int n;
  int err;
  y4m_ratio_t rate = i->framerate;
  y4m_ratio_t aspect = i->sampleaspect;
  const char *chroma_keyword = y4m_chroma_keyword(i->chroma);

  if ((i->chroma == Y4M_UNKNOWN) || (chroma_keyword == NULL))
    return Y4M_ERR_HEADER;
  if (_y4mparam_feature_level < 1) {
    if ((i->chroma != Y4M_CHROMA_420JPEG) &&
	(i->chroma != Y4M_CHROMA_420MPEG2) &&
	(i->chroma != Y4M_CHROMA_420PALDV))
      return Y4M_ERR_FEATURE;
    if (i->interlace == Y4M_ILACE_MIXED)
      return Y4M_ERR_FEATURE;
  }
  y4m_ratio_reduce(&rate);
  y4m_ratio_reduce(&aspect);
  n = snprintf(s, sizeof(s), "%s W%d H%d F%d:%d I%s A%d:%d C%s",
	       Y4M_MAGIC,
	       i->width,
	       i->height,
	       rate.n, rate.d,
	       (i->interlace == Y4M_ILACE_NONE) ? "p" :
	       (i->interlace == Y4M_ILACE_TOP_FIRST) ? "t" :
	       (i->interlace == Y4M_ILACE_BOTTOM_FIRST) ? "b" :
	       (i->interlace == Y4M_ILACE_MIXED) ? "m" : "?",
	       aspect.n, aspect.d,
	       chroma_keyword
	       );
  if ((n < 0) || (n > Y4M_LINE_MAX)) return Y4M_ERR_HEADER;
  if ((err = y4m_snprint_xtags(s + n, sizeof(s) - n - 1, &(i->x_tags))) 
      != Y4M_OK) 
    return err;
  /* non-zero on error */
  return (y4m_write(fd, s, strlen(s)) ? Y4M_ERR_SYSTEM : Y4M_OK);
}
예제 #7
0
bool y4m_render::render_one_frame(AVFrame* data, int pix_fmt)
{
    uint8_t *image_y = NULL;
    uint8_t *image_u = NULL;
    uint8_t *image_v = NULL;
    uint8_t* src_yuv[3] = { data->data[0], data->data[1], data->data[2] };
    int i;
    int write_bytes = m_image_width * m_image_height * 3 / 2;

    image_y = (uint8_t*)m_image;
    image_u = image_y + m_image_width * m_image_height;
    image_v = image_u + m_image_width * m_image_height / 4;


    for (i = 0; i < m_image_height; i++)
    {
        memcpy(image_y, src_yuv[0], m_image_width);
        src_yuv[0] += data->linesize[0];
        image_y += m_image_width;

        if (i % 2 == 0)
        {
            memcpy(image_u, src_yuv[1], m_image_width / 2);
            src_yuv[1] += (m_image_width / 2);
            image_u += (m_image_width / 2);

            memcpy(image_v, src_yuv[2], m_image_width / 2);
            src_yuv[2] += (m_image_width / 2);
            image_v += (m_image_width / 2);
        }
    }

    y4m_write(m_yuv_out, m_image, write_bytes);
    fflush(m_yuv_out);

    return true;
}
예제 #8
0
int y4m_write_stream_header(int fd, y4m_stream_info_t *i)
{
  char s[Y4M_LINE_MAX+1];
  int n;
  int err;

  y4m_ratio_reduce(&(i->framerate));
  y4m_ratio_reduce(&(i->sampleaspect));
  n = snprintf(s, sizeof(s), "%s W%d H%d F%d:%d I%s A%d:%d",
	       Y4M_MAGIC,
	       i->width,
	       i->height,
	       i->framerate.n, i->framerate.d,
	       (i->interlace == Y4M_ILACE_NONE) ? "p" :
	       (i->interlace == Y4M_ILACE_TOP_FIRST) ? "t" :
	       (i->interlace == Y4M_ILACE_BOTTOM_FIRST) ? "b" : "?",
	       i->sampleaspect.n, i->sampleaspect.d);
  if ((n < 0) || (n > Y4M_LINE_MAX)) return Y4M_ERR_HEADER;
  if ((err = y4m_snprint_xtags(s + n, sizeof(s) - n - 1, &(i->x_tags))) 
      != Y4M_OK) 
    return err;
  /* non-zero on error */
  return (y4m_write(fd, s, strlen(s)) ? Y4M_ERR_SYSTEM : Y4M_OK);
}
예제 #9
0
int y4m_write_frame_header(int fd,
			   const y4m_stream_info_t *si,
			   const y4m_frame_info_t *fi)
{
  char s[Y4M_LINE_MAX+1];
  int n, err;

  if (si->interlace == Y4M_ILACE_MIXED) {
    if (_y4mparam_feature_level < 1) return Y4M_ERR_FEATURE;
    n = snprintf(s, sizeof(s), "%s I%c%c%c", Y4M_FRAME_MAGIC,
		 (fi->presentation == Y4M_PRESENT_TOP_FIRST)        ? 't' :
		 (fi->presentation == Y4M_PRESENT_TOP_FIRST_RPT)    ? 'T' :
		 (fi->presentation == Y4M_PRESENT_BOTTOM_FIRST)     ? 'b' :
		 (fi->presentation == Y4M_PRESENT_BOTTOM_FIRST_RPT) ? 'B' :
		 (fi->presentation == Y4M_PRESENT_PROG_SINGLE) ? '1' :
		 (fi->presentation == Y4M_PRESENT_PROG_DOUBLE) ? '2' :
		 (fi->presentation == Y4M_PRESENT_PROG_TRIPLE) ? '3' :
		 '?',
		 (fi->temporal == Y4M_SAMPLING_PROGRESSIVE) ? 'p' :
		 (fi->temporal == Y4M_SAMPLING_INTERLACED)  ? 'i' :
		 '?',
		 (fi->spatial == Y4M_SAMPLING_PROGRESSIVE) ? 'p' :
		 (fi->spatial == Y4M_SAMPLING_INTERLACED)  ? 'i' :
		 '?'
		 );
  } else {
    n = snprintf(s, sizeof(s), "%s", Y4M_FRAME_MAGIC);
  }
  
  if ((n < 0) || (n > Y4M_LINE_MAX)) return Y4M_ERR_HEADER;
  if ((err = y4m_snprint_xtags(s + n, sizeof(s) - n - 1, &(fi->x_tags))) 
      != Y4M_OK) 
    return err;
  /* non-zero on error */
  return (y4m_write(fd, s, strlen(s)) ? Y4M_ERR_SYSTEM : Y4M_OK);
}
예제 #10
0
파일: yuv4mpeg.c 프로젝트: c0ntrol/veejay
/* write len bytes from fd into buf */
static ssize_t y4m_write_fd(void * data, const void *buf, size_t len)
  {
  int * f = (int*)data;
  return y4m_write(*f, buf, len);
  }