X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=flags.cpp;h=bdb9821d5aafed89dbe453be4865600f888beb68;hb=refs%2Fheads%2Fmjpeg;hp=cd648b9d1ec53eff80a8185763b8131ca8cae550;hpb=e08f8c2acf17cbdc4bd878edb1d779bf898aac76;p=nageru diff --git a/flags.cpp b/flags.cpp index cd648b9..bdb9821 100644 --- a/flags.cpp +++ b/flags.cpp @@ -14,6 +14,7 @@ Flags global_flags; // Long options that have no corresponding short option. enum LongOption { OPTION_HELP = 1000, + OPTION_FULLSCREEN, OPTION_MULTICHANNEL, OPTION_MIDI_MAPPING, OPTION_DEFAULT_HDMI_INPUT, @@ -62,8 +63,57 @@ enum LongOption { OPTION_10_BIT_INPUT, OPTION_10_BIT_OUTPUT, OPTION_INPUT_YCBCR_INTERPRETATION, + OPTION_MJPEG_EXPORT_CARDS, }; +map parse_mjpeg_export_cards(char *optarg) +{ + map ret; + if (optarg[0] == '\0') { + return ret; + } + + unsigned stream_idx = 0; + char *start = optarg; + for ( ;; ) { + char *end = strchr(start, ','); + if (end != nullptr) { + *end = '\0'; + } + + unsigned range_begin, range_end; + if (sscanf(start, "%u-%u", &range_begin, &range_end) != 2) { + range_begin = range_end = atoi(start); + } + if (range_end < range_begin) { + fprintf(stderr, "ERROR: Invalid range %u-%u in --mjpeg-export-cards=\n", range_begin, range_end); + exit(1); + } + if (range_end >= unsigned(global_flags.num_cards)) { + // There are situations where we could possibly want to + // include FFmpeg inputs (CEF inputs are unlikely), + // but they're not necessarily in 4:2:2 Y'CbCr, so it would + // require more functionality the the JPEG encoder. + fprintf(stderr, "ERROR: Asked for (zero-indexed) card %u in --mjpeg-export-cards=, but there are only %u cards\n", + range_end, global_flags.num_cards); + exit(1); + } + for (unsigned card_idx = range_begin; card_idx <= range_end; ++card_idx) { + if (ret.count(card_idx)) { + fprintf(stderr, "ERROR: Card %u was given twice in --mjpeg-export-cards=\n", card_idx); + exit(1); + } + ret[card_idx] = stream_idx++; + } + if (end == nullptr) { + break; + } else { + start = end + 1; + } + } + return ret; +} + void usage(Program program) { if (program == PROGRAM_KAERU) { @@ -73,6 +123,9 @@ void usage(Program program) } fprintf(stderr, "\n"); fprintf(stderr, " --help print usage information\n"); + if (program == PROGRAM_NAGERU) { + fprintf(stderr, " --fullscreen run in full screen, with no decorations\n"); + } fprintf(stderr, " -w, --width output width in pixels (default 1280)\n"); fprintf(stderr, " -h, --height output height in pixels (default 720)\n"); if (program == PROGRAM_NAGERU) { @@ -156,6 +209,10 @@ void usage(Program program) fprintf(stderr, " Y'CbCr coefficient standard of card CARD (default auto)\n"); fprintf(stderr, " auto is rec601 for SD, rec709 for HD, always limited\n"); fprintf(stderr, " limited means standard 0-240/0-235 input range (for 8-bit)\n"); + fprintf(stderr, " --mjpeg-export-cards=RANGE[,RANGE...]\n"); + fprintf(stderr, " export the given cards in MJPEG format to /multicam.mp4,\n"); + fprintf(stderr, " in the given order (ranges can be either single card indexes\n"); + fprintf(stderr, " or pairs like 1-3 for camera 1,2,3; default is all cards)\n"); } } @@ -163,6 +220,7 @@ void parse_flags(Program program, int argc, char * const argv[]) { static const option long_options[] = { { "help", no_argument, 0, OPTION_HELP }, + { "fullscreen", no_argument, 0, OPTION_FULLSCREEN }, { "width", required_argument, 0, 'w' }, { "height", required_argument, 0, 'h' }, { "num-cards", required_argument, 0, 'c' }, @@ -220,10 +278,12 @@ void parse_flags(Program program, int argc, char * const argv[]) { "10-bit-input", no_argument, 0, OPTION_10_BIT_INPUT }, { "10-bit-output", no_argument, 0, OPTION_10_BIT_OUTPUT }, { "input-ycbcr-interpretation", required_argument, 0, OPTION_INPUT_YCBCR_INTERPRETATION }, + { "mjpeg-export-cards", required_argument, 0, OPTION_MJPEG_EXPORT_CARDS }, { 0, 0, 0, 0 } }; vector theme_dirs; string output_ycbcr_coefficients = "auto"; + bool card_to_mjpeg_stream_export_set = false; for ( ;; ) { int option_index = 0; int c = getopt_long(argc, argv, "c:t:I:r:v:m:M:w:h:", long_options, &option_index); @@ -473,6 +533,18 @@ void parse_flags(Program program, int argc, char * const argv[]) global_flags.ycbcr_interpretation[card_num] = interpretation; break; } + case OPTION_FULLSCREEN: + global_flags.fullscreen = true; + break; + case OPTION_MJPEG_EXPORT_CARDS: { + if (card_to_mjpeg_stream_export_set) { + fprintf(stderr, "ERROR: --mjpeg-export-cards given twice\n"); + exit(1); + } + global_flags.card_to_mjpeg_stream_export = parse_mjpeg_export_cards(optarg); + card_to_mjpeg_stream_export_set = true; + break; + } case OPTION_HELP: usage(program); exit(0); @@ -593,4 +665,11 @@ void parse_flags(Program program, int argc, char * const argv[]) } else if (global_flags.x264_bitrate == -1) { global_flags.x264_bitrate = DEFAULT_X264_OUTPUT_BIT_RATE; } + + if (!card_to_mjpeg_stream_export_set) { + // Fill in the default mapping (export all cards, in order). + for (unsigned card_idx = 0; card_idx < unsigned(global_flags.num_cards); ++card_idx) { + global_flags.card_to_mjpeg_stream_export[card_idx] = card_idx; + } + } }