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