Debian Codegraph @

encodedv/encodedv.c

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