]> git.sesse.net Git - nageru/blob - flags.cpp
Make it possible to set x264 preset/tune from the command line.
[nageru] / flags.cpp
1 #include "flags.h"
2
3 #include <getopt.h>
4 #include <stdio.h>
5 #include <stdlib.h>
6
7 Flags global_flags;
8
9 void usage()
10 {
11         fprintf(stderr, "Usage: nageru [OPTION]...\n");
12         fprintf(stderr, "\n");
13         fprintf(stderr, "  -h, --help                      print usage information\n");
14         fprintf(stderr, "  -c, --num-cards                 set number of input cards (default 2)\n");
15         fprintf(stderr, "  -t, --theme=FILE                choose theme (default theme.lua)\n");
16         fprintf(stderr, "  -v, --va-display=SPEC           VA-API device for H.264 encoding\n");
17         fprintf(stderr, "                                    ($DISPLAY spec or /dev/dri/render* path)\n");
18         fprintf(stderr, "      --http-uncompressed-video   send uncompressed NV12 video to HTTP clients\n");
19         fprintf(stderr, "      --http-x264-video           send x264-compressed video to HTTP clients\n");
20         fprintf(stderr, "      --x264-preset               x264 quality preset (default " X264_DEFAULT_PRESET ")\n");
21         fprintf(stderr, "      --x264-tune                 x264 tuning (default " X264_DEFAULT_TUNE ", can be blank)\n");
22         fprintf(stderr, "      --http-mux=NAME             mux to use for HTTP streams (default " DEFAULT_STREAM_MUX_NAME ")\n");
23         fprintf(stderr, "      --http-audio-codec=NAME     audio codec to use for HTTP streams\n");
24         fprintf(stderr, "                                  (default is to use the same as for the recording)\n");
25         fprintf(stderr, "      --http-audio-bitrate=KBITS  audio codec bit rate to use for HTTP streams\n");
26         fprintf(stderr, "                                  (default is %d, ignored unless --http-audio-codec is set)\n",
27                 DEFAULT_AUDIO_OUTPUT_BIT_RATE / 1000);
28         fprintf(stderr, "      --http-coarse-timebase      use less timebase for HTTP (recommended for muxers\n");
29         fprintf(stderr, "                                  that handle large pts poorly, like e.g. MP4)\n");
30         fprintf(stderr, "      --flat-audio                start with most audio processing turned off\n");
31         fprintf(stderr, "      --no-flush-pbos             do not explicitly signal texture data uploads\n");
32         fprintf(stderr, "                                    (will give display corruption, but makes it\n");
33         fprintf(stderr, "                                    possible to run with apitrace in real time)\n");
34 }
35
36 void parse_flags(int argc, char * const argv[])
37 {
38         static const option long_options[] = {
39                 { "help", no_argument, 0, 'h' },
40                 { "num-cards", required_argument, 0, 'c' },
41                 { "theme", required_argument, 0, 't' },
42                 { "va-display", required_argument, 0, 1000 },
43                 { "http-uncompressed-video", no_argument, 0, 1001 },
44                 { "http-x264-video", no_argument, 0, 1008 },
45                 { "x264-preset", required_argument, 0, 1009 },
46                 { "x264-tune", required_argument, 0, 1010 },
47                 { "http-mux", required_argument, 0, 1004 },
48                 { "http-coarse-timebase", no_argument, 0, 1005 },
49                 { "http-audio-codec", required_argument, 0, 1006 },
50                 { "http-audio-bitrate", required_argument, 0, 1007 },
51                 { "flat-audio", no_argument, 0, 1002 },
52                 { "no-flush-pbos", no_argument, 0, 1003 },
53                 { 0, 0, 0, 0 }
54         };
55         for ( ;; ) {
56                 int option_index = 0;
57                 int c = getopt_long(argc, argv, "c:t:", long_options, &option_index);
58
59                 if (c == -1) {
60                         break;
61                 }
62                 switch (c) {
63                 case 'c':
64                         global_flags.num_cards = atoi(optarg);
65                         break;
66                 case 't':
67                         global_flags.theme_filename = optarg;
68                         break;
69                 case 1000:
70                         global_flags.va_display = optarg;
71                         break;
72                 case 1001:
73                         global_flags.uncompressed_video_to_http = true;
74                         break;
75                 case 1004:
76                         global_flags.stream_mux_name = optarg;
77                         break;
78                 case 1005:
79                         global_flags.stream_coarse_timebase = true;
80                         break;
81                 case 1006:
82                         global_flags.stream_audio_codec_name = optarg;
83                         break;
84                 case 1007:
85                         global_flags.stream_audio_codec_bitrate = atoi(optarg) * 1000;
86                         break;
87                 case 1008:
88                         global_flags.x264_video_to_http = true;
89                         break;
90                 case 1009:
91                         global_flags.x264_preset = optarg;
92                         break;
93                 case 1010:
94                         global_flags.x264_tune = optarg;
95                         break;
96                 case 1002:
97                         global_flags.flat_audio = true;
98                         break;
99                 case 1003:
100                         global_flags.flush_pbos = false;
101                         break;
102                 case 'h':
103                         usage();
104                         exit(0);
105                 default:
106                         fprintf(stderr, "Unknown option '%s'\n", argv[option_index]);
107                         fprintf(stderr, "\n");
108                         usage();
109                         exit(1);
110                 }
111         }
112
113         if (global_flags.uncompressed_video_to_http &&
114             global_flags.x264_video_to_http) {
115                 fprintf(stderr, "ERROR: --http-uncompressed-video and --http-x264-video are mutually incompatible\n");
116                 exit(1);
117         }
118 }