16 fprintf(stderr, "Usage: nageru [OPTION]...\n");
17 fprintf(stderr, "\n");
18 fprintf(stderr, " -h, --help print usage information\n");
19 fprintf(stderr, " -c, --num-cards set number of input cards (default 2)\n");
20 fprintf(stderr, " -t, --theme=FILE choose theme (default theme.lua)\n");
21 fprintf(stderr, " -v, --va-display=SPEC VA-API device for H.264 encoding\n");
22 fprintf(stderr, " ($DISPLAY spec or /dev/dri/render* path)\n");
23 fprintf(stderr, " -m, --map-signal=SIGNAL,CARD set a default card mapping (can be given multiple times)\n");
24 fprintf(stderr, " --http-uncompressed-video send uncompressed NV12 video to HTTP clients\n");
25 fprintf(stderr, " --http-x264-video send x264-compressed video to HTTP clients\n");
26 fprintf(stderr, " --x264-preset x264 quality preset (default " X264_DEFAULT_PRESET ")\n");
27 fprintf(stderr, " --x264-tune x264 tuning (default " X264_DEFAULT_TUNE ", can be blank)\n");
28 fprintf(stderr, " --x264-bitrate x264 bitrate (in kilobit/sec, default %d)\n",
29 DEFAULT_X264_OUTPUT_BIT_RATE);
30 fprintf(stderr, " --x264-vbv-bufsize x264 VBV size (in kilobits, 0 = one-frame VBV,\n");
31 fprintf(stderr, " default: same as --x264-bitrate, that is, one-second VBV)\n");
32 fprintf(stderr, " --x264-vbv-max-bitrate x264 local max bitrate (in kilobit/sec per --vbv-bufsize,\n");
33 fprintf(stderr, " 0 = no limit, default: same as --x264-bitrate, i.e., CBR)\n");
34 fprintf(stderr, " --http-mux=NAME mux to use for HTTP streams (default " DEFAULT_STREAM_MUX_NAME ")\n");
35 fprintf(stderr, " --http-audio-codec=NAME audio codec to use for HTTP streams\n");
36 fprintf(stderr, " (default is to use the same as for the recording)\n");
37 fprintf(stderr, " --http-audio-bitrate=KBITS audio codec bit rate to use for HTTP streams\n");
38 fprintf(stderr, " (default is %d, ignored unless --http-audio-codec is set)\n",
39 DEFAULT_AUDIO_OUTPUT_BIT_RATE / 1000);
40 fprintf(stderr, " --http-coarse-timebase use less timebase for HTTP (recommended for muxers\n");
41 fprintf(stderr, " that handle large pts poorly, like e.g. MP4)\n");
42 fprintf(stderr, " --flat-audio start with most audio processing turned off\n");
43 fprintf(stderr, " --disable-alsa-output disable audio monitoring via ALSA\n");
44 fprintf(stderr, " --no-flush-pbos do not explicitly signal texture data uploads\n");
45 fprintf(stderr, " (will give display corruption, but makes it\n");
46 fprintf(stderr, " possible to run with apitrace in real time)\n");
49 void parse_flags(int argc, char * const argv[])
51 static const option long_options[] = {
52 { "help", no_argument, 0, 'h' },
53 { "num-cards", required_argument, 0, 'c' },
54 { "theme", required_argument, 0, 't' },
55 { "map-signal", required_argument, 0, 'm' },
56 { "va-display", required_argument, 0, 1000 },
57 { "http-uncompressed-video", no_argument, 0, 1001 },
58 { "http-x264-video", no_argument, 0, 1008 },
59 { "x264-preset", required_argument, 0, 1009 },
60 { "x264-tune", required_argument, 0, 1010 },
61 { "x264-bitrate", required_argument, 0, 1011 },
62 { "x264-vbv-bufsize", required_argument, 0, 1012 },
63 { "x264-vbv-max-bitrate", required_argument, 0, 1013 },
64 { "http-mux", required_argument, 0, 1004 },
65 { "http-coarse-timebase", no_argument, 0, 1005 },
66 { "http-audio-codec", required_argument, 0, 1006 },
67 { "http-audio-bitrate", required_argument, 0, 1007 },
68 { "flat-audio", no_argument, 0, 1002 },
69 { "disable-alsa-output", no_argument, 0, 1014 },
70 { "no-flush-pbos", no_argument, 0, 1003 },
75 int c = getopt_long(argc, argv, "c:t:", long_options, &option_index);
82 global_flags.num_cards = atoi(optarg);
85 global_flags.theme_filename = optarg;
88 char *ptr = strchr(optarg, ',');
90 fprintf(stderr, "ERROR: Invalid argument '%s' to --map-signal (needs a signal and a card number, separated by comma)\n", optarg);
94 const int signal_num = atoi(optarg);
95 const int card_num = atoi(ptr + 1);
96 if (global_flags.default_stream_mapping.count(signal_num)) {
97 fprintf(stderr, "ERROR: Signal %d already mapped to card %d\n",
98 signal_num, global_flags.default_stream_mapping[signal_num]);
101 global_flags.default_stream_mapping[signal_num] = card_num;
105 global_flags.va_display = optarg;
108 global_flags.uncompressed_video_to_http = true;
111 global_flags.stream_mux_name = optarg;
114 global_flags.stream_coarse_timebase = true;
117 global_flags.stream_audio_codec_name = optarg;
120 global_flags.stream_audio_codec_bitrate = atoi(optarg) * 1000;
123 global_flags.x264_video_to_http = true;
126 global_flags.x264_preset = optarg;
129 global_flags.x264_tune = optarg;
132 global_flags.x264_bitrate = atoi(optarg);
135 global_flags.x264_vbv_buffer_size = atoi(optarg);
138 global_flags.x264_vbv_max_bitrate = atoi(optarg);
141 global_flags.flat_audio = true;
144 global_flags.enable_alsa_output = false;
147 global_flags.flush_pbos = false;
153 fprintf(stderr, "Unknown option '%s'\n", argv[option_index]);
154 fprintf(stderr, "\n");
160 if (global_flags.uncompressed_video_to_http &&
161 global_flags.x264_video_to_http) {
162 fprintf(stderr, "ERROR: --http-uncompressed-video and --http-x264-video are mutually incompatible\n");
165 for (pair<int, int> mapping : global_flags.default_stream_mapping) {
166 if (mapping.second >= global_flags.num_cards) {
167 fprintf(stderr, "ERROR: Signal %d mapped to card %d, which doesn't exist (try adjusting --num-cards)\n",
168 mapping.first, mapping.second);