static int y4m_write_stream_header2(FILE *fd, y4m_stream_info_t *i) { char s[Y4M_LINE_MAX+1]; int n; int err; y4m_ratio_t tmpframerate = y4m_si_get_framerate(i); y4m_ratio_t tmpsamplerate = y4m_si_get_sampleaspect(i); y4m_ratio_reduce(&tmpframerate); y4m_ratio_reduce(&tmpsamplerate); n = tc_snprintf(s, sizeof(s), "%s W%d H%d F%d:%d I%s A%d:%d", Y4M_MAGIC, y4m_si_get_width(i), y4m_si_get_height(i), y4m_si_get_framerate(i).n, y4m_si_get_framerate(i).d, (y4m_si_get_interlace(i) == Y4M_ILACE_NONE) ? "p" : (y4m_si_get_interlace(i) == Y4M_ILACE_TOP_FIRST) ? "t" : (y4m_si_get_interlace(i) == Y4M_ILACE_BOTTOM_FIRST) ? "b" : "?", y4m_si_get_sampleaspect(i).n, y4m_si_get_sampleaspect(i).d); if (n < 0) return Y4M_ERR_HEADER; if ((err = y4m_snprint_xtags(s + n, sizeof(s) - n - 1, y4m_si_xtags(i))) != Y4M_OK) return err; /* zero on error */ return (fwrite(s, strlen(s), 1, fd) ? Y4M_OK : Y4M_ERR_SYSTEM); }
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); }
static int y4m_write_frame_header2(FILE *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) return Y4M_ERR_HEADER; if ((err = y4m_snprint_xtags(s + n, sizeof(s) - n - 1, y4m_fi_xtags(i))) != Y4M_OK) return err; /* zero on error */ return (fwrite(s, strlen(s), 1, fd) ? Y4M_OK : Y4M_ERR_SYSTEM); }
int y4m_write_stream_header_cb(y4m_cb_writer_t * 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_cb(fd, s, strlen(s)) ? Y4M_ERR_SYSTEM : Y4M_OK); }
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); }
int y4m_write_frame_header_cb(y4m_cb_writer_t * 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_cb(fd, s, strlen(s)) ? Y4M_ERR_SYSTEM : Y4M_OK); }