14 // Long options that have no corresponding short option.
20 OPTION_DEFAULT_HDMI_INPUT,
21 OPTION_FAKE_CARDS_AUDIO,
23 OPTION_HTTP_UNCOMPRESSED_VIDEO,
24 OPTION_HTTP_X264_VIDEO,
25 OPTION_RECORD_X264_VIDEO,
28 OPTION_X264_SPEEDCONTROL,
29 OPTION_X264_SPEEDCONTROL_VERBOSE,
32 OPTION_X264_VBV_BUFSIZE,
33 OPTION_X264_VBV_MAX_BITRATE,
36 OPTION_HTTP_COARSE_TIMEBASE,
37 OPTION_HTTP_AUDIO_CODEC,
38 OPTION_HTTP_AUDIO_BITRATE,
42 OPTION_NO_TRANSCODE_AUDIO,
48 OPTION_DISABLE_GAIN_STAGING_AUTO,
49 OPTION_ENABLE_GAIN_STAGING_AUTO,
50 OPTION_DISABLE_COMPRESSOR,
51 OPTION_ENABLE_COMPRESSOR,
52 OPTION_DISABLE_LIMITER,
53 OPTION_ENABLE_LIMITER,
54 OPTION_DISABLE_MAKEUP_GAIN_AUTO,
55 OPTION_ENABLE_MAKEUP_GAIN_AUTO,
56 OPTION_DISABLE_ALSA_OUTPUT,
58 OPTION_PRINT_VIDEO_LATENCY,
59 OPTION_MAX_INPUT_QUEUE_FRAMES,
60 OPTION_AUDIO_QUEUE_LENGTH_MS,
61 OPTION_OUTPUT_YCBCR_COEFFICIENTS,
62 OPTION_OUTPUT_BUFFER_FRAMES,
63 OPTION_OUTPUT_SLOP_FRAMES,
64 OPTION_TIMECODE_STREAM,
65 OPTION_TIMECODE_STDOUT,
66 OPTION_QUICK_CUT_KEYS,
69 OPTION_INPUT_YCBCR_INTERPRETATION,
70 OPTION_MJPEG_EXPORT_CARDS,
73 map<unsigned, unsigned> parse_mjpeg_export_cards(char *optarg)
75 map<unsigned, unsigned> ret;
76 if (optarg[0] == '\0') {
80 unsigned stream_idx = 0;
83 char *end = strchr(start, ',');
88 unsigned range_begin, range_end;
89 if (sscanf(start, "%u-%u", &range_begin, &range_end) != 2) {
90 range_begin = range_end = atoi(start);
92 if (range_end < range_begin) {
93 fprintf(stderr, "ERROR: Invalid range %u-%u in --mjpeg-export-cards=\n", range_begin, range_end);
96 if (range_end >= unsigned(global_flags.num_cards)) {
97 // There are situations where we could possibly want to
98 // include FFmpeg inputs (CEF inputs are unlikely),
99 // but they're not necessarily in 4:2:2 Y'CbCr, so it would
100 // require more functionality the the JPEG encoder.
101 fprintf(stderr, "ERROR: Asked for (zero-indexed) card %u in --mjpeg-export-cards=, but there are only %u cards\n",
102 range_end, global_flags.num_cards);
105 for (unsigned card_idx = range_begin; card_idx <= range_end; ++card_idx) {
106 if (ret.count(card_idx)) {
107 fprintf(stderr, "ERROR: Card %u was given twice in --mjpeg-export-cards=\n", card_idx);
110 ret[card_idx] = stream_idx++;
112 if (end == nullptr) {
121 void usage(Program program)
123 if (program == PROGRAM_KAERU) {
124 fprintf(stderr, "Usage: kaeru [OPTION]... SOURCE_URL\n");
126 fprintf(stderr, "Usage: nageru [OPTION]...\n");
128 fprintf(stderr, "\n");
129 fprintf(stderr, " --help print usage information\n");
130 if (program == PROGRAM_NAGERU) {
131 fprintf(stderr, " --fullscreen run in full screen, with no decorations\n");
133 fprintf(stderr, " -w, --width output width in pixels (default 1280)\n");
134 fprintf(stderr, " -h, --height output height in pixels (default 720)\n");
135 if (program == PROGRAM_NAGERU) {
136 fprintf(stderr, " -c, --num-cards set number of input cards (default 2)\n");
137 fprintf(stderr, " -o, --output-card=CARD also output signal to the given card (default none)\n");
138 fprintf(stderr, " -t, --theme=FILE choose theme (default theme.lua)\n");
139 fprintf(stderr, " -I, --theme-dir=DIR search for theme in this directory (can be given multiple times)\n");
140 fprintf(stderr, " -r, --recording-dir=DIR where to store disk recording\n");
141 fprintf(stderr, " -v, --va-display=SPEC VA-API device for H.264 encoding\n");
142 fprintf(stderr, " ($DISPLAY spec or /dev/dri/render* path)\n");
143 fprintf(stderr, " -m, --map-signal=SIGNAL,CARD set a default card mapping (can be given multiple times)\n");
144 fprintf(stderr, " -M, --input-mapping=FILE start with the given audio input mapping (implies --multichannel)\n");
145 fprintf(stderr, " --multichannel start in multichannel audio mapping mode\n");
146 fprintf(stderr, " --midi-mapping=FILE start with the given MIDI controller mapping (implies --multichannel)\n");
147 fprintf(stderr, " --default-hdmi-input default to HDMI over SDI inputs for cards that have both\n");
148 fprintf(stderr, " --fake-cards-audio make fake (disconnected) cards output a simple tone\n");
149 fprintf(stderr, " --v4l-output DEVICE send video (no audio) to V4L2 output/loopback\n");
150 fprintf(stderr, " --http-uncompressed-video send uncompressed NV12 video to HTTP clients\n");
151 fprintf(stderr, " --http-x264-video send x264-compressed video to HTTP clients\n");
152 fprintf(stderr, " --record-x264-video store x264-compressed video to disk (implies --http-x264-video,\n");
153 fprintf(stderr, " removes the need for working VA-API encoding)\n");
155 fprintf(stderr, " --x264-preset x264 quality preset (default " X264_DEFAULT_PRESET ")\n");
156 fprintf(stderr, " --x264-tune x264 tuning (default " X264_DEFAULT_TUNE ", can be blank)\n");
157 fprintf(stderr, " --x264-speedcontrol try to match x264 preset to available CPU speed\n");
158 fprintf(stderr, " --x264-speedcontrol-verbose output speedcontrol debugging statistics\n");
159 fprintf(stderr, " --x264-bitrate x264 bitrate (in kilobit/sec, default %d)\n",
160 DEFAULT_X264_OUTPUT_BIT_RATE);
161 fprintf(stderr, " --x264-crf=VALUE quality-based VBR (-12 to 51), incompatible with --x264-bitrate and VBV\n");
162 fprintf(stderr, " --x264-vbv-bufsize x264 VBV size (in kilobits, 0 = one-frame VBV,\n");
163 fprintf(stderr, " default: same as --x264-bitrate, that is, one-second VBV)\n");
164 fprintf(stderr, " --x264-vbv-max-bitrate x264 local max bitrate (in kilobit/sec per --vbv-bufsize,\n");
165 fprintf(stderr, " 0 = no limit, default: same as --x264-bitrate, i.e., CBR)\n");
166 fprintf(stderr, " --x264-param=NAME[,VALUE] set any x264 parameter, for fine tuning\n");
167 fprintf(stderr, " --http-mux=NAME mux to use for HTTP streams (default " DEFAULT_STREAM_MUX_NAME ")\n");
168 fprintf(stderr, " --http-audio-codec=NAME audio codec to use for HTTP streams\n");
169 fprintf(stderr, " (default is to use the same as for the recording)\n");
170 fprintf(stderr, " --http-audio-bitrate=KBITS audio codec bit rate to use for HTTP streams\n");
171 fprintf(stderr, " (default is %d, ignored unless --http-audio-codec is set)\n",
172 DEFAULT_AUDIO_OUTPUT_BIT_RATE / 1000);
173 fprintf(stderr, " --http-port=PORT which port to use for the built-in HTTP server\n");
174 fprintf(stderr, " (default is %d)\n", DEFAULT_HTTPD_PORT);
175 fprintf(stderr, " --srt-port=PORT which port to use for receiving SRT streams\n");
176 fprintf(stderr, " (default is %d)\n", DEFAULT_SRT_PORT);
177 fprintf(stderr, " --no-srt disable receiving SRT streams\n");
178 if (program == PROGRAM_KAERU) {
179 fprintf(stderr, " --no-transcode-audio copy encoded audio raw from the source stream\n");
180 fprintf(stderr, " (requires --http-audio-codec= to be set)\n");
181 fprintf(stderr, " --disable-audio do not include any audio in the stream\n");
183 if (program == PROGRAM_NAGERU) {
184 fprintf(stderr, " --flat-audio start with most audio processing turned off\n");
185 fprintf(stderr, " (can be overridden by e.g. --enable-limiter)\n");
186 fprintf(stderr, " --gain-staging=DB set initial gain staging to the given value\n");
187 fprintf(stderr, " (--disable-gain-staging-auto)\n");
188 fprintf(stderr, " --disable-locut turn off locut filter (also --enable)\n");
189 fprintf(stderr, " --disable-gain-staging-auto turn off automatic gain staging (also --enable)\n");
190 fprintf(stderr, " --disable-compressor turn off regular compressor (also --enable)\n");
191 fprintf(stderr, " --disable-limiter turn off limiter (also --enable)\n");
192 fprintf(stderr, " --disable-makeup-gain-auto turn off auto-adjustment of final makeup gain (also --enable)\n");
193 fprintf(stderr, " --disable-alsa-output disable audio monitoring via ALSA\n");
194 fprintf(stderr, " --no-flush-pbos do not explicitly signal texture data uploads\n");
195 fprintf(stderr, " (will give display corruption, but makes it\n");
196 fprintf(stderr, " possible to run with apitrace in real time)\n");
197 fprintf(stderr, " --print-video-latency print out measurements of video latency on stdout\n");
198 fprintf(stderr, " --max-input-queue-frames=FRAMES never keep more than FRAMES frames for each card\n");
199 fprintf(stderr, " (default 6, minimum 1)\n");
200 fprintf(stderr, " --audio-queue-length-ms=MS length of audio resampling queue (default 100.0)\n");
201 fprintf(stderr, " --output-ycbcr-coefficients={rec601,rec709,auto}\n");
202 fprintf(stderr, " Y'CbCr coefficient standard of output (default auto)\n");
203 fprintf(stderr, " auto is rec601, unless --output-card is used\n");
204 fprintf(stderr, " and a Rec. 709 mode (typically HD modes) is in use\n");
205 fprintf(stderr, " --output-buffer-frames=NUM number of frames in output buffer for --output-card,\n");
206 fprintf(stderr, " can be fractional (default 6.0); note also\n");
207 fprintf(stderr, " the audio queue can't be much longer than this\n");
208 fprintf(stderr, " --output-slop-frames=NUM if more less than this number of frames behind for\n");
209 fprintf(stderr, " --output-card, try to submit anyway instead of\n");
210 fprintf(stderr, " dropping the frame (default 0.5)\n");
211 fprintf(stderr, " --timecode-stream show timestamp and timecode in stream\n");
212 fprintf(stderr, " --timecode-stdout show timestamp and timecode on standard output\n");
213 fprintf(stderr, " --quick-cut-keys enable direct cutting by Q, W, E, ... keys\n");
214 fprintf(stderr, " --10-bit-input use 10-bit video input (requires compute shaders)\n");
215 fprintf(stderr, " --10-bit-output use 10-bit video output (requires compute shaders,\n");
216 fprintf(stderr, " implies --record-x264-video)\n");
217 fprintf(stderr, " --input-ycbcr-interpretation=CARD,{rec601,rec709,auto}[,{limited,full}]\n");
218 fprintf(stderr, " Y'CbCr coefficient standard of card CARD (default auto)\n");
219 fprintf(stderr, " auto is rec601 for SD, rec709 for HD, always limited\n");
220 fprintf(stderr, " limited means standard 0-240/0-235 input range (for 8-bit)\n");
221 fprintf(stderr, " --mjpeg-export-cards=RANGE[,RANGE...]\n");
222 fprintf(stderr, " export the given cards in MJPEG format to /multicam.mp4,\n");
223 fprintf(stderr, " in the given order (ranges can be either single card indexes\n");
224 fprintf(stderr, " or pairs like 1-3 for camera 1,2,3; default is all cards)\n");
228 void parse_flags(Program program, int argc, char * const argv[])
230 static const option long_options[] = {
231 { "help", no_argument, 0, OPTION_HELP },
232 { "fullscreen", no_argument, 0, OPTION_FULLSCREEN },
233 { "width", required_argument, 0, 'w' },
234 { "height", required_argument, 0, 'h' },
235 { "num-cards", required_argument, 0, 'c' },
236 { "output-card", required_argument, 0, 'o' },
237 { "theme", required_argument, 0, 't' },
238 { "theme-dir", required_argument, 0, 'I' },
239 { "recording-dir", required_argument, 0, 'r' },
240 { "map-signal", required_argument, 0, 'm' },
241 { "input-mapping", required_argument, 0, 'M' },
242 { "va-display", required_argument, 0, 'v' },
243 { "multichannel", no_argument, 0, OPTION_MULTICHANNEL },
244 { "midi-mapping", required_argument, 0, OPTION_MIDI_MAPPING },
245 { "default-hdmi-input", no_argument, 0, OPTION_DEFAULT_HDMI_INPUT },
246 { "fake-cards-audio", no_argument, 0, OPTION_FAKE_CARDS_AUDIO },
247 { "v4l-output", required_argument, 0, OPTION_V4L_OUTPUT },
248 { "http-uncompressed-video", no_argument, 0, OPTION_HTTP_UNCOMPRESSED_VIDEO },
249 { "http-x264-video", no_argument, 0, OPTION_HTTP_X264_VIDEO },
250 { "record-x264-video", no_argument, 0, OPTION_RECORD_X264_VIDEO },
251 { "x264-preset", required_argument, 0, OPTION_X264_PRESET },
252 { "x264-tune", required_argument, 0, OPTION_X264_TUNE },
253 { "x264-speedcontrol", no_argument, 0, OPTION_X264_SPEEDCONTROL },
254 { "x264-speedcontrol-verbose", no_argument, 0, OPTION_X264_SPEEDCONTROL_VERBOSE },
255 { "x264-bitrate", required_argument, 0, OPTION_X264_BITRATE },
256 { "x264-crf", required_argument, 0, OPTION_X264_CRF },
257 { "x264-vbv-bufsize", required_argument, 0, OPTION_X264_VBV_BUFSIZE },
258 { "x264-vbv-max-bitrate", required_argument, 0, OPTION_X264_VBV_MAX_BITRATE },
259 { "x264-param", required_argument, 0, OPTION_X264_PARAM },
260 { "http-mux", required_argument, 0, OPTION_HTTP_MUX },
261 { "http-audio-codec", required_argument, 0, OPTION_HTTP_AUDIO_CODEC },
262 { "http-audio-bitrate", required_argument, 0, OPTION_HTTP_AUDIO_BITRATE },
263 { "http-port", required_argument, 0, OPTION_HTTP_PORT },
264 { "srt-port", required_argument, 0, OPTION_SRT_PORT },
265 { "no-srt", no_argument, 0, OPTION_NO_SRT },
266 { "no-transcode-audio", no_argument, 0, OPTION_NO_TRANSCODE_AUDIO },
267 { "disable-audio", no_argument, 0, OPTION_DISABLE_AUDIO },
268 { "flat-audio", no_argument, 0, OPTION_FLAT_AUDIO },
269 { "gain-staging", required_argument, 0, OPTION_GAIN_STAGING },
270 { "disable-locut", no_argument, 0, OPTION_DISABLE_LOCUT },
271 { "enable-locut", no_argument, 0, OPTION_ENABLE_LOCUT },
272 { "disable-gain-staging-auto", no_argument, 0, OPTION_DISABLE_GAIN_STAGING_AUTO },
273 { "enable-gain-staging-auto", no_argument, 0, OPTION_ENABLE_GAIN_STAGING_AUTO },
274 { "disable-compressor", no_argument, 0, OPTION_DISABLE_COMPRESSOR },
275 { "enable-compressor", no_argument, 0, OPTION_ENABLE_COMPRESSOR },
276 { "disable-limiter", no_argument, 0, OPTION_DISABLE_LIMITER },
277 { "enable-limiter", no_argument, 0, OPTION_ENABLE_LIMITER },
278 { "disable-makeup-gain-auto", no_argument, 0, OPTION_DISABLE_MAKEUP_GAIN_AUTO },
279 { "enable-makeup-gain-auto", no_argument, 0, OPTION_ENABLE_MAKEUP_GAIN_AUTO },
280 { "disable-alsa-output", no_argument, 0, OPTION_DISABLE_ALSA_OUTPUT },
281 { "no-flush-pbos", no_argument, 0, OPTION_NO_FLUSH_PBOS },
282 { "print-video-latency", no_argument, 0, OPTION_PRINT_VIDEO_LATENCY },
283 { "max-input-queue-frames", required_argument, 0, OPTION_MAX_INPUT_QUEUE_FRAMES },
284 { "audio-queue-length-ms", required_argument, 0, OPTION_AUDIO_QUEUE_LENGTH_MS },
285 { "output-ycbcr-coefficients", required_argument, 0, OPTION_OUTPUT_YCBCR_COEFFICIENTS },
286 { "output-buffer-frames", required_argument, 0, OPTION_OUTPUT_BUFFER_FRAMES },
287 { "output-slop-frames", required_argument, 0, OPTION_OUTPUT_SLOP_FRAMES },
288 { "timecode-stream", no_argument, 0, OPTION_TIMECODE_STREAM },
289 { "timecode-stdout", no_argument, 0, OPTION_TIMECODE_STDOUT },
290 { "quick-cut-keys", no_argument, 0, OPTION_QUICK_CUT_KEYS },
291 { "10-bit-input", no_argument, 0, OPTION_10_BIT_INPUT },
292 { "10-bit-output", no_argument, 0, OPTION_10_BIT_OUTPUT },
293 { "input-ycbcr-interpretation", required_argument, 0, OPTION_INPUT_YCBCR_INTERPRETATION },
294 { "mjpeg-export-cards", required_argument, 0, OPTION_MJPEG_EXPORT_CARDS },
297 vector<string> theme_dirs;
298 string output_ycbcr_coefficients = "auto";
299 bool card_to_mjpeg_stream_export_set = false;
301 int option_index = 0;
302 int c = getopt_long(argc, argv, "c:o:t:I:r:v:m:M:w:h:", long_options, &option_index);
309 global_flags.width = atoi(optarg);
312 global_flags.height = atoi(optarg);
315 global_flags.num_cards = atoi(optarg);
318 global_flags.output_card = atoi(optarg);
321 global_flags.theme_filename = optarg;
324 theme_dirs.push_back(optarg);
327 global_flags.recording_dir = optarg;
330 char *ptr = strchr(optarg, ',');
331 if (ptr == nullptr) {
332 fprintf(stderr, "ERROR: Invalid argument '%s' to --map-signal (needs a signal and a card number, separated by comma)\n", optarg);
336 const int signal_num = atoi(optarg);
337 const int card_num = atoi(ptr + 1);
338 if (global_flags.default_stream_mapping.count(signal_num)) {
339 fprintf(stderr, "ERROR: Signal %d already mapped to card %d\n",
340 signal_num, global_flags.default_stream_mapping[signal_num]);
343 global_flags.default_stream_mapping[signal_num] = card_num;
347 global_flags.input_mapping_filename = optarg;
349 case OPTION_MULTICHANNEL:
350 global_flags.multichannel_mapping_mode = true;
353 global_flags.va_display = optarg;
355 case OPTION_MIDI_MAPPING:
356 global_flags.midi_mapping_filename = optarg;
357 global_flags.multichannel_mapping_mode = true;
359 case OPTION_DEFAULT_HDMI_INPUT:
360 global_flags.default_hdmi_input = true;
362 case OPTION_FAKE_CARDS_AUDIO:
363 global_flags.fake_cards_audio = true;
365 case OPTION_V4L_OUTPUT:
366 global_flags.v4l_output_device = optarg;
368 case OPTION_HTTP_UNCOMPRESSED_VIDEO:
369 global_flags.uncompressed_video_to_http = true;
371 case OPTION_HTTP_MUX:
372 global_flags.stream_mux_name = optarg;
374 case OPTION_HTTP_AUDIO_CODEC:
375 global_flags.stream_audio_codec_name = optarg;
377 case OPTION_HTTP_AUDIO_BITRATE:
378 global_flags.stream_audio_codec_bitrate = atoi(optarg) * 1000;
380 case OPTION_HTTP_PORT:
381 global_flags.http_port = atoi(optarg);
383 case OPTION_SRT_PORT:
384 global_flags.srt_port = atoi(optarg);
387 global_flags.srt_port = -1;
389 case OPTION_NO_TRANSCODE_AUDIO:
390 global_flags.transcode_audio = false;
392 case OPTION_DISABLE_AUDIO:
393 global_flags.transcode_audio = false;
394 global_flags.enable_audio = false;
396 case OPTION_HTTP_X264_VIDEO:
397 global_flags.x264_video_to_http = true;
399 case OPTION_RECORD_X264_VIDEO:
400 global_flags.x264_video_to_disk = true;
401 global_flags.x264_video_to_http = true;
403 case OPTION_X264_PRESET:
404 global_flags.x264_preset = optarg;
406 case OPTION_X264_TUNE:
407 global_flags.x264_tune = optarg;
409 case OPTION_X264_SPEEDCONTROL:
410 global_flags.x264_speedcontrol = true;
412 case OPTION_X264_SPEEDCONTROL_VERBOSE:
413 global_flags.x264_speedcontrol_verbose = true;
415 case OPTION_X264_BITRATE:
416 global_flags.x264_bitrate = atoi(optarg);
418 case OPTION_X264_CRF:
419 global_flags.x264_crf = atof(optarg);
421 case OPTION_X264_VBV_BUFSIZE:
422 global_flags.x264_vbv_buffer_size = atoi(optarg);
424 case OPTION_X264_VBV_MAX_BITRATE:
425 global_flags.x264_vbv_max_bitrate = atoi(optarg);
427 case OPTION_X264_PARAM:
428 global_flags.x264_extra_param.push_back(optarg);
430 case OPTION_FLAT_AUDIO:
431 // If --flat-audio is given, turn off everything that messes with the sound,
432 // except the final makeup gain.
433 global_flags.locut_enabled = false;
434 global_flags.gain_staging_auto = false;
435 global_flags.compressor_enabled = false;
436 global_flags.limiter_enabled = false;
438 case OPTION_GAIN_STAGING:
439 global_flags.initial_gain_staging_db = atof(optarg);
440 global_flags.gain_staging_auto = false;
442 case OPTION_DISABLE_LOCUT:
443 global_flags.locut_enabled = false;
445 case OPTION_ENABLE_LOCUT:
446 global_flags.locut_enabled = true;
448 case OPTION_DISABLE_GAIN_STAGING_AUTO:
449 global_flags.gain_staging_auto = false;
451 case OPTION_ENABLE_GAIN_STAGING_AUTO:
452 global_flags.gain_staging_auto = true;
454 case OPTION_DISABLE_COMPRESSOR:
455 global_flags.compressor_enabled = false;
457 case OPTION_ENABLE_COMPRESSOR:
458 global_flags.compressor_enabled = true;
460 case OPTION_DISABLE_LIMITER:
461 global_flags.limiter_enabled = false;
463 case OPTION_ENABLE_LIMITER:
464 global_flags.limiter_enabled = true;
466 case OPTION_DISABLE_MAKEUP_GAIN_AUTO:
467 global_flags.final_makeup_gain_auto = false;
469 case OPTION_ENABLE_MAKEUP_GAIN_AUTO:
470 global_flags.final_makeup_gain_auto = true;
472 case OPTION_DISABLE_ALSA_OUTPUT:
473 global_flags.enable_alsa_output = false;
475 case OPTION_NO_FLUSH_PBOS:
476 global_flags.flush_pbos = false;
478 case OPTION_PRINT_VIDEO_LATENCY:
479 global_flags.print_video_latency = true;
481 case OPTION_MAX_INPUT_QUEUE_FRAMES:
482 global_flags.max_input_queue_frames = atoi(optarg);
484 case OPTION_AUDIO_QUEUE_LENGTH_MS:
485 global_flags.audio_queue_length_ms = atof(optarg);
487 case OPTION_OUTPUT_YCBCR_COEFFICIENTS:
488 output_ycbcr_coefficients = optarg;
490 case OPTION_OUTPUT_BUFFER_FRAMES:
491 global_flags.output_buffer_frames = atof(optarg);
493 case OPTION_OUTPUT_SLOP_FRAMES:
494 global_flags.output_slop_frames = atof(optarg);
496 case OPTION_TIMECODE_STREAM:
497 global_flags.display_timecode_in_stream = true;
499 case OPTION_TIMECODE_STDOUT:
500 global_flags.display_timecode_on_stdout = true;
502 case OPTION_QUICK_CUT_KEYS:
503 global_flags.enable_quick_cut_keys = true;
505 case OPTION_10_BIT_INPUT:
506 global_flags.ten_bit_input = true;
508 case OPTION_10_BIT_OUTPUT:
509 global_flags.ten_bit_output = true;
510 global_flags.x264_video_to_disk = true;
511 global_flags.x264_video_to_http = true;
512 global_flags.x264_bit_depth = 10;
514 case OPTION_INPUT_YCBCR_INTERPRETATION: {
515 char *ptr = strchr(optarg, ',');
516 if (ptr == nullptr) {
517 fprintf(stderr, "ERROR: Invalid argument '%s' to --input-ycbcr-interpretation (needs a card and an interpretation, separated by comma)\n", optarg);
521 const int card_num = atoi(optarg);
522 if (card_num < 0 || card_num >= MAX_VIDEO_CARDS) {
523 fprintf(stderr, "ERROR: Invalid card number %d\n", card_num);
527 YCbCrInterpretation interpretation;
528 char *interpretation_str = ptr + 1;
529 ptr = strchr(interpretation_str, ',');
530 if (ptr != nullptr) {
532 const char *range = ptr + 1;
533 if (strcmp(range, "full") == 0) {
534 interpretation.full_range = true;
535 } else if (strcmp(range, "limited") == 0) {
536 interpretation.full_range = false;
538 fprintf(stderr, "ERROR: Invalid Y'CbCr range '%s' (must be “full” or “limited”)\n", range);
543 if (strcmp(interpretation_str, "rec601") == 0) {
544 interpretation.ycbcr_coefficients_auto = false;
545 interpretation.ycbcr_coefficients = movit::YCBCR_REC_601;
546 } else if (strcmp(interpretation_str, "rec709") == 0) {
547 interpretation.ycbcr_coefficients_auto = false;
548 interpretation.ycbcr_coefficients = movit::YCBCR_REC_709;
549 } else if (strcmp(interpretation_str, "auto") == 0) {
550 interpretation.ycbcr_coefficients_auto = true;
551 if (interpretation.full_range) {
552 fprintf(stderr, "ERROR: Cannot use “auto” Y'CbCr coefficients with full range\n");
556 fprintf(stderr, "ERROR: Invalid Y'CbCr coefficients '%s' (must be “rec601”, “rec709” or “auto”)\n", interpretation_str);
559 global_flags.ycbcr_interpretation[card_num] = interpretation;
562 case OPTION_FULLSCREEN:
563 global_flags.fullscreen = true;
565 case OPTION_MJPEG_EXPORT_CARDS: {
566 if (card_to_mjpeg_stream_export_set) {
567 fprintf(stderr, "ERROR: --mjpeg-export-cards given twice\n");
570 global_flags.card_to_mjpeg_stream_export = parse_mjpeg_export_cards(optarg);
571 card_to_mjpeg_stream_export_set = true;
578 fprintf(stderr, "Unknown option '%s'\n", argv[option_index]);
579 fprintf(stderr, "\n");
585 if (global_flags.uncompressed_video_to_http &&
586 global_flags.x264_video_to_http) {
587 fprintf(stderr, "ERROR: --http-uncompressed-video and --http-x264-video are mutually incompatible\n");
590 if (global_flags.num_cards <= 0) {
591 fprintf(stderr, "ERROR: --num-cards must be at least 1\n");
594 if (global_flags.output_card < -1 ||
595 global_flags.output_card >= global_flags.num_cards) {
596 fprintf(stderr, "ERROR: --output-card points to a nonexistant card\n");
599 if (global_flags.enable_audio && !global_flags.transcode_audio && global_flags.stream_audio_codec_name.empty()) {
600 fprintf(stderr, "ERROR: If not transcoding audio, you must specify ahead-of-time what audio codec is in use\n");
601 fprintf(stderr, " (using --http-audio-codec).\n");
604 if (global_flags.x264_speedcontrol) {
605 if (!global_flags.x264_preset.empty() && global_flags.x264_preset != "faster") {
606 fprintf(stderr, "WARNING: --x264-preset is overridden by --x264-speedcontrol (implicitly uses \"faster\" as base preset)\n");
608 global_flags.x264_preset = "faster";
609 } else if (global_flags.x264_preset.empty()) {
610 global_flags.x264_preset = X264_DEFAULT_PRESET;
612 if (!theme_dirs.empty()) {
613 global_flags.theme_dirs = theme_dirs;
616 // In reality, we could probably do with any even value (we subsample
617 // by two in some places), but it's better to be on the safe side
618 // wrt. video codecs and such. (I'd set 16 if I could, but 1080 isn't
620 if (global_flags.width <= 0 || (global_flags.width % 8) != 0 ||
621 global_flags.height <= 0 || (global_flags.height % 8) != 0) {
622 fprintf(stderr, "ERROR: --width and --height must be positive integers divisible by 8\n");
626 for (pair<int, int> mapping : global_flags.default_stream_mapping) {
627 if (mapping.second >= global_flags.num_cards) {
628 fprintf(stderr, "ERROR: Signal %d mapped to card %d, which doesn't exist (try adjusting --num-cards)\n",
629 mapping.first, mapping.second);
634 // Rec. 709 would be the sane thing to do, but it seems many players
635 // just default to BT.601 coefficients no matter what. We _do_ set
636 // the right flags, so that a player that works properly doesn't have
637 // to guess, but it's frequently ignored. See discussions
638 // in e.g. https://trac.ffmpeg.org/ticket/4978; the situation with
639 // browsers is complicated and depends on things like hardware acceleration
640 // (https://bugs.chromium.org/p/chromium/issues/detail?id=333619 for
641 // extensive discussion). VLC generally fixed this as part of 3.0.0
642 // (see e.g. https://github.com/videolan/vlc/commit/bc71288b2e38c07d6921472824b92eef1aa85f7e
643 // and https://github.com/videolan/vlc/commit/c3fc2683a9cde1d42674ebf9935dced05733a215),
644 // but earlier versions were pretty random.
646 // On the other hand, HDMI/SDI output typically requires Rec. 709 for
647 // HD resolutions (with no way of signaling anything else), which is
648 // a conflicting demand. In this case, we typically let the HDMI/SDI
649 // output win if it is active, but the user can override this.
650 if (output_ycbcr_coefficients == "auto") {
651 // Essentially: BT.709 if HDMI/SDI output is on, otherwise BT.601.
652 global_flags.ycbcr_rec709_coefficients = false;
653 global_flags.ycbcr_auto_coefficients = true;
654 } else if (output_ycbcr_coefficients == "rec709") {
655 global_flags.ycbcr_rec709_coefficients = true;
656 global_flags.ycbcr_auto_coefficients = false;
657 } else if (output_ycbcr_coefficients == "rec601") {
658 global_flags.ycbcr_rec709_coefficients = false;
659 global_flags.ycbcr_auto_coefficients = false;
661 fprintf(stderr, "ERROR: --output-ycbcr-coefficients must be “rec601”, “rec709” or “auto”\n");
665 if (global_flags.output_buffer_frames < 0.0f) {
666 // Actually, even zero probably won't make sense; there is some internal
667 // delay to the card.
668 fprintf(stderr, "ERROR: --output-buffer-frames can't be negative.\n");
671 if (global_flags.output_slop_frames < 0.0f) {
672 fprintf(stderr, "ERROR: --output-slop-frames can't be negative.\n");
675 if (global_flags.max_input_queue_frames < 1) {
676 fprintf(stderr, "ERROR: --max-input-queue-frames must be at least 1.\n");
679 if (global_flags.max_input_queue_frames > 10) {
680 fprintf(stderr, "WARNING: --max-input-queue-frames has little effect over 10.\n");
683 if (!isinf(global_flags.x264_crf)) { // CRF mode is selected.
684 if (global_flags.x264_bitrate != -1) {
685 fprintf(stderr, "ERROR: --x264-bitrate and --x264-crf are mutually incompatible.\n");
688 if (global_flags.x264_vbv_max_bitrate != -1 && global_flags.x264_vbv_buffer_size != -1) {
689 fprintf(stderr, "WARNING: VBV settings are ignored with --x264-crf.\n");
691 } else if (global_flags.x264_bitrate == -1) {
692 global_flags.x264_bitrate = DEFAULT_X264_OUTPUT_BIT_RATE;
695 if (!card_to_mjpeg_stream_export_set) {
696 // Fill in the default mapping (export all cards, in order).
697 for (unsigned card_idx = 0; card_idx < unsigned(global_flags.num_cards); ++card_idx) {
698 global_flags.card_to_mjpeg_stream_export[card_idx] = card_idx;