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.
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)
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). */
36 extern int vidbuf_height
;
37 extern int vidbuf_width
;
38 extern double vidin_fps
;
39 extern double vidout_fps
;
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
){
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"
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"
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
[]){
109 if(!strcmp(argv
[0],"snatch2yuv2"))yuvtype
=2;
116 while((c
=getopt(argc
,argv
,optstring
))!=EOF
){
119 begin_time
=atof(optarg
);
122 ratecode
=atoi(optarg
);
123 if(ratecode
<1)ratecode
=1;
124 if(ratecode
>8)ratecode
=8;
125 vidout_fps
=framerates
[ratecode
];
131 vidin_fps
=atof(optarg
);
132 if(vidin_fps
<1.)vidin_fps
=1.;
133 if(vidin_fps
>60.)vidin_fps
=60.;
139 end_time
=begin_time
+atof(optarg
);
146 char *h
=strchr(optarg
,'x');
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;
167 done
=snatch_iterator(stdin
,stdout
,0,yuvtype
);
170 long seconds
=framesout
/vidout_fps
;
171 long minutes
=seconds
/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
);
188 if(noisy
)fprintf(stderr
,"\n");
190 if(max
<fpsgraph
[i
])max
=fpsgraph
[i
];
193 int val
=(int)(fpsgraph
[i
]*70/max
);
195 fprintf(stderr
,"%3dfps|%*c\n",i
,val
-1,'*');
197 fprintf(stderr
,"%3dfps|\n",i
,val
-1,'*');
201 if(noisy
)fprintf(stderr
,"\n");