Recognizes if input is ogg or not.
[xiph.git] / snatch / snatch2wav.c
blobf898b6b0eb353d662f29101abffde2b0377c3a41
1 /*
3 * snatch2wav.c
4 *
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.
9 *
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)
13 * any later version.
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). */
31 #include <unistd.h>
32 #include <stdlib.h>
33 #include <stdio.h>
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){
51 fprintf(f,
52 "snatch2wav 20011115\n\n"
53 "USAGE: snatch2wav [options] < infile { > outfile, | nextutil }\n\n"
54 "OPTIONS:\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[]){
72 int done=0;
73 int noisy =1;
74 int c;
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){
81 switch(c){
82 case 'b':
83 begin_time=atof(optarg);
84 break;
85 case 'c':
86 audbuf_channels=atoi(optarg);
87 if(audbuf_channels<1)audbuf_channels=1;
88 if(audbuf_channels>2)audbuf_channels=2;
89 break;
90 case 'h':
91 usage(stdout);
92 return(0);
93 case 'n':
94 end_time=begin_time+atof(optarg);
95 break;
96 case 'q':
97 noisy=0;
98 break;
99 case 'r':
100 audbuf_rate=atol(optarg);
101 if(audbuf_rate<4000)audbuf_rate=4000;
102 if(audbuf_rate>48000)audbuf_rate=48000;
103 break;
104 default:
105 usage(stderr);
106 exit(1);
110 while(!done){
111 done=snatch_iterator(stdin,stdout,1,0);
113 if(noisy && audbuf_rate){
114 long seconds=samplesout/audbuf_rate;
115 long minutes=seconds/60;
116 long hours;
118 seconds-=minutes*60;
119 hours=minutes/60;
120 minutes-=hours*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");
129 return(0);