Debian Codegraph @

encodedv/encodedv.c

raw symbols ◀ ▶ SCIP
1 Debian patch touch this file
1 /*
2 * encodedv.c
3 *
4 * Copyright (C) James Bowman - July 2000
5 * Peter Schlaile - Jan 2001
6 *
7 * This file is part of libdv, a free DV (IEC 61834/SMPTE 314M)
8 * codec.
9 *
10 * libdv is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU Lesser Public License as published by
12 * the Free Software Foundation; either version 2.1, or (at your
13 * option) any later version.
14 *
15 * libdv is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser Public License for more details.
19 *
20 * You should have received a copy of the GNU Lesser Public License
21 * along with libdv; see the file COPYING. If not, write to
22 * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
23 *
24 * The libdv homepage is http://libdv.sourceforge.net/.
25 */
26
•27 #ifdef HAVE_CONFIG_H
28 #include <config.h>
29 #endif
30
31 #include <string.h>
32 #include "libdv/dv_types.h"
33 #include "libdv/dv.h"
34 #include "libdv/encode.h"
35 #include "libdv/enc_input.h"
36 #include "libdv/enc_output.h"
37 #include "libdv/headers.h"
38
39 #define DV_ENCODER_OPT_VERSION 0
40 #define DV_ENCODER_OPT_START_FRAME 1
41 #define DV_ENCODER_OPT_END_FRAME 2
42 #define DV_ENCODER_OPT_WRONG_INTERLACE 3
43 #define DV_ENCODER_OPT_ENCODE_PASSES 4
44 #define DV_ENCODER_OPT_VERBOSE 5
45 #define DV_ENCODER_OPT_INPUT 6
46 #define DV_ENCODER_OPT_AUDIO_INPUT 7
47 #define DV_ENCODER_OPT_OUTPUT 8
48 #define DV_ENCODER_OPT_AUTOHELP 9
49 #define DV_ENCODER_OPT_STATIC_QNO 10
50 #define DV_ENCODER_OPT_FPS 11
51 #define DV_ENCODER_OPT_FORCE_DCT 12
52 #define DV_ENCODER_OPT_16X9 13
53 #define DV_ENCODER_OPT_STDIN 14
54 #define DV_ENCODER_NUM_OPTS 15
55
56 int main(int argc, char *argv[])
57 {
58 unsigned long start = 0;
59 unsigned long end = 0xfffffff;
60 int wrong_interlace = 0;
61 const char* filename = NULL;
62 const char* audio_filename = NULL;
63 int vlc_encode_passes = 3;
64 int static_qno = 0;
65 int verbose_mode = 0;
66 const char* audio_input_filter_str = "none";
67 const char* input_filter_str = "ppm";
68 const char* output_filter_str = "raw";
69 dv_enc_audio_input_filter_t * audio_input_filter = NULL;
70 dv_enc_input_filter_t * input_filter;
71 dv_enc_output_filter_t * output_filter;
72 int count = 0;
73 int fps = 0;
74 int is16x9 = 0;
75 int err_code;
76 int force_dct = -1;
77 int isStdin = 0;
78
79 #if HAVE_LIBPOPT
80 struct poptOption option_table[DV_ENCODER_NUM_OPTS+1];
81 int rc; /* return code from popt */
82 poptContext optCon; /* context for parsing command-line options */
83 option_table[DV_ENCODER_OPT_VERSION] = (struct poptOption) {
84 longName: "version",
85 val: 'v',
86 descrip: "show encode version number"
87 }; /* version */
88
89 option_table[DV_ENCODER_OPT_START_FRAME] = (struct poptOption) {
90 longName: "start-frame",
91 shortName: 's',
92 argInfo: POPT_ARG_INT,
93 arg: &start,
94 argDescrip: "count",
95 descrip: "start at <count> frame (defaults to 0)"
96 }; /* start-frame */
97
98 option_table[DV_ENCODER_OPT_END_FRAME] = (struct poptOption) {
99 longName: "end-frame",
100 shortName: 'e',
101 argInfo: POPT_ARG_INT,
102 arg: &end,
103 argDescrip: "count",
104 descrip: "end at <count> frame (defaults to unlimited)"
105 }; /* end-frames */
106
107 option_table[DV_ENCODER_OPT_WRONG_INTERLACE] = (struct poptOption) {
108 longName: "wrong-interlace",
109 shortName: 'l',
110 arg: &wrong_interlace,
111 descrip: "flip lines to compensate for wrong interlacing"
112 }; /* wrong-interlace */
113
114 option_table[DV_ENCODER_OPT_ENCODE_PASSES] = (struct poptOption) {
115 longName: "vlc-passes",
116 shortName: 'p',
117 argInfo: POPT_ARG_INT,
118 arg: &vlc_encode_passes,
119 descrip: "vlc code distribution passes (1-3) "
120 "greater values = better quality but "
121 "not necessarily slower encoding!"
122 }; /* vlc encoder passes */
123
124 option_table[DV_ENCODER_OPT_VERBOSE] = (struct poptOption) {
125 longName: "verbose",
126 shortName: 'v',
127 arg: &verbose_mode,
128 descrip: "show encoder statistics / status information"
129 }; /* verbose mode */
130
131 option_table[DV_ENCODER_OPT_INPUT] = (struct poptOption) {
132 longName: "input",
133 shortName: 'i',
134 arg: &input_filter_str,
135 argInfo: POPT_ARG_STRING,
136 descrip: "choose input-filter [>ppm<, pgm, video]"
137 }; /* input */
138
139 option_table[DV_ENCODER_OPT_AUDIO_INPUT] = (struct poptOption) {
140 longName: "audio-input",
141 shortName: 'a',
142 arg: &audio_input_filter_str,
143 argInfo: POPT_ARG_STRING,
144 descrip: "choose audio-input-filter [>none<, wav, dsp]"
145 }; /* audio input */
146
147 option_table[DV_ENCODER_OPT_OUTPUT] = (struct poptOption) {
148 longName: "output",
149 shortName: 'o',
150 arg: &output_filter_str,
151 argInfo: POPT_ARG_STRING,
152 descrip: "choose output-filter [>raw<]"
153 }; /* output */
154
155 option_table[DV_ENCODER_OPT_STATIC_QNO] = (struct poptOption) {
156 longName: "static-qno",
157 shortName: 'q',
158 arg: &static_qno,
159 argInfo: POPT_ARG_INT,
160 descrip: "static qno tables for quantisation on 2 VLC "
161 "passes. For turbo (but somewhat lossy encoding) try "
162 "-q [1,2] -p 2"
163 }; /* start qno */
164
165 option_table[DV_ENCODER_OPT_FPS] = (struct poptOption) {
166 longName: "fps",
167 shortName: 'f',
168 arg: &fps,
169 argInfo: POPT_ARG_INT,
170 descrip: "set frames per second (default: use all frames)"
171 }; /* fps */
172
173 option_table[DV_ENCODER_OPT_FORCE_DCT] = (struct poptOption) {
174 longName: "force-dct",
175 shortName: 'd',
176 arg: &force_dct,
177 argInfo: POPT_ARG_INT,
178 descrip: "force dct mode (88 or 248) for whole picture"
179 }; /* force dct */
180
181 option_table[DV_ENCODER_OPT_16X9] = (struct poptOption) {
182 longName: "wide",
183 shortName: 'w',
184 arg: &is16x9,
185 argInfo: POPT_ARG_INT,
186 descrip: "set wide 16 x 9 format"
187 }; /* 16x9 */
188
189 option_table[DV_ENCODER_OPT_STDIN] = (struct poptOption) {
190 longName: "",
191 shortName: '-',
192 arg: &isStdin,
193 descrip: "set stdin input"
194 }; /* stdin */
195
196 option_table[DV_ENCODER_OPT_AUTOHELP] = (struct poptOption) {
197 argInfo: POPT_ARG_INCLUDE_TABLE,
198 arg: poptHelpOptions,
199 descrip: "Help options",
200 }; /* autohelp */
201
202 option_table[DV_ENCODER_NUM_OPTS] = (struct poptOption) {
203 NULL, 0, 0, NULL, 0 };
204
205 optCon = poptGetContext(NULL, argc,
206 (const char **)argv, option_table, 0);
207 poptSetOtherOptionHelp(optCon, "<filename pattern or - for stdin>"
208 " [<audio input>]");
209
210 while ((rc = poptGetNextOpt(optCon)) > 0) {
211 switch (rc) {
212 case 'v':
213 fprintf(stderr,"encode: version %s, "
214 "http://libdv.sourceforge.net/\n",
215 "CVS 01/14/2001");
216 exit(0);
217 break;
218 default:
219 break;
220 } /* switch */
221 } /* while */
222
223 if (rc < -1) {
224 /* an error occurred during option processing */
225 fprintf(stderr, "%s: %s\n",
226 poptBadOption(optCon, POPT_BADOPTION_NOALIAS),
227 poptStrerror(rc));
228 exit(-1);
229 }
230
231 if ( !isStdin ) {
232 filename = poptGetArg(optCon);
233 if(filename == NULL) {
234 poptPrintUsage(optCon, stderr, 0);
235 fprintf(stderr,
236 "\nSpecify a single <filename pattern> argument; "
237 "e.g. pond%%05d.ppm or - for stdin\n"
238 "(For audio input specify additionally "
239 "the audio source.)\n");
240 exit(-1);
241 }
242 }
243 else {
244 filename = "-";
245 }
246
247 audio_filename = poptGetArg(optCon);
248 poptFreeContext(optCon);
249
250 #else
251 /* No popt, no usage and no options! HINT: get popt if you don't
252 * have it yet, it's at: ftp://ftp.redhat.com/pub/redhat/code/popt
253 */
254 filename = argv[1];
255 #endif /* HAVE_LIBPOPT */
256
257 dv_enc_get_input_filters(&input_filter, &count);
258 while (count
259 && strcmp(input_filter->filter_name, input_filter_str) != 0) {
260 input_filter++;
261 count--;
262 }
263 if (!count) {
264 fprintf(stderr, "Unknown input filter selected: %s!\n"
265 "The following filters are supported:\n",
266 input_filter_str);
267 dv_enc_get_input_filters(&input_filter, &count);
268 while (count--) {
269 fprintf(stderr, "%s\n", input_filter->filter_name);
270 input_filter++;
271 }
272 return(-1);
273 }
274
275 if (strcmp(audio_input_filter_str, "none") != 0) {
276 dv_enc_get_audio_input_filters(&audio_input_filter, &count);
277 while (count
278 && strcmp(audio_input_filter->filter_name,
279 audio_input_filter_str) != 0) {
280 audio_input_filter++;
281 count--;
282 }
283 if (!count) {
284 fprintf(stderr,
285 "Unknown audio input filter selected: %s!\n"
286 "The following filters are supported:\n",
287 audio_input_filter_str);
288 dv_enc_get_audio_input_filters(&audio_input_filter,
289 &count);
290 while (count--) {
291 fprintf(stderr, "%s\n",
292 audio_input_filter->filter_name);
293 audio_input_filter++;
294 }
295 return(-1);
296 }
297 if (!audio_filename) {
298 fprintf(stderr, "Audio input selected but no filename "
299 "or device given!\n");
300 return(-1);
301 }
302 }
303
304 dv_enc_get_output_filters(&output_filter, &count);
305 while (count &&
306 strcmp(output_filter->filter_name, output_filter_str) != 0) {
307 output_filter++;
308 count--;
309 }
310 if (!count) {
311 fprintf(stderr, "Unknown output filter selected: %s!\n"
312 "The following filters are supported:\n",
313 output_filter_str);
314 dv_enc_get_output_filters(&output_filter, &count);
315 while (count--) {
316 fprintf(stderr, "%s\n", output_filter->filter_name);
317 output_filter++;
318 }
319 return(-1);
320 }
321 if (static_qno < 0 || static_qno > 2) {
322 fprintf(stderr, "There are only two static qno tables "
323 "registered right now:\n"
324 "1 : for sharp DV pictures\n"
325 "2 : for somewhat noisy satelite television signal\n"
326 "\nIf you want to add some more, go ahead ;-)\n");
327 return(-1);
328 }
329 if (static_qno && vlc_encode_passes == 1) {
330 fprintf(stderr, "Warning! static_qno enabled but "
331 "vlc_passes == 1.\n"
332 "This won't gain you anything for now !!!\n");
333 }
334 if (force_dct != -1) {
335 switch (force_dct) {
336 case 88:
337 force_dct = DV_DCT_88;
338 break;
339 case 248:
340 force_dct = DV_DCT_248;
341 break;
342 default:
343 fprintf(stderr, "--force-dct has to be 88 or 248!\n");
344 return(-1);
345 }
346 }
347
348 dv_init(FALSE, FALSE);
349
350 if (input_filter->init(wrong_interlace, force_dct) < 0) {
351 return -1;
352 }
353 if (output_filter->init(stdout) < 0) {
354 return -1;
355 }
356 /* audio_input_filter->init() is in dv_encoder_loop! */
357
358 err_code = dv_encoder_loop(input_filter,audio_input_filter, output_filter,
359 start, end, filename, audio_filename,
360 vlc_encode_passes, static_qno,
361 verbose_mode, fps, is16x9);
362
363 input_filter->finish();
364 if (audio_input_filter) {
365 audio_input_filter->finish();
366 }
367 output_filter->finish();
368
369 if (verbose_mode) {
370 dv_show_statistics();
371 }
372 return 0;
373 }
374
375