disable the unrecognized nls and x flags
[AROS-Contrib.git] / MultiMedia / play / play.c
blob82af10f83ad7a22da224c1d4be68e58d600f217b
1 /*
2 2004/09/10 - Joseph Fenton, changed to support
3 playing audio-only streams. Removed code that
4 killed using audio in AROS. Put conditional
5 around gtk_init() for AROS.
6 */
8 #include "externs.h"
9 #include "freq.h"
10 #include <exec/types.h>
12 int audio_sample_rate, audio_channels = -1;
13 int frame_width = 320, frame_height = 240, use_audio = 0;
14 int no_video = 1;
15 int verbose = 0, debugging = 0;
16 int benchmark_mode = 0;
17 double frame_rate = 20.0;
18 int force_fps = -1;
19 LONG __stack = 600000; /* Make it big!! */
21 void show_formats(void)
23 AVInputFormat *ifmt;
24 AVCodec *p;
26 printf("Input audio/video file formats:");
27 for(ifmt = first_iformat; ifmt != NULL; ifmt = ifmt->next) {
28 printf(" %s", ifmt->name);
30 printf("\n\n");
32 printf(" Decoders:");
33 for(p = first_avcodec; p != NULL; p = p->next) {
34 if (p->decode)
35 printf(" %s", p->name);
38 printf("\n");
41 #include "getopt.h"
43 #if defined(AMIGA) || defined(AROS)
44 #include <proto/dos.h>
45 BPTR lock = NULL, oldlock;
47 void amigaquit()
49 if (lock) {
50 CurrentDir(oldlock);
51 UnLock(lock);
54 #endif
56 int main(int argc, char *argv[])
58 int i;
59 char *filename;
60 AVFormatContext *ic;
61 AVInputFormat *file_iformat = NULL;
62 AVFormatParameters params;
63 char *c;
65 av_register_all();
67 while ((i = getopt(argc, argv, "hbBndvif:")) != EOF) {
68 switch(i) {
69 case 'h':
70 printf("Usage: %s [options] [filename]\n"
71 "-h\tThis help.\n"
72 "-n\tDisable audio.\n"
73 "-b\tBenchmark mode (no display, no audio)\n"
74 "-B\tBenchmark mode (no audio)\n"
75 "-v\tVerbose mode\n"
76 "-i\tShow supported formats and exits\n"
77 "-d\tDelay initialization for debugging purposes\n"
78 "-f <value>\tForce frames per second to value\n"
79 , argv[0]);
81 return 0;
82 case 'v':
83 verbose = 1;
84 break;
85 case 'b':
86 benchmark_mode = 2;
87 break;
88 case 'B':
89 benchmark_mode = 1;
90 break;
91 case 'n':
92 use_audio = -1;
93 break;
94 case 'f':
95 force_fps = atoi(optarg);
96 break;
97 case 'i':
98 show_formats();
99 return 0;
100 case 'd':
101 debugging = 1;
102 break;
103 default:
104 printf("Unknown option %c\n", i);
105 return 0;
109 if((argc-optind) != 1) {
110 FRequest f;
112 #ifndef AROS
113 #ifdef linux
114 gtk_init(&argc, &argv);
115 #endif
116 #endif
118 f.Title = "Select a movie to play...";
119 f.Dir = NULL;
120 f.Filter = "All supported files|*.mpg;*.avi;*.mov;*.qt;*.asf;*.mpeg|MPEG Files|*.mpg;*.mpeg|AVI Files|*.avi|Quicktime Files|*.qt;*.mov|All files|*.*\0\0";
121 f.Save = 0;
123 if(Request(&f)) {
124 // the following code is due to the fact avformat has a few problems with Amigalike paths...
125 #if defined(AMIGA) || defined(AROS)
126 filename = FilePart(f.File);
127 if (strcmp(filename, f.File)) {
128 lock = Lock(PathPart(f.File), ACCESS_READ);
130 if (lock) {
131 oldlock = CurrentDir(lock);
132 atexit(amigaquit);
135 #else
136 filename = f.File;
137 #endif
139 else
140 return 0;
142 else
143 filename = argv[optind];
145 if((c = strrchr(filename, '.'))) {
146 file_iformat = av_find_input_format(c + 1);
148 printf("First guess of fileformat: %s\n",
149 file_iformat ? file_iformat->name : "UNKNOWN");
152 memset(&params, 0, sizeof(params));
154 if(av_open_input_file(&ic, filename, NULL /*file_iformat*/, 0, &params) < 0) {
155 fprintf(stderr, "Unable to find format of %s\n", filename);
156 return 0;
159 if(av_find_stream_info(ic) < 0) {
160 fprintf(stderr, "%s: could not find codec parameters\n", filename);
161 return 0;
165 dump_format(ic, 0, filename, 0);
167 if (verbose)
168 fprintf(stderr, "Examining %d streams...\n", ic->nb_streams);
170 for(i=0;i<ic->nb_streams;i++) {
171 AVCodecContext *enc = &ic->streams[i]->codec;
172 switch(enc->codec_type) {
173 case CODEC_TYPE_AUDIO:
174 if(use_audio != -1) {
175 use_audio = 1;
176 audio_channels = enc->channels;
177 audio_sample_rate = enc->sample_rate;
179 if(verbose)
180 fprintf(stderr, "audio: %d/%d\n",
181 enc->sample_rate, enc->channels);
184 break;
185 case CODEC_TYPE_VIDEO:
186 no_video = 0;
187 frame_height = enc->height;
188 frame_width = enc->width;
189 frame_rate = (double)ic->streams[i]->r_frame_rate / (double)ic->streams[i]->r_frame_rate_base;
190 #if 0
191 enc->workaround_bugs = FF_BUG_AUTODETECT;
192 enc->error_resilience = 2;
193 enc->error_concealment = 3;
194 enc->idct_algo= 0;
195 #endif
196 if(force_fps > 0) {
197 fprintf(stderr, "FPS forced from %f to %f.\n",
198 frame_rate, (double) force_fps);
199 frame_rate = force_fps;
202 if(verbose)
203 fprintf(stderr, "video: %dx%d %f fps\n",
204 frame_width, frame_height, frame_rate);
205 break;
210 if(!(c = strrchr(filename,
211 #ifdef WIN32
212 '\\'
213 #else
215 #endif
217 c = filename;
218 else
219 c++;
221 if(benchmark_mode || use_audio == -1)
222 use_audio = 0;
224 if(verbose) {
225 fprintf(stderr, "Initializing the audio/video section...\n");
227 if(debugging)
228 os_delay(2000);
231 init_system(c);
233 if(verbose) {
234 fprintf(stderr, "Start decoding %s (%lx/%d)...\n", c, ic, ic->nb_streams);
236 if(debugging)
237 os_delay(2000);
239 play_decode_stream(ic);