]> git.sesse.net Git - nageru/blob - flags.cpp
Add a switch for writing a timecode to the stream; useful for latency debugging.
[nageru] / flags.cpp
1 #include "flags.h"
2
3 #include <getopt.h>
4 #include <stdio.h>
5 #include <stdlib.h>
6 #include <string.h>
7
8 #include <utility>
9
10 using namespace std;
11
12 Flags global_flags;
13
14 // Long options that have no corresponding short option.
15 enum LongOption {
16         OPTION_HELP = 1000,
17         OPTION_MULTICHANNEL,
18         OPTION_MIDI_MAPPING,
19         OPTION_FAKE_CARDS_AUDIO,
20         OPTION_HTTP_UNCOMPRESSED_VIDEO,
21         OPTION_HTTP_X264_VIDEO,
22         OPTION_X264_PRESET,
23         OPTION_X264_TUNE,
24         OPTION_X264_SPEEDCONTROL,
25         OPTION_X264_SPEEDCONTROL_VERBOSE,
26         OPTION_X264_BITRATE,
27         OPTION_X264_VBV_BUFSIZE,
28         OPTION_X264_VBV_MAX_BITRATE,
29         OPTION_X264_PARAM,
30         OPTION_HTTP_MUX,
31         OPTION_HTTP_COARSE_TIMEBASE,
32         OPTION_HTTP_AUDIO_CODEC,
33         OPTION_HTTP_AUDIO_BITRATE,
34         OPTION_FLAT_AUDIO,
35         OPTION_GAIN_STAGING,
36         OPTION_DISABLE_LOCUT,
37         OPTION_ENABLE_LOCUT,
38         OPTION_DISABLE_GAIN_STAGING_AUTO,
39         OPTION_ENABLE_GAIN_STAGING_AUTO,
40         OPTION_DISABLE_COMPRESSOR,
41         OPTION_ENABLE_COMPRESSOR,
42         OPTION_DISABLE_LIMITER,
43         OPTION_ENABLE_LIMITER,
44         OPTION_DISABLE_MAKEUP_GAIN_AUTO,
45         OPTION_ENABLE_MAKEUP_GAIN_AUTO,
46         OPTION_DISABLE_ALSA_OUTPUT,
47         OPTION_NO_FLUSH_PBOS,
48         OPTION_PRINT_VIDEO_LATENCY,
49         OPTION_MAX_INPUT_QUEUE_FRAMES,
50         OPTION_AUDIO_QUEUE_LENGTH_MS,
51         OPTION_OUTPUT_YCBCR_COEFFICIENTS,
52         OPTION_OUTPUT_BUFFER_FRAMES,
53         OPTION_OUTPUT_SLOP_FRAMES,
54         OPTION_TIMECODE_STREAM,
55         OPTION_TIMECODE_STDOUT,
56 };
57
58 void usage()
59 {
60         fprintf(stderr, "Usage: nageru [OPTION]...\n");
61         fprintf(stderr, "\n");
62         fprintf(stderr, "      --help                      print usage information\n");
63         fprintf(stderr, "  -w, --width                     output width in pixels (default 1280)\n");
64         fprintf(stderr, "  -h, --height                    output height in pixels (default 720)\n");
65         fprintf(stderr, "  -c, --num-cards                 set number of input cards (default 2)\n");
66         fprintf(stderr, "  -o, --output-card=CARD          also output signal to the given card (default none)\n");
67         fprintf(stderr, "  -t, --theme=FILE                choose theme (default theme.lua)\n");
68         fprintf(stderr, "  -I, --theme-dir=DIR             search for theme in this directory (can be given multiple times)\n");
69         fprintf(stderr, "  -v, --va-display=SPEC           VA-API device for H.264 encoding\n");
70         fprintf(stderr, "                                    ($DISPLAY spec or /dev/dri/render* path)\n");
71         fprintf(stderr, "  -m, --map-signal=SIGNAL,CARD    set a default card mapping (can be given multiple times)\n");
72         fprintf(stderr, "  -M, --input-mapping=FILE        start with the given audio input mapping (implies --multichannel)\n");
73         fprintf(stderr, "      --multichannel              start in multichannel audio mapping mode\n");
74         fprintf(stderr, "      --midi-mapping=FILE         start with the given MIDI controller mapping (implies --multichannel)\n");
75         fprintf(stderr, "      --fake-cards-audio          make fake (disconnected) cards output a simple tone\n");
76         fprintf(stderr, "      --http-uncompressed-video   send uncompressed NV12 video to HTTP clients\n");
77         fprintf(stderr, "      --http-x264-video           send x264-compressed video to HTTP clients\n");
78         fprintf(stderr, "      --x264-preset               x264 quality preset (default " X264_DEFAULT_PRESET ")\n");
79         fprintf(stderr, "      --x264-tune                 x264 tuning (default " X264_DEFAULT_TUNE ", can be blank)\n");
80         fprintf(stderr, "      --x264-speedcontrol         try to match x264 preset to available CPU speed\n");
81         fprintf(stderr, "      --x264-speedcontrol-verbose  output speedcontrol debugging statistics\n");
82         fprintf(stderr, "      --x264-bitrate              x264 bitrate (in kilobit/sec, default %d)\n",
83                 DEFAULT_X264_OUTPUT_BIT_RATE);
84         fprintf(stderr, "      --x264-vbv-bufsize          x264 VBV size (in kilobits, 0 = one-frame VBV,\n");
85         fprintf(stderr, "                                  default: same as --x264-bitrate, that is, one-second VBV)\n");
86         fprintf(stderr, "      --x264-vbv-max-bitrate      x264 local max bitrate (in kilobit/sec per --vbv-bufsize,\n");
87         fprintf(stderr, "                                  0 = no limit, default: same as --x264-bitrate, i.e., CBR)\n");
88         fprintf(stderr, "      --x264-param=NAME[,VALUE]   set any x264 parameter, for fine tuning\n");
89         fprintf(stderr, "      --http-mux=NAME             mux to use for HTTP streams (default " DEFAULT_STREAM_MUX_NAME ")\n");
90         fprintf(stderr, "      --http-audio-codec=NAME     audio codec to use for HTTP streams\n");
91         fprintf(stderr, "                                  (default is to use the same as for the recording)\n");
92         fprintf(stderr, "      --http-audio-bitrate=KBITS  audio codec bit rate to use for HTTP streams\n");
93         fprintf(stderr, "                                  (default is %d, ignored unless --http-audio-codec is set)\n",
94                 DEFAULT_AUDIO_OUTPUT_BIT_RATE / 1000);
95         fprintf(stderr, "      --http-coarse-timebase      use less timebase for HTTP (recommended for muxers\n");
96         fprintf(stderr, "                                  that handle large pts poorly, like e.g. MP4)\n");
97         fprintf(stderr, "      --flat-audio                start with most audio processing turned off\n");
98         fprintf(stderr, "                                    (can be overridden by e.g. --enable-limiter)\n");
99         fprintf(stderr, "      --gain-staging=DB           set initial gain staging to the given value\n");
100         fprintf(stderr, "                                    (--disable-gain-staging-auto)\n");
101         fprintf(stderr, "      --disable-locut             turn off locut filter (also --enable)\n");
102         fprintf(stderr, "      --disable-gain-staging-auto  turn off automatic gain staging (also --enable)\n");
103         fprintf(stderr, "      --disable-compressor        turn off regular compressor (also --enable)\n");
104         fprintf(stderr, "      --disable-limiter           turn off limiter (also --enable)\n");
105         fprintf(stderr, "      --disable-makeup-gain-auto  turn off auto-adjustment of final makeup gain (also --enable)\n");
106         fprintf(stderr, "      --disable-alsa-output       disable audio monitoring via ALSA\n");
107         fprintf(stderr, "      --no-flush-pbos             do not explicitly signal texture data uploads\n");
108         fprintf(stderr, "                                    (will give display corruption, but makes it\n");
109         fprintf(stderr, "                                    possible to run with apitrace in real time)\n");
110         fprintf(stderr, "      --print-video-latency       print out measurements of video latency on stdout\n");
111         fprintf(stderr, "      --max-input-queue-frames=FRAMES  never keep more than FRAMES frames for each card\n");
112         fprintf(stderr, "                                    (default 6, minimum 1)\n");
113         fprintf(stderr, "      --audio-queue-length-ms=MS  length of audio resampling queue (default 100.0)\n");
114         fprintf(stderr, "      --output-ycbcr-coefficients={rec601,rec709,auto}\n");
115         fprintf(stderr, "                                  Y'CbCr coefficient standard of output (default auto)\n");
116         fprintf(stderr, "                                    auto is rec709 if and only if --output-card is used\n");
117         fprintf(stderr, "                                    and a HD resolution is set\n");
118         fprintf(stderr, "      --output-buffer-frames=NUM  number of frames in output buffer for --output-card,\n");
119         fprintf(stderr, "                                    can be fractional (default 6.0); note also\n");
120         fprintf(stderr, "                                    the audio queue can't be much longer than this\n");
121         fprintf(stderr, "      --output-slop-frames=NUM    if more less than this number of frames behind for\n");
122         fprintf(stderr, "                                    --output-card, try to submit anyway instead of\n");
123         fprintf(stderr, "                                    dropping the frame (default 0.5)\n");
124         fprintf(stderr, "      --timecode-stream           show timestamp and timecode in stream\n");
125         fprintf(stderr, "      --timecode-stdout           show timestamp and timecode on standard output\n");
126 }
127
128 void parse_flags(int argc, char * const argv[])
129 {
130         static const option long_options[] = {
131                 { "help", no_argument, 0, OPTION_HELP },
132                 { "width", required_argument, 0, 'w' },
133                 { "height", required_argument, 0, 'h' },
134                 { "num-cards", required_argument, 0, 'c' },
135                 { "output-card", required_argument, 0, 'o' },
136                 { "theme", required_argument, 0, 't' },
137                 { "theme-dir", required_argument, 0, 'I' },
138                 { "map-signal", required_argument, 0, 'm' },
139                 { "input-mapping", required_argument, 0, 'M' },
140                 { "va-display", required_argument, 0, 'v' },
141                 { "multichannel", no_argument, 0, OPTION_MULTICHANNEL },
142                 { "midi-mapping", required_argument, 0, OPTION_MIDI_MAPPING },
143                 { "fake-cards-audio", no_argument, 0, OPTION_FAKE_CARDS_AUDIO },
144                 { "http-uncompressed-video", no_argument, 0, OPTION_HTTP_UNCOMPRESSED_VIDEO },
145                 { "http-x264-video", no_argument, 0, OPTION_HTTP_X264_VIDEO },
146                 { "x264-preset", required_argument, 0, OPTION_X264_PRESET },
147                 { "x264-tune", required_argument, 0, OPTION_X264_TUNE },
148                 { "x264-speedcontrol", no_argument, 0, OPTION_X264_SPEEDCONTROL },
149                 { "x264-speedcontrol-verbose", no_argument, 0, OPTION_X264_SPEEDCONTROL_VERBOSE },
150                 { "x264-bitrate", required_argument, 0, OPTION_X264_BITRATE },
151                 { "x264-vbv-bufsize", required_argument, 0, OPTION_X264_VBV_BUFSIZE },
152                 { "x264-vbv-max-bitrate", required_argument, 0, OPTION_X264_VBV_MAX_BITRATE },
153                 { "x264-param", required_argument, 0, OPTION_X264_PARAM },
154                 { "http-mux", required_argument, 0, OPTION_HTTP_MUX },
155                 { "http-coarse-timebase", no_argument, 0, OPTION_HTTP_COARSE_TIMEBASE },
156                 { "http-audio-codec", required_argument, 0, OPTION_HTTP_AUDIO_CODEC },
157                 { "http-audio-bitrate", required_argument, 0, OPTION_HTTP_AUDIO_BITRATE },
158                 { "flat-audio", no_argument, 0, OPTION_FLAT_AUDIO },
159                 { "gain-staging", required_argument, 0, OPTION_GAIN_STAGING },
160                 { "disable-locut", no_argument, 0, OPTION_DISABLE_LOCUT },
161                 { "enable-locut", no_argument, 0, OPTION_ENABLE_LOCUT },
162                 { "disable-gain-staging-auto", no_argument, 0, OPTION_DISABLE_GAIN_STAGING_AUTO },
163                 { "enable-gain-staging-auto", no_argument, 0, OPTION_ENABLE_GAIN_STAGING_AUTO },
164                 { "disable-compressor", no_argument, 0, OPTION_DISABLE_COMPRESSOR },
165                 { "enable-compressor", no_argument, 0, OPTION_ENABLE_COMPRESSOR },
166                 { "disable-limiter", no_argument, 0, OPTION_DISABLE_LIMITER },
167                 { "enable-limiter", no_argument, 0, OPTION_ENABLE_LIMITER },
168                 { "disable-makeup-gain-auto", no_argument, 0, OPTION_DISABLE_MAKEUP_GAIN_AUTO },
169                 { "enable-makeup-gain-auto", no_argument, 0, OPTION_ENABLE_MAKEUP_GAIN_AUTO },
170                 { "disable-alsa-output", no_argument, 0, OPTION_DISABLE_ALSA_OUTPUT },
171                 { "no-flush-pbos", no_argument, 0, OPTION_NO_FLUSH_PBOS },
172                 { "print-video-latency", no_argument, 0, OPTION_PRINT_VIDEO_LATENCY },
173                 { "max-input-queue-frames", required_argument, 0, OPTION_MAX_INPUT_QUEUE_FRAMES },
174                 { "audio-queue-length-ms", required_argument, 0, OPTION_AUDIO_QUEUE_LENGTH_MS },
175                 { "output-ycbcr-coefficients", required_argument, 0, OPTION_OUTPUT_YCBCR_COEFFICIENTS },
176                 { "output-buffer-frames", required_argument, 0, OPTION_OUTPUT_BUFFER_FRAMES },
177                 { "output-slop-frames", required_argument, 0, OPTION_OUTPUT_SLOP_FRAMES },
178                 { "timecode-stream", no_argument, 0, OPTION_TIMECODE_STREAM },
179                 { "timecode-stdout", no_argument, 0, OPTION_TIMECODE_STDOUT },
180                 { 0, 0, 0, 0 }
181         };
182         vector<string> theme_dirs;
183         string output_ycbcr_coefficients = "auto";
184         for ( ;; ) {
185                 int option_index = 0;
186                 int c = getopt_long(argc, argv, "c:t:I:v:m:M:w:h:", long_options, &option_index);
187
188                 if (c == -1) {
189                         break;
190                 }
191                 switch (c) {
192                 case 'w':
193                         global_flags.width = atoi(optarg);
194                         break;
195                 case 'h':
196                         global_flags.height = atoi(optarg);
197                         break;
198                 case 'c':
199                         global_flags.num_cards = atoi(optarg);
200                         break;
201                 case 'o':
202                         global_flags.output_card = atoi(optarg);
203                         break;
204                 case 't':
205                         global_flags.theme_filename = optarg;
206                         break;
207                 case 'I':
208                         theme_dirs.push_back(optarg);
209                         break;
210                 case 'm': {
211                         char *ptr = strchr(optarg, ',');
212                         if (ptr == nullptr) {
213                                 fprintf(stderr, "ERROR: Invalid argument '%s' to --map-signal (needs a signal and a card number, separated by comma)\n", optarg);
214                                 exit(1);
215                         }
216                         *ptr = '\0';
217                         const int signal_num = atoi(optarg);
218                         const int card_num = atoi(ptr + 1);
219                         if (global_flags.default_stream_mapping.count(signal_num)) {
220                                 fprintf(stderr, "ERROR: Signal %d already mapped to card %d\n",
221                                         signal_num, global_flags.default_stream_mapping[signal_num]);
222                                 exit(1);
223                         }
224                         global_flags.default_stream_mapping[signal_num] = card_num;
225                         break;
226                 }
227                 case 'M':
228                         global_flags.input_mapping_filename = optarg;
229                         break;
230                 case OPTION_MULTICHANNEL:
231                         global_flags.multichannel_mapping_mode = true;
232                         break;
233                 case 'v':
234                         global_flags.va_display = optarg;
235                         break;
236                 case OPTION_MIDI_MAPPING:
237                         global_flags.midi_mapping_filename = optarg;
238                         global_flags.multichannel_mapping_mode = true;
239                         break;
240                 case OPTION_FAKE_CARDS_AUDIO:
241                         global_flags.fake_cards_audio = true;
242                         break;
243                 case OPTION_HTTP_UNCOMPRESSED_VIDEO:
244                         global_flags.uncompressed_video_to_http = true;
245                         break;
246                 case OPTION_HTTP_MUX:
247                         global_flags.stream_mux_name = optarg;
248                         break;
249                 case OPTION_HTTP_COARSE_TIMEBASE:
250                         global_flags.stream_coarse_timebase = true;
251                         break;
252                 case OPTION_HTTP_AUDIO_CODEC:
253                         global_flags.stream_audio_codec_name = optarg;
254                         break;
255                 case OPTION_HTTP_AUDIO_BITRATE:
256                         global_flags.stream_audio_codec_bitrate = atoi(optarg) * 1000;
257                         break;
258                 case OPTION_HTTP_X264_VIDEO:
259                         global_flags.x264_video_to_http = true;
260                         break;
261                 case OPTION_X264_PRESET:
262                         global_flags.x264_preset = optarg;
263                         break;
264                 case OPTION_X264_TUNE:
265                         global_flags.x264_tune = optarg;
266                         break;
267                 case OPTION_X264_SPEEDCONTROL:
268                         global_flags.x264_speedcontrol = true;
269                         break;
270                 case OPTION_X264_SPEEDCONTROL_VERBOSE:
271                         global_flags.x264_speedcontrol_verbose = true;
272                         break;
273                 case OPTION_X264_BITRATE:
274                         global_flags.x264_bitrate = atoi(optarg);
275                         break;
276                 case OPTION_X264_VBV_BUFSIZE:
277                         global_flags.x264_vbv_buffer_size = atoi(optarg);
278                         break;
279                 case OPTION_X264_VBV_MAX_BITRATE:
280                         global_flags.x264_vbv_max_bitrate = atoi(optarg);
281                         break;
282                 case OPTION_X264_PARAM:
283                         global_flags.x264_extra_param.push_back(optarg);
284                         break;
285                 case OPTION_FLAT_AUDIO:
286                         // If --flat-audio is given, turn off everything that messes with the sound,
287                         // except the final makeup gain.
288                         global_flags.locut_enabled = false;
289                         global_flags.gain_staging_auto = false;
290                         global_flags.compressor_enabled = false;
291                         global_flags.limiter_enabled = false;
292                         break;
293                 case OPTION_GAIN_STAGING:
294                         global_flags.initial_gain_staging_db = atof(optarg);
295                         global_flags.gain_staging_auto = false;
296                         break;
297                 case OPTION_DISABLE_LOCUT:
298                         global_flags.locut_enabled = false;
299                         break;
300                 case OPTION_ENABLE_LOCUT:
301                         global_flags.locut_enabled = true;
302                         break;
303                 case OPTION_DISABLE_GAIN_STAGING_AUTO:
304                         global_flags.gain_staging_auto = false;
305                         break;
306                 case OPTION_ENABLE_GAIN_STAGING_AUTO:
307                         global_flags.gain_staging_auto = true;
308                         break;
309                 case OPTION_DISABLE_COMPRESSOR:
310                         global_flags.compressor_enabled = false;
311                         break;
312                 case OPTION_ENABLE_COMPRESSOR:
313                         global_flags.compressor_enabled = true;
314                         break;
315                 case OPTION_DISABLE_LIMITER:
316                         global_flags.limiter_enabled = false;
317                         break;
318                 case OPTION_ENABLE_LIMITER:
319                         global_flags.limiter_enabled = true;
320                         break;
321                 case OPTION_DISABLE_MAKEUP_GAIN_AUTO:
322                         global_flags.final_makeup_gain_auto = false;
323                         break;
324                 case OPTION_ENABLE_MAKEUP_GAIN_AUTO:
325                         global_flags.final_makeup_gain_auto = true;
326                         break;
327                 case OPTION_DISABLE_ALSA_OUTPUT:
328                         global_flags.enable_alsa_output = false;
329                         break;
330                 case OPTION_NO_FLUSH_PBOS:
331                         global_flags.flush_pbos = false;
332                         break;
333                 case OPTION_PRINT_VIDEO_LATENCY:
334                         global_flags.print_video_latency = true;
335                         break;
336                 case OPTION_MAX_INPUT_QUEUE_FRAMES:
337                         global_flags.max_input_queue_frames = atoi(optarg);
338                         break;
339                 case OPTION_AUDIO_QUEUE_LENGTH_MS:
340                         global_flags.audio_queue_length_ms = atof(optarg);
341                         break;
342                 case OPTION_OUTPUT_YCBCR_COEFFICIENTS:
343                         output_ycbcr_coefficients = optarg;
344                         break;
345                 case OPTION_OUTPUT_BUFFER_FRAMES:
346                         global_flags.output_buffer_frames = atof(optarg);
347                         break;
348                 case OPTION_OUTPUT_SLOP_FRAMES:
349                         global_flags.output_slop_frames = atof(optarg);
350                         break;
351                 case OPTION_TIMECODE_STREAM:
352                         global_flags.display_timecode_in_stream = true;
353                         break;
354                 case OPTION_TIMECODE_STDOUT:
355                         global_flags.display_timecode_on_stdout = true;
356                         break;
357                 case OPTION_HELP:
358                         usage();
359                         exit(0);
360                 default:
361                         fprintf(stderr, "Unknown option '%s'\n", argv[option_index]);
362                         fprintf(stderr, "\n");
363                         usage();
364                         exit(1);
365                 }
366         }
367
368         if (global_flags.uncompressed_video_to_http &&
369             global_flags.x264_video_to_http) {
370                 fprintf(stderr, "ERROR: --http-uncompressed-video and --http-x264-video are mutually incompatible\n");
371                 exit(1);
372         }
373         if (global_flags.num_cards <= 0) {
374                 fprintf(stderr, "ERROR: --num-cards must be at least 1\n");
375                 exit(1);
376         }
377         if (global_flags.output_card < -1 ||
378             global_flags.output_card >= global_flags.num_cards) {
379                 fprintf(stderr, "ERROR: --output-card points to a nonexistant card\n");
380                 exit(1);
381         }
382         if (global_flags.x264_speedcontrol) {
383                 if (!global_flags.x264_preset.empty() && global_flags.x264_preset != "faster") {
384                         fprintf(stderr, "WARNING: --x264-preset is overridden by --x264-speedcontrol (implicitly uses \"faster\" as base preset)\n");
385                 }
386                 global_flags.x264_preset = "faster";
387         } else if (global_flags.x264_preset.empty()) {
388                 global_flags.x264_preset = X264_DEFAULT_PRESET;
389         }
390         if (!theme_dirs.empty()) {
391                 global_flags.theme_dirs = theme_dirs;
392         }
393
394         // In reality, we could probably do with any even value (we subsample
395         // by two in some places), but it's better to be on the safe side
396         // wrt. video codecs and such. (I'd set 16 if I could, but 1080 isn't
397         // divisible by 16.)
398         if (global_flags.width <= 0 || (global_flags.width % 8) != 0 ||
399             global_flags.height <= 0 || (global_flags.height % 8) != 0) {
400                 fprintf(stderr, "ERROR: --width and --height must be positive integers divisible by 8\n");
401                 exit(1);
402         }
403
404         for (pair<int, int> mapping : global_flags.default_stream_mapping) {
405                 if (mapping.second >= global_flags.num_cards) {
406                         fprintf(stderr, "ERROR: Signal %d mapped to card %d, which doesn't exist (try adjusting --num-cards)\n",
407                                 mapping.first, mapping.second);
408                         exit(1);
409                 }
410         }
411
412         // Rec. 709 would be the sane thing to do, but it seems many players
413         // just default to BT.601 coefficients no matter what. We _do_ set
414         // the right flags, so that a player that works properly doesn't have
415         // to guess, but it's frequently ignored. See discussions
416         // in e.g. https://trac.ffmpeg.org/ticket/4978; the situation with
417         // browsers is complicated and depends on things like hardware acceleration
418         // (https://bugs.chromium.org/p/chromium/issues/detail?id=333619 for
419         // extensive discussion). VLC generally fixed this as part of 3.0.0
420         // (see e.g. https://github.com/videolan/vlc/commit/bc71288b2e38c07d6921472824b92eef1aa85f7e
421         // and https://github.com/videolan/vlc/commit/c3fc2683a9cde1d42674ebf9935dced05733a215),
422         // but earlier versions were pretty random.
423         //
424         // On the other hand, HDMI/SDI output typically requires Rec. 709 for
425         // HD resolutions (with no way of signaling anything else), which is
426         // a conflicting demand. In this case, we typically let the HDMI/SDI
427         // output win, but the user can override this.
428         if (output_ycbcr_coefficients == "auto") {
429                 if (global_flags.output_card >= 0 && global_flags.width >= 1280) {
430                         global_flags.ycbcr_rec709_coefficients = true;
431                 } else {
432                         global_flags.ycbcr_rec709_coefficients = false;
433                 }
434         } else if (output_ycbcr_coefficients == "rec709") {
435                 global_flags.ycbcr_rec709_coefficients = true;
436         } else if (output_ycbcr_coefficients == "rec601") {
437                 global_flags.ycbcr_rec709_coefficients = false;
438         } else {
439                 fprintf(stderr, "ERROR: --output-ycbcr-coefficients must be “rec601”, “rec709” or “auto”\n");
440                 exit(1);
441         }
442
443         if (global_flags.output_buffer_frames < 0.0f) {
444                 // Actually, even zero probably won't make sense; there is some internal
445                 // delay to the card.
446                 fprintf(stderr, "ERROR: --output-buffer-frames can't be negative.\n");
447                 exit(1);
448         }
449         if (global_flags.output_slop_frames < 0.0f) {
450                 fprintf(stderr, "ERROR: --output-slop-frames can't be negative.\n");
451                 exit(1);
452         }
453         if (global_flags.max_input_queue_frames < 1) {
454                 fprintf(stderr, "ERROR: --max-input-queue-frames must be at least 1.\n");
455                 exit(1);
456         }
457         if (global_flags.max_input_queue_frames > 10) {
458                 fprintf(stderr, "WARNING: --max-input-queue-frames has little effect over 10.\n");
459         }
460 }