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