]> git.sesse.net Git - nageru/blob - nageru/flags.cpp
Implement SRT output.
[nageru] / 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_FULLSCREEN,
18         OPTION_MAX_NUM_CARDS,
19         OPTION_MULTICHANNEL,
20         OPTION_MIDI_MAPPING,
21         OPTION_DEFAULT_HDMI_INPUT,
22         OPTION_FAKE_CARDS_AUDIO,
23         OPTION_V4L_OUTPUT,
24         OPTION_HTTP_UNCOMPRESSED_VIDEO,
25         OPTION_HTTP_X264_VIDEO,
26         OPTION_HTTP_AV1_VIDEO,
27         OPTION_RECORD_X264_VIDEO,
28         OPTION_SEPARATE_X264_DISK_ENCODE,
29         OPTION_X264_PRESET,
30         OPTION_X264_TUNE,
31         OPTION_X264_SPEEDCONTROL,
32         OPTION_X264_SPEEDCONTROL_VERBOSE,
33         OPTION_X264_BITRATE,
34         OPTION_X264_CRF,
35         OPTION_X264_VBV_BUFSIZE,
36         OPTION_X264_VBV_MAX_BITRATE,
37         OPTION_X264_PARAM,
38         OPTION_X264_SEPARATE_DISK_PRESET,
39         OPTION_X264_SEPARATE_DISK_TUNE,
40         OPTION_X264_SEPARATE_DISK_BITRATE,
41         OPTION_X264_SEPARATE_DISK_CRF,
42         OPTION_X264_SEPARATE_DISK_PARAM,
43         OPTION_AV1_PRESET,
44         OPTION_AV1_BITRATE,
45         OPTION_AV1_FPS,
46         OPTION_AV1_PARAM,
47         OPTION_HTTP_MUX,
48         OPTION_HTTP_COARSE_TIMEBASE,
49         OPTION_HTTP_AUDIO_CODEC,
50         OPTION_HTTP_AUDIO_BITRATE,
51         OPTION_HTTP_PORT,
52         OPTION_SRT_PORT,
53         OPTION_NO_SRT,
54         OPTION_SRT_DESTINATION,
55         OPTION_SRT_STREAMID,
56         OPTION_SRT_PASSPHRASE,
57         OPTION_SRT_YOUTUBE_STREAM_KEY,
58         OPTION_SRT_LATENCY,
59         OPTION_NO_TRANSCODE_VIDEO,
60         OPTION_NO_TRANSCODE_AUDIO,
61         OPTION_DISABLE_AUDIO,
62         OPTION_FLAT_AUDIO,
63         OPTION_GAIN_STAGING,
64         OPTION_DISABLE_LOCUT,
65         OPTION_ENABLE_LOCUT,
66         OPTION_DISABLE_GAIN_STAGING_AUTO,
67         OPTION_ENABLE_GAIN_STAGING_AUTO,
68         OPTION_DISABLE_COMPRESSOR,
69         OPTION_ENABLE_COMPRESSOR,
70         OPTION_DISABLE_LIMITER,
71         OPTION_ENABLE_LIMITER,
72         OPTION_DISABLE_MAKEUP_GAIN_AUTO,
73         OPTION_ENABLE_MAKEUP_GAIN_AUTO,
74         OPTION_DISABLE_ALSA_OUTPUT,
75         OPTION_NO_FLUSH_PBOS,
76         OPTION_PRINT_VIDEO_LATENCY,
77         OPTION_MAX_INPUT_QUEUE_FRAMES,
78         OPTION_AUDIO_QUEUE_LENGTH_MS,
79         OPTION_OUTPUT_YCBCR_COEFFICIENTS,
80         OPTION_OUTPUT_BUFFER_FRAMES,
81         OPTION_OUTPUT_SLOP_FRAMES,
82         OPTION_OUTPUT_CARD_UNSYNCHRONIZED,
83         OPTION_TIMECODE_STREAM,
84         OPTION_TIMECODE_STDOUT,
85         OPTION_QUICK_CUT_KEYS,
86         OPTION_10_BIT,
87         OPTION_10_BIT_INPUT,
88         OPTION_10_BIT_OUTPUT,
89         OPTION_INPUT_YCBCR_INTERPRETATION,
90         OPTION_MJPEG_EXPORT_CARDS,
91 };
92
93 map<unsigned, unsigned> parse_mjpeg_export_cards(char *optarg)
94 {
95         map<unsigned, unsigned> ret;
96         if (optarg[0] == '\0') {
97                 return ret;
98         }
99
100         unsigned stream_idx = 0;
101         char *start = optarg;
102         for ( ;; ) {
103                 char *end = strchr(start, ',');
104                 if (end != nullptr) {
105                         *end = '\0';
106                 }
107
108                 unsigned range_begin, range_end;
109                 if (sscanf(start, "%u-%u", &range_begin, &range_end) != 2) {
110                         range_begin = range_end = atoi(start);
111                 }
112                 if (range_end < range_begin) {
113                         fprintf(stderr, "ERROR: Invalid range %u-%u in --mjpeg-export-cards=\n", range_begin, range_end);
114                         exit(1);
115                 }
116                 if (range_end >= unsigned(global_flags.max_num_cards)) {
117                         // There are situations where we could possibly want to
118                         // include FFmpeg inputs (CEF inputs are unlikely),
119                         // but they're not necessarily in 4:2:2 Y'CbCr, so it would
120                         // require more functionality the the JPEG encoder.
121                         fprintf(stderr, "ERROR: Asked for (zero-indexed) card %u in --mjpeg-export-cards=, but there are only %u cards\n",
122                                 range_end, global_flags.max_num_cards);
123                         exit(1);
124                 }
125                 for (unsigned card_idx = range_begin; card_idx <= range_end; ++card_idx) {
126                         if (ret.count(card_idx)) {
127                                 fprintf(stderr, "ERROR: Card %u was given twice in --mjpeg-export-cards=\n", card_idx);
128                                 exit(1);
129                         }
130                         ret[card_idx] = stream_idx++;
131                 }
132                 if (end == nullptr) {
133                         break;
134                 } else {
135                         start = end + 1;
136                 }
137         }
138         return ret;
139 }
140
141 void usage(Program program)
142 {
143         if (program == PROGRAM_KAERU) {
144                 fprintf(stderr, "Usage: kaeru [OPTION]... SOURCE_URL\n");
145         } else {
146                 fprintf(stderr, "Usage: nageru [OPTION]...\n");
147         }
148         fprintf(stderr, "\n");
149         fprintf(stderr, "      --help                      print usage information\n");
150         if (program == PROGRAM_NAGERU) {
151                 fprintf(stderr, "      --fullscreen                run in full screen, with no decorations\n");
152         }
153         fprintf(stderr, "  -w, --width                     output width in pixels (default 1280)\n");
154         fprintf(stderr, "  -h, --height                    output height in pixels (default 720)\n");
155         if (program == PROGRAM_NAGERU) {
156                 fprintf(stderr, "  -c, --num-cards                 set minimum number of input cards (default 2)\n");
157                 fprintf(stderr, "      --max-num-cards             set maximum number of input cards (default %d)\n", MAX_VIDEO_CARDS);
158                 fprintf(stderr, "  -o, --output-card=CARD          also output signal to the given card (default none)\n");
159                 fprintf(stderr, "  -t, --theme=FILE                choose theme (default theme.lua)\n");
160                 fprintf(stderr, "  -I, --theme-dir=DIR             search for theme in this directory (can be given multiple times)\n");
161                 fprintf(stderr, "  -r, --recording-dir=DIR         where to store disk recording\n");
162                 fprintf(stderr, "  -v, --va-display=SPEC           VA-API device for H.264 encoding\n");
163                 fprintf(stderr, "                                    ($DISPLAY spec or /dev/dri/render* path)\n");
164                 fprintf(stderr, "  -m, --map-signal=SIGNAL,CARD    set a default card mapping (can be given multiple times)\n");
165                 fprintf(stderr, "  -M, --input-mapping=FILE        start with the given audio input mapping (implies --multichannel)\n");
166                 fprintf(stderr, "      --multichannel              start in multichannel audio mapping mode\n");
167                 fprintf(stderr, "      --midi-mapping=FILE         start with the given MIDI controller mapping (implies --multichannel)\n");
168                 fprintf(stderr, "      --default-hdmi-input        default to HDMI over SDI inputs for cards that have both\n");
169                 fprintf(stderr, "      --fake-cards-audio          make fake (disconnected) cards output a simple tone\n");
170                 fprintf(stderr, "      --v4l-output=DEVICE         send video (no audio) to V4L2 output/loopback\n");
171                 fprintf(stderr, "      --http-x264-video           send x264-compressed video to HTTP clients\n");
172                 fprintf(stderr, "      --record-x264-video         store x264-compressed video to disk (implies --http-x264-video,\n");
173                 fprintf(stderr, "                                    removes the need for working VA-API encoding)\n");
174                 fprintf(stderr, "      --separate-x264-disk-encode run a different x264 encoder for disk recording\n");
175                 fprintf(stderr, "                                    (implies --record-x264-video)\n");
176         }
177         fprintf(stderr, "      --x264-preset               x264 quality preset (default " X264_DEFAULT_PRESET ")\n");
178         fprintf(stderr, "      --x264-tune                 x264 tuning (default " X264_DEFAULT_TUNE ", can be blank)\n");
179         fprintf(stderr, "      --x264-speedcontrol         try to match x264 preset to available CPU speed\n");
180         fprintf(stderr, "      --x264-bitrate              x264 bitrate (in kilobit/sec, default %d)\n",
181                 DEFAULT_X264_OUTPUT_BIT_RATE);
182         fprintf(stderr, "      --x264-crf=VALUE            quality-based VBR (-12 to 51), incompatible with --x264-bitrate\n");
183         fprintf(stderr, "      --x264-param=NAME[,VALUE]   set any x264 parameter, for fine tuning\n");
184         if (program == PROGRAM_NAGERU) {
185                 fprintf(stderr, "      --x264-separate-disk-preset x264 quality preset (default " X264_DEFAULT_PRESET ")\n");
186                 fprintf(stderr, "      --x264-separate-disk-tune   x264 tuning (default " X264_DEFAULT_TUNE ", can be blank)\n");
187                 fprintf(stderr, "      --x264-separate-disk-bitrate  x264 bitrate (in kilobit/sec, default %d)\n",
188                         DEFAULT_X264_OUTPUT_BIT_RATE);
189                 fprintf(stderr, "      --x264-separate-disk-crf=VALUE  quality-based VBR (-12 to 51), \n");
190                 fprintf(stderr, "                                  incompatible with --x264-separate-disk-bitrate\n");
191                 fprintf(stderr, "      --x264-separate-disk-param=NAME[,VALUE] set any x264 parameter, for fine tuning\n");
192         }
193 #ifdef HAVE_AV1
194         fprintf(stderr, "      --http-av1-video            send AV1-compressed video to HTTP clients and SRT output\n");
195         fprintf(stderr, "      --av1-preset                SVT-AV1 quality preset (default %d, from -2 to 13)\n",
196                 DEFAULT_AV1_PRESET);
197         fprintf(stderr, "      --av1-bitrate               AV1 bitrate (in kilobit/sec, default %d)\n",
198                 DEFAULT_AV1_OUTPUT_BIT_RATE);
199         fprintf(stderr, "      --av1-fps=NUM[/DEN]         AV1 encoded frame rate (default %d/%d)\n",
200                 DEFAULT_AV1_FPS_NUM, DEFAULT_AV1_FPS_DEN);
201         fprintf(stderr, "      --av1-param=NAME[,VALUE]    set any SVT-AV1 parameter, for fine tuning\n");
202 #endif
203         fprintf(stderr, "      --http-mux=NAME             mux to use for HTTP streams (default " DEFAULT_STREAM_MUX_NAME ")\n");
204         fprintf(stderr, "      --http-audio-codec=NAME     audio codec to use for HTTP streams and SRT output\n");
205         fprintf(stderr, "                                  (default is to use the same as for the recording)\n");
206         fprintf(stderr, "      --http-audio-bitrate=KBITS  audio codec bit rate to use for HTTP streams and SRT output\n");
207         fprintf(stderr, "                                  (default is %d, ignored unless --http-audio-codec is set)\n",
208                 DEFAULT_AUDIO_OUTPUT_BIT_RATE / 1000);
209         fprintf(stderr, "      --http-port=PORT            which port to use for the built-in HTTP server\n");
210         fprintf(stderr, "                                  (default is %d)\n", DEFAULT_HTTPD_PORT);
211 #ifdef HAVE_SRT
212         fprintf(stderr, "      --srt-port=PORT             which port to use for receiving SRT streams\n");
213         fprintf(stderr, "                                  (default is %d)\n", DEFAULT_SRT_PORT);
214         fprintf(stderr, "      --no-srt                    disable receiving SRT streams\n");
215 #endif
216         if (program == PROGRAM_KAERU) {
217                 fprintf(stderr, "      --no-transcode-video        copy encoded video raw from the source stream\n");
218                 fprintf(stderr, "                                    (experimental, must be H.264)\n");
219                 fprintf(stderr, "      --no-transcode-audio        copy encoded audio raw from the source stream\n");
220                 fprintf(stderr, "                                    (requires --http-audio-codec= to be set)\n");
221                 fprintf(stderr, "      --disable-audio             do not include any audio in the stream\n");
222         }
223         if (program == PROGRAM_NAGERU) {
224 #ifdef HAVE_SRT
225                 fprintf(stderr, "      --srt-destination=HOST:PORT  send HTTP video stream also to given destination\n");
226                 fprintf(stderr, "      --srt-streamid=STREAMID     SRT stream identifying ID\n");
227                 fprintf(stderr, "      --srt-passphrase=PASSPHRASE  SRT encryption key\n");
228                 fprintf(stderr, "      --srt-youtube-stream-key=KEY  shortcut for --srt-destination=a.srt.youtube.com:2010\n");
229                 fprintf(stderr, "                                    --srt-streamid=#!::u=<KEY>,copy=0,encoder=Nageru\n");
230                 fprintf(stderr, "      --srt-latency=MS            output SRT latency in milliseconds (default is %d)\n", DEFAULT_SRT_OUTPUT_LATENCY_MS);
231                 fprintf(stderr, "                                    --srt-streamid=#!::u=<KEY>,copy=0,encoder=Nageru\n");
232 #endif
233                 fprintf(stderr, "      --flat-audio                start with most audio processing turned off\n");
234                 fprintf(stderr, "                                    (can be overridden by e.g. --enable-limiter)\n");
235                 fprintf(stderr, "      --gain-staging=DB           set initial gain staging to the given value\n");
236                 fprintf(stderr, "                                    (--disable-gain-staging-auto)\n");
237                 fprintf(stderr, "      --disable-locut             turn off locut filter (also --enable)\n");
238                 fprintf(stderr, "      --disable-gain-staging-auto  turn off automatic gain staging (also --enable)\n");
239                 fprintf(stderr, "      --disable-compressor        turn off regular compressor (also --enable)\n");
240                 fprintf(stderr, "      --disable-limiter           turn off limiter (also --enable)\n");
241                 fprintf(stderr, "      --disable-makeup-gain-auto  turn off auto-adjustment of final makeup gain (also --enable)\n");
242                 fprintf(stderr, "      --disable-alsa-output       disable audio monitoring via ALSA\n");
243                 fprintf(stderr, "      --print-video-latency       print out measurements of video latency on stdout\n");
244                 fprintf(stderr, "      --max-input-queue-frames=FRAMES  never keep more than FRAMES frames for each card\n");
245                 fprintf(stderr, "                                    (default 6, minimum 1)\n");
246                 fprintf(stderr, "      --audio-queue-length-ms=MS  length of audio resampling queue (default 100.0)\n");
247                 fprintf(stderr, "      --output-ycbcr-coefficients={rec601,rec709,auto}\n");
248                 fprintf(stderr, "                                  Y'CbCr coefficient standard of output (default auto)\n");
249                 fprintf(stderr, "                                    auto is rec601, unless --output-card is used\n");
250                 fprintf(stderr, "                                    and a Rec. 709 mode (typically HD modes) is in use\n");
251                 fprintf(stderr, "      --output-buffer-frames=NUM  number of frames in output buffer for --output-card,\n");
252                 fprintf(stderr, "                                    can be fractional (default 6.0); note also\n");
253                 fprintf(stderr, "                                    the audio queue can't be much longer than this\n");
254                 fprintf(stderr, "      --output-slop-frames=NUM    if more less than this number of frames behind for\n");
255                 fprintf(stderr, "                                    --output-card, try to submit anyway instead of\n");
256                 fprintf(stderr, "                                    dropping the frame (default 0.5)\n");
257                 fprintf(stderr, "      --output-card-unsynchronized  if --output-card is in use, do _not_ use it as\n");
258                 fprintf(stderr, "                                  master clock (may give jittery output and audio breakups)\n");
259                 fprintf(stderr, "      --timecode-stream           show timestamp and timecode in stream\n");
260                 fprintf(stderr, "      --timecode-stdout           show timestamp and timecode on standard output\n");
261                 fprintf(stderr, "      --quick-cut-keys            enable direct cutting by Q, W, E, ... keys\n");
262                 fprintf(stderr, "      --10-bit                    use 10-bit color depth\n");
263                 fprintf(stderr, "      --input-ycbcr-interpretation=CARD,{rec601,rec709,auto}[,{limited,full}]\n");
264                 fprintf(stderr, "                                  Y'CbCr coefficient standard of card CARD (default auto)\n");
265                 fprintf(stderr, "                                    auto is rec601 for SD, rec709 for HD, always limited\n");
266                 fprintf(stderr, "                                    limited means standard 0-240/0-235 input range (for 8-bit)\n");
267                 fprintf(stderr, "      --mjpeg-export-cards=RANGE[,RANGE...]\n");
268                 fprintf(stderr, "                                  export the given cards in MJPEG format to /multicam.mp4,\n");
269                 fprintf(stderr, "                                    in the given order (ranges can be either single card indexes\n");
270                 fprintf(stderr, "                                    or pairs like 1-3 for camera 1,2,3; default is all cards)\n");
271         }
272 }
273
274 void parse_flags(Program program, int argc, char * const argv[])
275 {
276         static const option long_options[] = {
277                 { "help", no_argument, 0, OPTION_HELP },
278                 { "fullscreen", no_argument, 0, OPTION_FULLSCREEN },
279                 { "width", required_argument, 0, 'w' },
280                 { "height", required_argument, 0, 'h' },
281                 { "num-cards", required_argument, 0, 'c' },
282                 { "max-num-cards", required_argument, 0, OPTION_MAX_NUM_CARDS },
283                 { "output-card", required_argument, 0, 'o' },
284                 { "theme", required_argument, 0, 't' },
285                 { "theme-dir", required_argument, 0, 'I' },
286                 { "recording-dir", required_argument, 0, 'r' },
287                 { "map-signal", required_argument, 0, 'm' },
288                 { "input-mapping", required_argument, 0, 'M' },
289                 { "va-display", required_argument, 0, 'v' },
290                 { "multichannel", no_argument, 0, OPTION_MULTICHANNEL },
291                 { "midi-mapping", required_argument, 0, OPTION_MIDI_MAPPING },
292                 { "default-hdmi-input", no_argument, 0, OPTION_DEFAULT_HDMI_INPUT },
293                 { "fake-cards-audio", no_argument, 0, OPTION_FAKE_CARDS_AUDIO },
294                 { "v4l-output", required_argument, 0, OPTION_V4L_OUTPUT },
295                 { "http-x264-video", no_argument, 0, OPTION_HTTP_X264_VIDEO },
296                 { "record-x264-video", no_argument, 0, OPTION_RECORD_X264_VIDEO },
297                 { "separate-x264-disk-encode", no_argument, 0, OPTION_SEPARATE_X264_DISK_ENCODE },
298                 { "x264-preset", required_argument, 0, OPTION_X264_PRESET },
299                 { "x264-tune", required_argument, 0, OPTION_X264_TUNE },
300                 { "x264-speedcontrol", no_argument, 0, OPTION_X264_SPEEDCONTROL },
301                 { "x264-crf", required_argument, 0, OPTION_X264_CRF },
302                 { "x264-param", required_argument, 0, OPTION_X264_PARAM },
303                 { "x264-separate-disk-preset", required_argument, 0, OPTION_X264_SEPARATE_DISK_PRESET },
304                 { "x264-separate-disk-tune", required_argument, 0, OPTION_X264_SEPARATE_DISK_TUNE },
305                 { "x264-separate-disk-bitrate", required_argument, 0, OPTION_X264_SEPARATE_DISK_BITRATE },
306                 { "x264-separate-disk-crf", required_argument, 0, OPTION_X264_SEPARATE_DISK_CRF },
307                 { "x264-separate-disk-param", required_argument, 0, OPTION_X264_SEPARATE_DISK_PARAM },
308 #ifdef HAVE_AV1
309                 { "http-av1-video", no_argument, 0, OPTION_HTTP_AV1_VIDEO },
310                 { "av1-preset", required_argument, 0, OPTION_AV1_PRESET },
311                 { "av1-bitrate", required_argument, 0, OPTION_AV1_BITRATE },
312                 { "av1-fps", required_argument, 0, OPTION_AV1_FPS },
313                 { "av1-param", required_argument, 0, OPTION_AV1_PARAM },
314 #endif
315                 { "http-mux", required_argument, 0, OPTION_HTTP_MUX },
316                 { "http-audio-codec", required_argument, 0, OPTION_HTTP_AUDIO_CODEC },
317                 { "http-audio-bitrate", required_argument, 0, OPTION_HTTP_AUDIO_BITRATE },
318                 { "http-port", required_argument, 0, OPTION_HTTP_PORT },
319 #ifdef HAVE_SRT
320                 { "srt-port", required_argument, 0, OPTION_SRT_PORT },
321 #endif
322                 { "no-srt", no_argument, 0, OPTION_NO_SRT },  // We silently allow this even without HAVE_SRT.
323 #ifdef HAVE_SRT
324                 { "srt-destination", required_argument, 0, OPTION_SRT_DESTINATION },
325                 { "srt-streamid", required_argument, 0, OPTION_SRT_STREAMID },
326                 { "srt-passphrase", required_argument, 0, OPTION_SRT_PASSPHRASE },
327                 { "srt-youtube-stream-key", required_argument, 0, OPTION_SRT_YOUTUBE_STREAM_KEY },
328                 { "srt-latency", required_argument, 0, OPTION_SRT_LATENCY },
329 #endif
330                 { "no-transcode-video", no_argument, 0, OPTION_NO_TRANSCODE_VIDEO },
331                 { "no-transcode-audio", no_argument, 0, OPTION_NO_TRANSCODE_AUDIO },
332                 { "disable-audio", no_argument, 0, OPTION_DISABLE_AUDIO },
333                 { "flat-audio", no_argument, 0, OPTION_FLAT_AUDIO },
334                 { "gain-staging", required_argument, 0, OPTION_GAIN_STAGING },
335                 { "disable-locut", no_argument, 0, OPTION_DISABLE_LOCUT },
336                 { "enable-locut", no_argument, 0, OPTION_ENABLE_LOCUT },
337                 { "disable-gain-staging-auto", no_argument, 0, OPTION_DISABLE_GAIN_STAGING_AUTO },
338                 { "enable-gain-staging-auto", no_argument, 0, OPTION_ENABLE_GAIN_STAGING_AUTO },
339                 { "disable-compressor", no_argument, 0, OPTION_DISABLE_COMPRESSOR },
340                 { "enable-compressor", no_argument, 0, OPTION_ENABLE_COMPRESSOR },
341                 { "disable-limiter", no_argument, 0, OPTION_DISABLE_LIMITER },
342                 { "enable-limiter", no_argument, 0, OPTION_ENABLE_LIMITER },
343                 { "disable-makeup-gain-auto", no_argument, 0, OPTION_DISABLE_MAKEUP_GAIN_AUTO },
344                 { "enable-makeup-gain-auto", no_argument, 0, OPTION_ENABLE_MAKEUP_GAIN_AUTO },
345                 { "disable-alsa-output", no_argument, 0, OPTION_DISABLE_ALSA_OUTPUT },
346                 { "print-video-latency", no_argument, 0, OPTION_PRINT_VIDEO_LATENCY },
347                 { "max-input-queue-frames", required_argument, 0, OPTION_MAX_INPUT_QUEUE_FRAMES },
348                 { "audio-queue-length-ms", required_argument, 0, OPTION_AUDIO_QUEUE_LENGTH_MS },
349                 { "output-ycbcr-coefficients", required_argument, 0, OPTION_OUTPUT_YCBCR_COEFFICIENTS },
350                 { "output-buffer-frames", required_argument, 0, OPTION_OUTPUT_BUFFER_FRAMES },
351                 { "output-slop-frames", required_argument, 0, OPTION_OUTPUT_SLOP_FRAMES },
352                 { "output-card-unsynchronized", no_argument, 0, OPTION_OUTPUT_CARD_UNSYNCHRONIZED },
353                 { "timecode-stream", no_argument, 0, OPTION_TIMECODE_STREAM },
354                 { "timecode-stdout", no_argument, 0, OPTION_TIMECODE_STDOUT },
355                 { "quick-cut-keys", no_argument, 0, OPTION_QUICK_CUT_KEYS },
356                 { "10-bit", no_argument, 0, OPTION_10_BIT },
357                 { "input-ycbcr-interpretation", required_argument, 0, OPTION_INPUT_YCBCR_INTERPRETATION },
358                 { "mjpeg-export-cards", required_argument, 0, OPTION_MJPEG_EXPORT_CARDS },
359
360                 // Do not explicitly signal texture data uploads (will give
361                 // display corruption, but makes it possible to run with
362                 // apitrace in real time). For developers only, so undocumented.
363                 { "no-flush-pbos", no_argument, 0, OPTION_NO_FLUSH_PBOS },
364
365                 // Output speedcontrol debugging statistics. For developers only,
366                 // so undocumented (users can get this information from Prometheus
367                 // statistics, too).
368                 { "x264-speedcontrol-verbose", no_argument, 0, OPTION_X264_SPEEDCONTROL_VERBOSE },
369
370                 // Deprecated variants.
371                 { "10-bit-input", no_argument, 0, OPTION_10_BIT_INPUT },
372                 { "10-bit-output", no_argument, 0, OPTION_10_BIT_OUTPUT },
373
374                 { 0, 0, 0, 0 }
375         };
376         vector<string> theme_dirs;
377         string output_ycbcr_coefficients = "auto";
378         bool card_to_mjpeg_stream_export_set = false;
379         for ( ;; ) {
380                 int option_index = 0;
381                 int c = getopt_long(argc, argv, "c:o:t:I:r:v:m:M:w:h:", long_options, &option_index);
382
383                 if (c == -1) {
384                         break;
385                 }
386                 switch (c) {
387                 case 'w':
388                         global_flags.width = atoi(optarg);
389                         break;
390                 case 'h':
391                         global_flags.height = atoi(optarg);
392                         break;
393                 case 'c':
394                         global_flags.min_num_cards = atoi(optarg);
395                         break;
396                 case OPTION_MAX_NUM_CARDS:
397                         global_flags.max_num_cards = atoi(optarg);
398                         break;
399                 case 'o':
400                         global_flags.output_card = atoi(optarg);
401                         break;
402                 case 't':
403                         global_flags.theme_filename = optarg;
404                         break;
405                 case 'I':
406                         theme_dirs.push_back(optarg);
407                         break;
408                 case 'r':
409                         global_flags.recording_dir = optarg;
410                         break;
411                 case 'm': {
412                         char *ptr = strchr(optarg, ',');
413                         if (ptr == nullptr) {
414                                 fprintf(stderr, "ERROR: Invalid argument '%s' to --map-signal (needs a signal and a card number, separated by comma)\n", optarg);
415                                 exit(1);
416                         }
417                         *ptr = '\0';
418                         const int signal_num = atoi(optarg);
419                         const int card_num = atoi(ptr + 1);
420                         if (global_flags.default_stream_mapping.count(signal_num)) {
421                                 fprintf(stderr, "ERROR: Signal %d already mapped to card %d\n",
422                                         signal_num, global_flags.default_stream_mapping[signal_num]);
423                                 exit(1);
424                         }
425                         global_flags.default_stream_mapping[signal_num] = card_num;
426                         break;
427                 }
428                 case 'M':
429                         global_flags.input_mapping_filename = optarg;
430                         break;
431                 case OPTION_MULTICHANNEL:
432                         global_flags.multichannel_mapping_mode = true;
433                         break;
434                 case 'v':
435                         global_flags.va_display = optarg;
436                         break;
437                 case OPTION_MIDI_MAPPING:
438                         global_flags.midi_mapping_filename = optarg;
439                         global_flags.multichannel_mapping_mode = true;
440                         break;
441                 case OPTION_DEFAULT_HDMI_INPUT:
442                         global_flags.default_hdmi_input = true;
443                         break;
444                 case OPTION_FAKE_CARDS_AUDIO:
445                         global_flags.fake_cards_audio = true;
446                         break;
447                 case OPTION_V4L_OUTPUT:
448                         global_flags.v4l_output_device = optarg;
449                         break;
450                 case OPTION_HTTP_MUX:
451                         global_flags.stream_mux_name = optarg;
452                         break;
453                 case OPTION_HTTP_AUDIO_CODEC:
454                         global_flags.stream_audio_codec_name = optarg;
455                         break;
456                 case OPTION_HTTP_AUDIO_BITRATE:
457                         global_flags.stream_audio_codec_bitrate = atoi(optarg) * 1000;
458                         break;
459                 case OPTION_HTTP_PORT:
460                         global_flags.http_port = atoi(optarg);
461                         break;
462 #ifdef HAVE_SRT
463                 case OPTION_SRT_PORT:
464                         global_flags.srt_port = atoi(optarg);
465                         break;
466 #endif
467                 case OPTION_NO_SRT:
468                         global_flags.srt_port = -1;
469                         break;
470 #ifdef HAVE_SRT
471                 case OPTION_SRT_DESTINATION: {
472                         const char *ptr = strrchr(optarg, ':');
473                         if (ptr == nullptr || strlen(optarg) < 3) {
474                                 fprintf(stderr, "ERROR: --srt-destination must be of the form host:port\n");
475                                 exit(1);
476                         }
477                         global_flags.srt_destination_host = string(optarg, ptr - optarg);
478                         if (global_flags.srt_destination_host[0] == '[' &&
479                             global_flags.srt_destination_host.back() == ']') {
480                                 // Support [IPv6]:port, in a sort of hackish way.
481                                 global_flags.srt_destination_host = global_flags.srt_destination_host.substr(1, global_flags.srt_destination_host.size() - 2);
482                         }
483                         global_flags.srt_destination_port = ptr + 1;
484                         break;
485                 }
486                 case OPTION_SRT_STREAMID:
487                         global_flags.srt_streamid = optarg;
488                         break;
489                 case OPTION_SRT_PASSPHRASE:
490                         global_flags.srt_passphrase = optarg;
491                         break;
492                 case OPTION_SRT_YOUTUBE_STREAM_KEY:
493                         global_flags.srt_destination_host = "a.srt.youtube.com";
494                         global_flags.srt_destination_port = "2010";
495                         global_flags.srt_streamid = string("#!::u=") + optarg + ",copy=0,encoder=Nageru " NAGERU_VERSION;
496                         break;
497                 case OPTION_SRT_LATENCY:
498                         global_flags.srt_output_latency = atoi(optarg);
499                         break;
500 #endif
501                 case OPTION_NO_TRANSCODE_VIDEO:
502                         global_flags.transcode_video = false;
503                         break;
504                 case OPTION_NO_TRANSCODE_AUDIO:
505                         global_flags.transcode_audio = false;
506                         break;
507                 case OPTION_DISABLE_AUDIO:
508                         global_flags.transcode_audio = false;
509                         global_flags.enable_audio = false;
510                         break;
511                 case OPTION_HTTP_X264_VIDEO:
512                         global_flags.x264_video_to_http = true;
513                         break;
514                 case OPTION_RECORD_X264_VIDEO:
515                         global_flags.x264_video_to_disk = true;
516                         break;
517                 case OPTION_SEPARATE_X264_DISK_ENCODE:
518                         global_flags.x264_video_to_disk = true;
519                         global_flags.x264_video_to_http = true;
520                         global_flags.x264_separate_disk_encode = true;
521                         break;
522                 case OPTION_HTTP_AV1_VIDEO:
523                         global_flags.av1_video_to_http = true;
524                         break;
525                 case OPTION_X264_PRESET:
526                         global_flags.x264_preset = optarg;
527                         break;
528                 case OPTION_X264_TUNE:
529                         global_flags.x264_tune = optarg;
530                         break;
531                 case OPTION_X264_SPEEDCONTROL:
532                         global_flags.x264_speedcontrol = true;
533                         break;
534                 case OPTION_X264_SPEEDCONTROL_VERBOSE:
535                         global_flags.x264_speedcontrol_verbose = true;
536                         break;
537                 case OPTION_X264_BITRATE:
538                         global_flags.x264_bitrate = atoi(optarg);
539                         break;
540                 case OPTION_X264_CRF:
541                         global_flags.x264_crf = atof(optarg);
542                         break;
543                 case OPTION_X264_PARAM:
544                         global_flags.x264_extra_param.push_back(optarg);
545                         break;
546                 case OPTION_X264_SEPARATE_DISK_PRESET:
547                         global_flags.x264_separate_disk_preset = optarg;
548                         break;
549                 case OPTION_X264_SEPARATE_DISK_TUNE:
550                         global_flags.x264_separate_disk_tune = optarg;
551                         break;
552                 case OPTION_X264_SEPARATE_DISK_BITRATE:
553                         global_flags.x264_separate_disk_bitrate = atoi(optarg);
554                         break;
555                 case OPTION_X264_SEPARATE_DISK_CRF:
556                         global_flags.x264_separate_disk_crf = atof(optarg);
557                         break;
558                 case OPTION_X264_SEPARATE_DISK_PARAM:
559                         global_flags.x264_separate_disk_extra_param.push_back(optarg);
560                         break;
561                 case OPTION_AV1_PRESET:
562                         global_flags.av1_preset = atoi(optarg);
563                         break;
564                 case OPTION_AV1_BITRATE:
565                         global_flags.av1_bitrate = atoi(optarg);
566                         break;
567                 case OPTION_AV1_FPS: {
568                         string str = optarg;
569                         const size_t pos = str.find('/');
570                         if (pos == string::npos) {
571                                 global_flags.av1_fps_num = stoi(str);
572                                 global_flags.av1_fps_den = 1;
573                         } else {
574                                 const string num = str.substr(0, pos);
575                                 const string den = str.substr(pos + 1);
576                                 global_flags.av1_fps_num = stoi(num);
577                                 global_flags.av1_fps_den = stoi(den);
578                         }
579                         break;
580                 }
581                 case OPTION_AV1_PARAM:
582                         global_flags.av1_extra_param.push_back(optarg);
583                         break;
584                 case OPTION_FLAT_AUDIO:
585                         // If --flat-audio is given, turn off everything that messes with the sound,
586                         // except the final makeup gain.
587                         global_flags.locut_enabled = false;
588                         global_flags.gain_staging_auto = false;
589                         global_flags.compressor_enabled = false;
590                         global_flags.limiter_enabled = false;
591                         break;
592                 case OPTION_GAIN_STAGING:
593                         global_flags.initial_gain_staging_db = atof(optarg);
594                         global_flags.gain_staging_auto = false;
595                         break;
596                 case OPTION_DISABLE_LOCUT:
597                         global_flags.locut_enabled = false;
598                         break;
599                 case OPTION_ENABLE_LOCUT:
600                         global_flags.locut_enabled = true;
601                         break;
602                 case OPTION_DISABLE_GAIN_STAGING_AUTO:
603                         global_flags.gain_staging_auto = false;
604                         break;
605                 case OPTION_ENABLE_GAIN_STAGING_AUTO:
606                         global_flags.gain_staging_auto = true;
607                         break;
608                 case OPTION_DISABLE_COMPRESSOR:
609                         global_flags.compressor_enabled = false;
610                         break;
611                 case OPTION_ENABLE_COMPRESSOR:
612                         global_flags.compressor_enabled = true;
613                         break;
614                 case OPTION_DISABLE_LIMITER:
615                         global_flags.limiter_enabled = false;
616                         break;
617                 case OPTION_ENABLE_LIMITER:
618                         global_flags.limiter_enabled = true;
619                         break;
620                 case OPTION_DISABLE_MAKEUP_GAIN_AUTO:
621                         global_flags.final_makeup_gain_auto = false;
622                         break;
623                 case OPTION_ENABLE_MAKEUP_GAIN_AUTO:
624                         global_flags.final_makeup_gain_auto = true;
625                         break;
626                 case OPTION_DISABLE_ALSA_OUTPUT:
627                         global_flags.enable_alsa_output = false;
628                         break;
629                 case OPTION_NO_FLUSH_PBOS:
630                         global_flags.flush_pbos = false;
631                         break;
632                 case OPTION_PRINT_VIDEO_LATENCY:
633                         global_flags.print_video_latency = true;
634                         break;
635                 case OPTION_MAX_INPUT_QUEUE_FRAMES:
636                         global_flags.max_input_queue_frames = atoi(optarg);
637                         break;
638                 case OPTION_AUDIO_QUEUE_LENGTH_MS:
639                         global_flags.audio_queue_length_ms = atof(optarg);
640                         break;
641                 case OPTION_OUTPUT_YCBCR_COEFFICIENTS:
642                         output_ycbcr_coefficients = optarg;
643                         break;
644                 case OPTION_OUTPUT_BUFFER_FRAMES:
645                         global_flags.output_buffer_frames = atof(optarg);
646                         break;
647                 case OPTION_OUTPUT_SLOP_FRAMES:
648                         global_flags.output_slop_frames = atof(optarg);
649                         break;
650                 case OPTION_OUTPUT_CARD_UNSYNCHRONIZED:
651                         global_flags.output_card_is_master = false;
652                         break;
653                 case OPTION_TIMECODE_STREAM:
654                         global_flags.display_timecode_in_stream = true;
655                         break;
656                 case OPTION_TIMECODE_STDOUT:
657                         global_flags.display_timecode_on_stdout = true;
658                         break;
659                 case OPTION_QUICK_CUT_KEYS:
660                         global_flags.enable_quick_cut_keys = true;
661                         break;
662                 case OPTION_10_BIT_INPUT:
663                         fprintf(stderr, "NOTE: --10-bit-input is a deprecated alias for --10-bit.\n");
664                         global_flags.bit_depth = 10;
665                         break;
666                 case OPTION_10_BIT_OUTPUT:
667                         fprintf(stderr, "NOTE: --10-bit-output is a deprecated alias for --10-bit.\n");
668                         global_flags.bit_depth = 10;
669                         break;
670                 case OPTION_10_BIT:
671                         global_flags.bit_depth = 10;
672                         break;
673                 case OPTION_INPUT_YCBCR_INTERPRETATION: {
674                         char *ptr = strchr(optarg, ',');
675                         if (ptr == nullptr) {
676                                 fprintf(stderr, "ERROR: Invalid argument '%s' to --input-ycbcr-interpretation (needs a card and an interpretation, separated by comma)\n", optarg);
677                                 exit(1);
678                         }
679                         *ptr = '\0';
680                         const int card_num = atoi(optarg);
681                         if (card_num < 0 || card_num >= MAX_VIDEO_CARDS) {
682                                 fprintf(stderr, "ERROR: Invalid card number %d\n", card_num);
683                                 exit(1);
684                         }
685
686                         YCbCrInterpretation interpretation;
687                         char *interpretation_str = ptr + 1;
688                         ptr = strchr(interpretation_str, ',');
689                         if (ptr != nullptr) {
690                                 *ptr = '\0';
691                                 const char *range = ptr + 1;
692                                 if (strcmp(range, "full") == 0) {
693                                         interpretation.full_range = true;
694                                 } else if (strcmp(range, "limited") == 0) {
695                                         interpretation.full_range = false;
696                                 } else {
697                                         fprintf(stderr, "ERROR: Invalid Y'CbCr range '%s' (must be “full” or “limited”)\n", range);
698                                         exit(1);
699                                 }
700                         }
701
702                         if (strcmp(interpretation_str, "rec601") == 0) {
703                                 interpretation.ycbcr_coefficients_auto = false;
704                                 interpretation.ycbcr_coefficients = movit::YCBCR_REC_601;
705                         } else if (strcmp(interpretation_str, "rec709") == 0) {
706                                 interpretation.ycbcr_coefficients_auto = false;
707                                 interpretation.ycbcr_coefficients = movit::YCBCR_REC_709;
708                         } else if (strcmp(interpretation_str, "auto") == 0) {
709                                 interpretation.ycbcr_coefficients_auto = true;
710                                 if (interpretation.full_range) {
711                                         fprintf(stderr, "ERROR: Cannot use “auto” Y'CbCr coefficients with full range\n");
712                                         exit(1);
713                                 }
714                         } else {
715                                 fprintf(stderr, "ERROR: Invalid Y'CbCr coefficients '%s' (must be “rec601”, “rec709” or “auto”)\n", interpretation_str);
716                                 exit(1);
717                         }
718                         global_flags.ycbcr_interpretation[card_num] = interpretation;
719                         break;
720                 }
721                 case OPTION_FULLSCREEN:
722                         global_flags.fullscreen = true;
723                         break;
724                 case OPTION_MJPEG_EXPORT_CARDS: {
725                         if (card_to_mjpeg_stream_export_set) {
726                                 fprintf(stderr, "ERROR: --mjpeg-export-cards given twice\n");
727                                 exit(1);
728                         }
729                         global_flags.card_to_mjpeg_stream_export = parse_mjpeg_export_cards(optarg);    
730                         card_to_mjpeg_stream_export_set = true;
731                         break;
732                 }
733                 case OPTION_HELP:
734                         usage(program);
735                         exit(0);
736                 default:
737                         fprintf(stderr, "Unknown option '%s'\n", argv[option_index]);
738                         fprintf(stderr, "\n");
739                         usage(program);
740                         exit(1);
741                 }
742         }
743
744         if (global_flags.x264_video_to_http +
745             global_flags.av1_video_to_http > 1) {
746                 fprintf(stderr, "ERROR: --http-{x264,av1}-video are mutually incompatible\n");
747                 exit(1);
748         }
749         if (global_flags.bit_depth == 10) {
750                 global_flags.x264_video_to_disk = true;  // No 10-bit Quick Sync support.
751                 if (!global_flags.av1_video_to_http) {
752                         global_flags.x264_video_to_http = true;
753                 }
754         }
755         if (global_flags.x264_video_to_disk && !global_flags.av1_video_to_http) {
756                 global_flags.x264_video_to_http = true;  // Quick Sync to HTTP but x264 to disk doesn't make sense.
757         }
758         if (global_flags.min_num_cards <= 0) {
759                 fprintf(stderr, "ERROR: --num-cards must be at least 1\n");
760                 exit(1);
761         }
762         if (global_flags.max_num_cards <= 0) {
763                 fprintf(stderr, "ERROR: --max-num-cards must be at least 1\n");
764                 exit(1);
765         }
766         if (global_flags.max_num_cards < global_flags.min_num_cards) {
767                 fprintf(stderr, "ERROR: --max-num-cards can not be lower than --num-cards\n");
768                 exit(1);
769         }
770         if (global_flags.output_card < -1 ||
771             global_flags.output_card >= global_flags.max_num_cards) {
772                 fprintf(stderr, "ERROR: --output-card points to a nonexistant card\n");
773                 exit(1);
774         }
775         if (global_flags.enable_audio && !global_flags.transcode_audio && global_flags.stream_audio_codec_name.empty()) {
776                 fprintf(stderr, "ERROR: If not transcoding audio, you must specify ahead-of-time what audio codec is in use\n");
777                 fprintf(stderr, "       (using --http-audio-codec).\n");
778                 exit(1);
779         }
780         if (global_flags.x264_speedcontrol) {
781                 if (!global_flags.x264_preset.empty() && global_flags.x264_preset != "faster") {
782                         fprintf(stderr, "WARNING: --x264-preset is overridden by --x264-speedcontrol (implicitly uses \"faster\" as base preset)\n");
783                 }
784                 global_flags.x264_preset = "faster";
785         } else if (global_flags.x264_preset.empty()) {
786                 global_flags.x264_preset = X264_DEFAULT_PRESET;
787         }
788         if (global_flags.x264_separate_disk_preset.empty()) {
789                 global_flags.x264_separate_disk_preset = X264_DEFAULT_PRESET;
790         }
791         if (!theme_dirs.empty()) {
792                 global_flags.theme_dirs = theme_dirs;
793         }
794
795         // In reality, we could probably do with any even value (we subsample
796         // by two in some places), but it's better to be on the safe side
797         // wrt. video codecs and such. (I'd set 16 if I could, but 1080 isn't
798         // divisible by 16.)
799         if (global_flags.width <= 0 || (global_flags.width % 8) != 0 ||
800             global_flags.height <= 0 || (global_flags.height % 8) != 0) {
801                 fprintf(stderr, "ERROR: --width and --height must be positive integers divisible by 8\n");
802                 exit(1);
803         }
804
805         for (pair<int, int> mapping : global_flags.default_stream_mapping) {
806                 if (mapping.second >= global_flags.max_num_cards) {
807                         fprintf(stderr, "ERROR: Signal %d mapped to card %d, which doesn't exist (try adjusting --max-num-cards)\n",
808                                 mapping.first, mapping.second);
809                         exit(1);
810                 }
811         }
812
813         // Rec. 709 would be the sane thing to do, but it seems many players
814         // just default to BT.601 coefficients no matter what. We _do_ set
815         // the right flags, so that a player that works properly doesn't have
816         // to guess, but it's frequently ignored. See discussions
817         // in e.g. https://trac.ffmpeg.org/ticket/4978; the situation with
818         // browsers is complicated and depends on things like hardware acceleration
819         // (https://bugs.chromium.org/p/chromium/issues/detail?id=333619 for
820         // extensive discussion). VLC generally fixed this as part of 3.0.0
821         // (see e.g. https://github.com/videolan/vlc/commit/bc71288b2e38c07d6921472824b92eef1aa85f7e
822         // and https://github.com/videolan/vlc/commit/c3fc2683a9cde1d42674ebf9935dced05733a215),
823         // but earlier versions were pretty random.
824         //
825         // On the other hand, HDMI/SDI output typically requires Rec. 709 for
826         // HD resolutions (with no way of signaling anything else), which is
827         // a conflicting demand. In this case, we typically let the HDMI/SDI
828         // output win if it is active, but the user can override this.
829         if (output_ycbcr_coefficients == "auto") {
830                 // Essentially: BT.709 if HDMI/SDI output is on, otherwise BT.601.
831                 global_flags.ycbcr_rec709_coefficients = false;
832                 global_flags.ycbcr_auto_coefficients = true;
833         } else if (output_ycbcr_coefficients == "rec709") {
834                 global_flags.ycbcr_rec709_coefficients = true;
835                 global_flags.ycbcr_auto_coefficients = false;
836         } else if (output_ycbcr_coefficients == "rec601") {
837                 global_flags.ycbcr_rec709_coefficients = false;
838                 global_flags.ycbcr_auto_coefficients = false;
839         } else {
840                 fprintf(stderr, "ERROR: --output-ycbcr-coefficients must be “rec601”, “rec709” or “auto”\n");
841                 exit(1);
842         }
843
844         if (global_flags.output_buffer_frames < 0.0f) {
845                 // Actually, even zero probably won't make sense; there is some internal
846                 // delay to the card.
847                 fprintf(stderr, "ERROR: --output-buffer-frames can't be negative.\n");
848                 exit(1);
849         }
850         if (global_flags.output_slop_frames < 0.0f) {
851                 fprintf(stderr, "ERROR: --output-slop-frames can't be negative.\n");
852                 exit(1);
853         }
854         if (global_flags.max_input_queue_frames < 1) {
855                 fprintf(stderr, "ERROR: --max-input-queue-frames must be at least 1.\n");
856                 exit(1);
857         }
858         if (global_flags.max_input_queue_frames > 10) {
859                 fprintf(stderr, "WARNING: --max-input-queue-frames has little effect over 10.\n");
860         }
861
862         if (!isinf(global_flags.x264_crf)) {  // CRF mode is selected.
863                 if (global_flags.x264_bitrate != -1) {
864                         fprintf(stderr, "ERROR: --x264-bitrate and --x264-crf are mutually incompatible.\n");
865                         exit(1);
866                 }
867         } else if (global_flags.x264_bitrate == -1) {
868                 global_flags.x264_bitrate = DEFAULT_X264_OUTPUT_BIT_RATE;
869         }
870
871         if (!isinf(global_flags.x264_separate_disk_crf)) {  // CRF mode is selected.
872                 if (global_flags.x264_separate_disk_bitrate != -1) {
873                         fprintf(stderr, "ERROR: --x264-separate-disk-bitrate and --x264-separate-disk-crf are mutually incompatible.\n");
874                         exit(1);
875                 }
876         } else if (global_flags.x264_separate_disk_bitrate == -1) {
877                 global_flags.x264_separate_disk_bitrate = DEFAULT_X264_OUTPUT_BIT_RATE;
878         }
879
880         if (!card_to_mjpeg_stream_export_set) {
881                 // Fill in the default mapping (export all cards, in order).
882                 for (unsigned card_idx = 0; card_idx < unsigned(global_flags.max_num_cards); ++card_idx) {
883                         global_flags.card_to_mjpeg_stream_export[card_idx] = card_idx;
884                 }
885         }
886
887         if (global_flags.srt_destination_host == "a.srt.youtube.com" && global_flags.srt_passphrase.empty()) {
888                 fprintf(stderr, "ERROR: Cannot stream to YouTube without --srt-passphrase (get it from the YouTube streaming console)\n");
889                 exit(1);
890         }
891 }