5 * Copyright (C) 2001 Monty
7 * This file is part of snatch2wav, a component of the "MJPEG tools"
8 * suite of open source tools for MJPEG and MPEG processing.
10 * snatch2wav 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 * snatch2wav 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 depths, rates and channels.
28 This resamples the given input files to the first rate/number of
29 channels it sees (or user selected format). */
35 extern long audbuf_rate
;
36 extern int audbuf_channels
;
37 extern long long audbuf_samples
;
39 extern long long samplesin
;
40 extern long long samplesout
;
41 extern long long samplesmissing
;
42 extern long long samplesdiscarded
;
44 extern double vidin_fps
;
45 extern double vidout_fps
;
46 extern int video_timeahead
;
48 int snatch_iterator(FILE *in
,FILE *out
,int process_a
,int process_v
);
50 static void usage(FILE *f
){
52 "snatch2wav 20011115\n\n"
53 "USAGE: snatch2wav [options] < infile { > outfile, | nextutil }\n\n"
55 " -b <N> : skip first <N> seconds of input file\n"
56 " -c <N> : convert to <N> output channels\n"
57 " -h : this information to stdout\n"
58 " -n <N> : output only up to the last frame beginning \n"
59 " before <N> seconds elapsed from start of file\n"
60 " (if preceeding or without -b) or from start of\n"
61 " output (following -b)\n"
62 " -q : operate quietly\n"
63 " -r <N> : resample to output rate <N>\n\n");
66 const char *optstring
= "b:c:hn:qr:";
68 extern double begin_time
;
69 extern double end_time
;
71 int main(int argc
,char *argv
[]){
76 video_timeahead
=2; /* absolute minimum for sync to work */
77 vidin_fps
=30; /* not critical in audio, but must still be set */
78 vidout_fps
=30; /* not critical in audio, but must still be set */
80 while((c
=getopt(argc
,argv
,optstring
))!=EOF
){
83 begin_time
=atof(optarg
);
86 audbuf_channels
=atoi(optarg
);
87 if(audbuf_channels
<1)audbuf_channels
=1;
88 if(audbuf_channels
>2)audbuf_channels
=2;
94 end_time
=begin_time
+atof(optarg
);
100 audbuf_rate
=atol(optarg
);
101 if(audbuf_rate
<4000)audbuf_rate
=4000;
102 if(audbuf_rate
>48000)audbuf_rate
=48000;
111 done
=snatch_iterator(stdin
,stdout
,1,0);
113 if(noisy
&& audbuf_rate
){
114 long seconds
=samplesout
/audbuf_rate
;
115 long minutes
=seconds
/60;
122 fprintf(stderr
,"\rSamples %ld->%ld dropped:%ld missing:%ld %ld:%02ld:%02ld",
123 (long)samplesin
,(long)samplesout
,(long)samplesdiscarded
,(long)samplesmissing
,
124 hours
,minutes
,seconds
);
128 if(noisy
)fprintf(stderr
,"\n");