Recognizes if input is ogg or not.
[xiph/unicode.git] / snatch / snatch2yuv.c
blobc3a4bc3d8c03465542e6eda0bf5a72f51365f7b7
1 /*
3 * snatch2yuv.c
4 *
5 * Copyright (C) 2001 Monty
7 * This file is part of snatch2yuv, a component of the "MJPEG tools"
8 * suite of open source tools for MJPEG and MPEG processing.
9 *
10 * snatch2yuv is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2, or (at your option)
13 * any later version.
15 * snatch2yuv is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with GNU Make; see the file COPYING. If not, write to
22 * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
27 /* Snatch files can consist of multiple resolutions and rates. This
28 scales the given input files to the first rate/size it sees (or
29 user selected format). */
31 #include <stdio.h>
32 #include <unistd.h>
33 #include <stdlib.h>
34 #include <string.h>
36 extern int vidbuf_height;
37 extern int vidbuf_width;
38 extern double vidin_fps;
39 extern double vidout_fps;
40 extern int ratecode;
41 extern int video_timeahead;
43 extern int scale_width;
44 extern int scale_height;
46 extern long long framesin;
47 extern long long framesout;
48 extern long long framesmissing;
49 extern long long framesdiscarded;
50 extern long fpsgraph[61];
52 int snatch_iterator(FILE *in,FILE *out,int process_a,int process_v);
54 extern double begin_time;
55 extern double end_time;
57 static double framerates[]={
58 0., 23.976, 24., 25., 29.970, 30., 50., 59.940, 60. };
60 static void usage(FILE *f){
61 fprintf(f,
62 "snatch2yuv 20020225\n"
63 "snatch2yuv2 20020225\n\n"
64 "snatch2yuv produces YUV4MPEG format files (used by, for example,\n"
65 "mjpeg-tools 1.4). snatch2yuv2 produces YUV4MPEG2 format files (used\n"
66 "by, eg, mjpeg-tools 1.6)\n\n"
68 "USAGE: snatch2yuv [options] < infile { > outfile, | nextutil }\n"
69 " snatch2yuv2 [options] < infile { > outfile, | nextutil }\n\n"
70 "OPTIONS:\n"
71 " -b <N> : skip first <N> seconds of input file\n"
72 " -f <N> : output video in specific MPEG legal\n"
73 " frames-per-second mode: \n"
74 " N = 1, 23.976fps (NTSC 3:2 pulldown)\n"
75 " 2, 24.000fps (film, 1:2 12fps input)\n"
76 " 3, 25.000fps (SECAM/PAL)\n"
77 " 4, 29.970fps (NTSC)\n"
78 " 5, 30.000fps (15fps@1:2, 10fps@1:3)\n"
79 " 6, 50.000fps\n"
80 " 7, 59.940fps\n"
81 " 8, 60.000fps\n"
82 " N=5, 30fps default\n"
83 " -g : graph distribution of frame time deltas [to help\n"
84 " determine correct input fps]\n"
85 " -h : this information to stdout\n"
86 " -i <N> : force input to specific number of frames per \n"
87 " second. Setting this to the 'correct' input fps\n"
88 " is never necessary, but it will smooth the video\n "
89 " motion in a capture that contains jerks/dropouts.\n"
90 " Use the actual fps for <N>, not MPEG mode as above.\n"
91 " -n <N> : output only up to the last frame beginning \n"
92 " before <N> seconds elapsed from start of file\n"
93 " (if preceeding or without -b) or from start of\n"
94 " output (following -b)\n"
95 " -q : operate quietly\n"
96 " -s <WxH> : crop/letterbox into an output framesize of\n"
97 " width W by height H\n\n");
100 const char *optstring = "b:f:ghi:n:qs:";
102 int main(int argc,char *argv[]){
103 int done=0;
104 int noisy=1;
105 int c;
106 int graph=0;
108 int yuvtype=1;
109 if(!strcmp(argv[0],"snatch2yuv2"))yuvtype=2;
111 ratecode=5;
112 vidin_fps=30;
113 vidout_fps=30;
114 video_timeahead=15;
116 while((c=getopt(argc,argv,optstring))!=EOF){
117 switch(c){
118 case 'b':
119 begin_time=atof(optarg);
120 break;
121 case 'f':
122 ratecode=atoi(optarg);
123 if(ratecode<1)ratecode=1;
124 if(ratecode>8)ratecode=8;
125 vidout_fps=framerates[ratecode];
126 break;
127 case 'g':
128 graph=1;
129 break;
130 case 'i':
131 vidin_fps=atof(optarg);
132 if(vidin_fps<1.)vidin_fps=1.;
133 if(vidin_fps>60.)vidin_fps=60.;
134 break;
135 case 'h':
136 usage(stdout);
137 return(0);
138 case 'n':
139 end_time=begin_time+atof(optarg);
140 break;
141 case 'q':
142 noisy=0;
143 break;
144 case 's':
146 char *h=strchr(optarg,'x');
147 if(!h){
148 usage(stderr);
149 exit(1);
151 h++;
152 vidbuf_width=atoi(optarg);
153 vidbuf_height=atoi(h);
155 if(vidbuf_width<2)vidbuf_width=2;
156 if(vidbuf_height<2)vidbuf_height=2;
158 break;
159 default:
160 usage(stderr);
161 exit(1);
166 while(!done){
167 done=snatch_iterator(stdin,stdout,0,yuvtype);
169 if(noisy){
170 long seconds=framesout/vidout_fps;
171 long minutes=seconds/60;
172 long hours;
174 seconds-=minutes*60;
175 hours=minutes/60;
176 minutes-=hours*60;
178 fprintf(stderr,"\rFrames %ld->%ld dropped:%ld missing:%ld %ld:%02ld:%02ld",
179 (long)framesin,(long)framesout,(long)framesdiscarded,(long)framesmissing,
180 hours,minutes,seconds);
184 if(graph){
185 long max=0;
186 int i;
188 if(noisy)fprintf(stderr,"\n");
189 for(i=1;i<=60;i++)
190 if(max<fpsgraph[i])max=fpsgraph[i];
191 if(max)
192 for(i=1;i<=60;i++){
193 int val=(int)(fpsgraph[i]*70/max);
194 if(val)
195 fprintf(stderr,"%3dfps|%*c\n",i,val-1,'*');
196 else
197 fprintf(stderr,"%3dfps|\n",i,val-1,'*');
201 if(noisy)fprintf(stderr,"\n");
202 return(0);