+ /* Read header */
+ for( i=0; i<MAX_YUV4_HEADER; i++ )
+ {
+ header[i] = fgetc(h->fh);
+ if( header[i] == '\n' )
+ {
+ /* Add a space after last option. Makes parsing "444" vs
+ "444alpha" easier. */
+ header[i+1] = 0x20;
+ header[i+2] = 0;
+ break;
+ }
+ }
+ if( i == MAX_YUV4_HEADER || strncmp(header, Y4M_MAGIC, strlen(Y4M_MAGIC)) )
+ return -1;
+
+ /* Scan properties */
+ header_end = &header[i+1]; /* Include space */
+ h->seq_header_len = i+1;
+ for( tokstart = &header[strlen(Y4M_MAGIC)+1]; tokstart < header_end; tokstart++ )
+ {
+ if(*tokstart==0x20) continue;
+ switch(*tokstart++)
+ {
+ case 'W': /* Width. Required. */
+ h->width = p_param->i_width = strtol(tokstart, &tokend, 10);
+ tokstart=tokend;
+ break;
+ case 'H': /* Height. Required. */
+ h->height = p_param->i_height = strtol(tokstart, &tokend, 10);
+ tokstart=tokend;
+ break;
+ case 'C': /* Color space */
+ if( strncmp("420", tokstart, 3) )
+ {
+ fprintf(stderr, "Colorspace unhandled\n");
+ return -1;
+ }
+ tokstart = strchr(tokstart, 0x20);
+ break;
+ case 'I': /* Interlace type */
+ switch(*tokstart++)
+ {
+ case 'p': interlaced = 0; break;
+ case '?':
+ case 't':
+ case 'b':
+ case 'm':
+ default: interlaced = 1;
+ fprintf(stderr, "Warning, this sequence might be interlaced\n");
+ }
+ break;
+ case 'F': /* Frame rate - 0:0 if unknown */
+ if( sscanf(tokstart, "%d:%d", &n, &d) == 2 && n && d )
+ {
+ x264_reduce_fraction( &n, &d );
+ p_param->i_fps_num = n;
+ p_param->i_fps_den = d;
+ }
+ tokstart = strchr(tokstart, 0x20);
+ break;
+ case 'A': /* Pixel aspect - 0:0 if unknown */
+ if( sscanf(tokstart, "%d:%d", &n, &d) == 2 && n && d )
+ {
+ x264_reduce_fraction( &n, &d );
+ p_param->vui.i_sar_width = n;
+ p_param->vui.i_sar_height = d;
+ }
+ tokstart = strchr(tokstart, 0x20);
+ break;
+ case 'X': /* Vendor extensions */
+ if( !strncmp("YSCSS=",tokstart,6) )
+ {
+ /* Older nonstandard pixel format representation */
+ tokstart += 6;
+ if( strncmp("420JPEG",tokstart,7) &&
+ strncmp("420MPEG2",tokstart,8) &&
+ strncmp("420PALDV",tokstart,8) )
+ {
+ fprintf(stderr, "Unsupported extended colorspace\n");
+ return -1;
+ }
+ }
+ tokstart = strchr(tokstart, 0x20);
+ break;
+ }
+ }
+
+ fprintf(stderr, "yuv4mpeg: %ix%i@%i/%ifps, %i:%i\n",
+ h->width, h->height, p_param->i_fps_num, p_param->i_fps_den,
+ p_param->vui.i_sar_width, p_param->vui.i_sar_height);
+
+ *p_handle = (hnd_t)h;
+ return 0;
+}
+
+/* Most common case: frame_header = "FRAME" */
+int get_frame_total_y4m( hnd_t handle )