示例#1
0
int file_is_ivf(struct VpxInputContext *input_ctx) {
  char raw_hdr[32];
  int is_ivf = 0;

  if (fread(raw_hdr, 1, 32, input_ctx->file) == 32) {
    if (memcmp(IVF_SIGNATURE, raw_hdr, 4) == 0) {
      is_ivf = 1;

      if (mem_get_le16(raw_hdr + 4) != 0) {
        fprintf(stderr, "Error: Unrecognized IVF version! This file may not"
                " decode properly.");
      }

      input_ctx->fourcc = mem_get_le32(raw_hdr + 8);
      input_ctx->width = mem_get_le16(raw_hdr + 12);
      input_ctx->height = mem_get_le16(raw_hdr + 14);
      input_ctx->framerate.numerator = mem_get_le32(raw_hdr + 16);
      input_ctx->framerate.denominator = mem_get_le32(raw_hdr + 20);
      fix_framerate(&input_ctx->framerate.numerator,
                    &input_ctx->framerate.denominator);
    }
  }

  if (!is_ivf) {
    rewind(input_ctx->file);
    input_ctx->detect.buf_read = 0;
  } else {
    input_ctx->detect.position = 4;
  }
  return is_ivf;
}
示例#2
0
unsigned int file_is_ivf(FILE *infile,
                         unsigned int *fourcc,
                         unsigned int *width,
                         unsigned int *height,
                         unsigned int *fps_den,
                         unsigned int *fps_num) {
    char raw_hdr[32];
    int is_ivf = 0;

    if (fread(raw_hdr, 1, 32, infile) == 32) {
        if (raw_hdr[0] == 'D' && raw_hdr[1] == 'K'
                && raw_hdr[2] == 'I' && raw_hdr[3] == 'F') {
            is_ivf = 1;

            if (mem_get_le16(raw_hdr + 4) != 0)
                fprintf(stderr, "Error: Unrecognized IVF version! This file may not"
                        " decode properly.");

            *fourcc = mem_get_le32(raw_hdr + 8);
            *width = mem_get_le16(raw_hdr + 12);
            *height = mem_get_le16(raw_hdr + 14);
            *fps_num = mem_get_le32(raw_hdr + 16);
            *fps_den = mem_get_le32(raw_hdr + 20);

            if (*fps_num < 1000) {
                if (*fps_num & 1)*fps_den <<= 1;
                else *fps_num >>= 1;
            } else {
                *fps_num = 30;
                *fps_den = 1;
            }
        }
示例#3
0
VpxVideoReader *vpx_video_reader_open(const char *filename) {
    char header[32];
    VpxVideoReader *reader = NULL;
    FILE *const file = fopen(filename, "rb");
    if (!file) return NULL;  // Can't open file

    if (fread(header, 1, 32, file) != 32) return NULL;  // Can't read file header

    if (memcmp(kIVFSignature, header, 4) != 0)
        return NULL;  // Wrong IVF signature

    if (mem_get_le16(header + 4) != 0) return NULL;  // Wrong IVF version

    reader = calloc(1, sizeof(*reader));
    if (!reader) return NULL;  // Can't allocate VpxVideoReader

    reader->file = file;
    reader->info.codec_fourcc = mem_get_le32(header + 8);
    reader->info.frame_width = mem_get_le16(header + 12);
    reader->info.frame_height = mem_get_le16(header + 14);
    reader->info.time_base.numerator = mem_get_le32(header + 16);
    reader->info.time_base.denominator = mem_get_le32(header + 20);

    return reader;
}
unsigned int file_is_ivf(FILE *infile,
                         unsigned int *fourcc,
                         unsigned int *width,
                         unsigned int *height,
                         unsigned int *fps_den,
                         unsigned int *fps_num) {
  char raw_hdr[32];
  int is_ivf = 0;

  if (fread(raw_hdr, 1, 32, infile) == 32) {
    if (raw_hdr[0] == 'D' && raw_hdr[1] == 'K'
        && raw_hdr[2] == 'I' && raw_hdr[3] == 'F') {
      is_ivf = 1;

      if (mem_get_le16(raw_hdr + 4) != 0)
        fprintf(stderr, "Error: Unrecognized IVF version! This file may not"
                " decode properly.");

      *fourcc = mem_get_le32(raw_hdr + 8);
      *width = mem_get_le16(raw_hdr + 12);
      *height = mem_get_le16(raw_hdr + 14);
      *fps_num = mem_get_le32(raw_hdr + 16);
      *fps_den = mem_get_le32(raw_hdr + 20);

      /* Some versions of vpxenc used 1/(2*fps) for the timebase, so
       * we can guess the framerate using only the timebase in this
       * case. Other files would require reading ahead to guess the
       * timebase, like we do for webm.
       */
      if (*fps_num < 1000) {
        /* Correct for the factor of 2 applied to the timebase in the
         * encoder.
         */
        if (*fps_num & 1)*fps_den <<= 1;
        else *fps_num >>= 1;
      } else {
        /* Don't know FPS for sure, and don't have readahead code
         * (yet?), so just default to 30fps.
         */
        *fps_num = 30;
        *fps_den = 1;
      }
    }
示例#5
0
static int
is_ivf (OMX_U8 * p_buf, unsigned int *fourcc, unsigned int *width,
        unsigned int *height, unsigned int *fps_den, unsigned int *fps_num)
{
  int is_ivf = 0;

  if (p_buf[0] == 'D' && p_buf[1] == 'K'
      && p_buf[2] == 'I' && p_buf[3] == 'F')
    {
      is_ivf = 1;

      if (mem_get_le16 (p_buf + 4) != 0)
        fprintf (stderr, "Error: Unrecognized IVF version! This file may not"
                 " decode properly.");

      *fourcc = mem_get_le32 (p_buf + 8);
      *width = mem_get_le16 (p_buf + 12);
      *height = mem_get_le16 (p_buf + 14);
      *fps_num = mem_get_le32 (p_buf + 16);
      *fps_den = mem_get_le32 (p_buf + 20);

      /* Some versions of vpxenc used 1/(2*fps) for the timebase, so
       * we can guess the framerate using only the timebase in this
       * case. Other files would require reading ahead to guess the
       * timebase, like we do for webm.
       */
      if (*fps_num < 1000)
        {
          /* Correct for the factor of 2 applied to the timebase in the
           * encoder.
           */
          if (*fps_num & 1)
            *fps_den <<= 1;
          else
            *fps_num >>= 1;
        }
      else
        {
示例#6
0
文件: ivfenc.c 项目: mrchapp/libvpx
unsigned int file_is_ivf(FILE *infile,
                         unsigned int *fourcc,
                         unsigned int *width,
                         unsigned int *height,
                         char          detect[4])
{
    char raw_hdr[IVF_FILE_HDR_SZ];
    int is_ivf = 0;

    if(memcmp(detect, "DKIF", 4) != 0)
        return 0;

    /* See write_ivf_file_header() for more documentation on the file header
     * layout.
     */
    if (fread(raw_hdr + 4, 1, IVF_FILE_HDR_SZ - 4, infile)
            == IVF_FILE_HDR_SZ - 4)
    {
        {
            is_ivf = 1;

            if (mem_get_le16(raw_hdr + 4) != 0)
                fprintf(stderr, "Error: Unrecognized IVF version! This file may not"
                        " decode properly.");

            *fourcc = mem_get_le32(raw_hdr + 8);
        }
    }

    if (is_ivf)
    {
        *width = mem_get_le16(raw_hdr + 12);
        *height = mem_get_le16(raw_hdr + 14);
    }

    return is_ivf;
}