X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=nageru%2Fflags.cpp;h=3231318077053b048bfd0cc5be5ac5c5a500526a;hb=f81ae3be1aae619fe4ad022f55d95a4a83ace076;hp=e625f8c11510163c2037fc20fbb1d8b79bcfefd1;hpb=acca75e2ec0a3dbd5fa26224d6cfa169827dedb1;p=nageru diff --git a/nageru/flags.cpp b/nageru/flags.cpp index e625f8c..3231318 100644 --- a/nageru/flags.cpp +++ b/nageru/flags.cpp @@ -1,11 +1,19 @@ #include "flags.h" +#include "defs.h" +#include "shared/shared_defs.h" +#include "ycbcr_interpretation.h" #include +#include +#include +#include #include #include #include +#include #include +#include using namespace std; @@ -51,6 +59,11 @@ enum LongOption { OPTION_HTTP_PORT, OPTION_SRT_PORT, OPTION_NO_SRT, + OPTION_SRT_DESTINATION, + OPTION_SRT_STREAMID, + OPTION_SRT_PASSPHRASE, + OPTION_SRT_YOUTUBE_STREAM_KEY, + OPTION_SRT_LATENCY, OPTION_NO_TRANSCODE_VIDEO, OPTION_NO_TRANSCODE_AUDIO, OPTION_DISABLE_AUDIO, @@ -162,7 +175,7 @@ void usage(Program program) fprintf(stderr, " --midi-mapping=FILE start with the given MIDI controller mapping (implies --multichannel)\n"); fprintf(stderr, " --default-hdmi-input default to HDMI over SDI inputs for cards that have both\n"); fprintf(stderr, " --fake-cards-audio make fake (disconnected) cards output a simple tone\n"); - fprintf(stderr, " --v4l-output DEVICE send video (no audio) to V4L2 output/loopback\n"); + fprintf(stderr, " --v4l-output=DEVICE send video (no audio) to V4L2 output/loopback\n"); fprintf(stderr, " --http-x264-video send x264-compressed video to HTTP clients\n"); fprintf(stderr, " --record-x264-video store x264-compressed video to disk (implies --http-x264-video,\n"); fprintf(stderr, " removes the need for working VA-API encoding)\n"); @@ -172,10 +185,9 @@ void usage(Program program) fprintf(stderr, " --x264-preset x264 quality preset (default " X264_DEFAULT_PRESET ")\n"); fprintf(stderr, " --x264-tune x264 tuning (default " X264_DEFAULT_TUNE ", can be blank)\n"); fprintf(stderr, " --x264-speedcontrol try to match x264 preset to available CPU speed\n"); - fprintf(stderr, " --x264-speedcontrol-verbose output speedcontrol debugging statistics\n"); fprintf(stderr, " --x264-bitrate x264 bitrate (in kilobit/sec, default %d)\n", DEFAULT_X264_OUTPUT_BIT_RATE); - fprintf(stderr, " --x264-crf=VALUE quality-based VBR (-12 to 51), incompatible with --x264-bitrate and VBV\n"); + fprintf(stderr, " --x264-crf=VALUE quality-based VBR (-12 to 51), incompatible with --x264-bitrate\n"); fprintf(stderr, " --x264-param=NAME[,VALUE] set any x264 parameter, for fine tuning\n"); if (program == PROGRAM_NAGERU) { fprintf(stderr, " --x264-separate-disk-preset x264 quality preset (default " X264_DEFAULT_PRESET ")\n"); @@ -187,7 +199,7 @@ void usage(Program program) fprintf(stderr, " --x264-separate-disk-param=NAME[,VALUE] set any x264 parameter, for fine tuning\n"); } #ifdef HAVE_AV1 - fprintf(stderr, " --http-av1-video send AV1-compressed video to HTTP clients\n"); + fprintf(stderr, " --http-av1-video send AV1-compressed video to HTTP clients and SRT output\n"); fprintf(stderr, " --av1-preset SVT-AV1 quality preset (default %d, from -2 to 13)\n", DEFAULT_AV1_PRESET); fprintf(stderr, " --av1-bitrate AV1 bitrate (in kilobit/sec, default %d)\n", @@ -197,16 +209,18 @@ void usage(Program program) fprintf(stderr, " --av1-param=NAME[,VALUE] set any SVT-AV1 parameter, for fine tuning\n"); #endif fprintf(stderr, " --http-mux=NAME mux to use for HTTP streams (default " DEFAULT_STREAM_MUX_NAME ")\n"); - fprintf(stderr, " --http-audio-codec=NAME audio codec to use for HTTP streams\n"); + fprintf(stderr, " --http-audio-codec=NAME audio codec to use for HTTP streams and SRT output\n"); fprintf(stderr, " (default is to use the same as for the recording)\n"); - fprintf(stderr, " --http-audio-bitrate=KBITS audio codec bit rate to use for HTTP streams\n"); + fprintf(stderr, " --http-audio-bitrate=KBITS audio codec bit rate to use for HTTP streams and SRT output\n"); fprintf(stderr, " (default is %d, ignored unless --http-audio-codec is set)\n", DEFAULT_AUDIO_OUTPUT_BIT_RATE / 1000); fprintf(stderr, " --http-port=PORT which port to use for the built-in HTTP server\n"); fprintf(stderr, " (default is %d)\n", DEFAULT_HTTPD_PORT); +#ifdef HAVE_SRT fprintf(stderr, " --srt-port=PORT which port to use for receiving SRT streams\n"); fprintf(stderr, " (default is %d)\n", DEFAULT_SRT_PORT); fprintf(stderr, " --no-srt disable receiving SRT streams\n"); +#endif if (program == PROGRAM_KAERU) { fprintf(stderr, " --no-transcode-video copy encoded video raw from the source stream\n"); fprintf(stderr, " (experimental, must be H.264)\n"); @@ -215,6 +229,14 @@ void usage(Program program) fprintf(stderr, " --disable-audio do not include any audio in the stream\n"); } if (program == PROGRAM_NAGERU) { +#ifdef HAVE_SRT + fprintf(stderr, " --srt-destination=HOST:PORT send HTTP video stream also to given destination\n"); + fprintf(stderr, " --srt-streamid=STREAMID SRT stream identifying ID\n"); + fprintf(stderr, " --srt-passphrase=PASSPHRASE SRT encryption key\n"); + fprintf(stderr, " --srt-youtube-stream-key=KEY shortcut for --srt-destination=a.srt.youtube.com:2010\n"); + fprintf(stderr, " --srt-streamid=#!::u=,copy=0,encoder=Nageru\n"); + fprintf(stderr, " --srt-latency=MS output SRT latency in milliseconds (default is %d)\n", DEFAULT_SRT_OUTPUT_LATENCY_MS); +#endif fprintf(stderr, " --flat-audio start with most audio processing turned off\n"); fprintf(stderr, " (can be overridden by e.g. --enable-limiter)\n"); fprintf(stderr, " --gain-staging=DB set initial gain staging to the given value\n"); @@ -283,8 +305,6 @@ void parse_flags(Program program, int argc, char * const argv[]) { "x264-preset", required_argument, 0, OPTION_X264_PRESET }, { "x264-tune", required_argument, 0, OPTION_X264_TUNE }, { "x264-speedcontrol", no_argument, 0, OPTION_X264_SPEEDCONTROL }, - { "x264-speedcontrol-verbose", no_argument, 0, OPTION_X264_SPEEDCONTROL_VERBOSE }, - { "x264-bitrate", required_argument, 0, OPTION_X264_BITRATE }, { "x264-crf", required_argument, 0, OPTION_X264_CRF }, { "x264-param", required_argument, 0, OPTION_X264_PARAM }, { "x264-separate-disk-preset", required_argument, 0, OPTION_X264_SEPARATE_DISK_PRESET }, @@ -303,8 +323,17 @@ void parse_flags(Program program, int argc, char * const argv[]) { "http-audio-codec", required_argument, 0, OPTION_HTTP_AUDIO_CODEC }, { "http-audio-bitrate", required_argument, 0, OPTION_HTTP_AUDIO_BITRATE }, { "http-port", required_argument, 0, OPTION_HTTP_PORT }, +#ifdef HAVE_SRT { "srt-port", required_argument, 0, OPTION_SRT_PORT }, - { "no-srt", no_argument, 0, OPTION_NO_SRT }, +#endif + { "no-srt", no_argument, 0, OPTION_NO_SRT }, // We silently allow this even without HAVE_SRT. +#ifdef HAVE_SRT + { "srt-destination", required_argument, 0, OPTION_SRT_DESTINATION }, + { "srt-streamid", required_argument, 0, OPTION_SRT_STREAMID }, + { "srt-passphrase", required_argument, 0, OPTION_SRT_PASSPHRASE }, + { "srt-youtube-stream-key", required_argument, 0, OPTION_SRT_YOUTUBE_STREAM_KEY }, + { "srt-latency", required_argument, 0, OPTION_SRT_LATENCY }, +#endif { "no-transcode-video", no_argument, 0, OPTION_NO_TRANSCODE_VIDEO }, { "no-transcode-audio", no_argument, 0, OPTION_NO_TRANSCODE_AUDIO }, { "disable-audio", no_argument, 0, OPTION_DISABLE_AUDIO }, @@ -340,6 +369,11 @@ void parse_flags(Program program, int argc, char * const argv[]) // apitrace in real time). For developers only, so undocumented. { "no-flush-pbos", no_argument, 0, OPTION_NO_FLUSH_PBOS }, + // Output speedcontrol debugging statistics. For developers only, + // so undocumented (users can get this information from Prometheus + // statistics, too). + { "x264-speedcontrol-verbose", no_argument, 0, OPTION_X264_SPEEDCONTROL_VERBOSE }, + // Deprecated variants. { "10-bit-input", no_argument, 0, OPTION_10_BIT_INPUT }, { "10-bit-output", no_argument, 0, OPTION_10_BIT_OUTPUT }, @@ -432,12 +466,45 @@ void parse_flags(Program program, int argc, char * const argv[]) case OPTION_HTTP_PORT: global_flags.http_port = atoi(optarg); break; +#ifdef HAVE_SRT case OPTION_SRT_PORT: global_flags.srt_port = atoi(optarg); break; +#endif case OPTION_NO_SRT: global_flags.srt_port = -1; break; +#ifdef HAVE_SRT + case OPTION_SRT_DESTINATION: { + const char *ptr = strrchr(optarg, ':'); + if (ptr == nullptr || strlen(optarg) < 3) { + fprintf(stderr, "ERROR: --srt-destination must be of the form host:port\n"); + exit(1); + } + global_flags.srt_destination_host = string(optarg, ptr - optarg); + if (global_flags.srt_destination_host[0] == '[' && + global_flags.srt_destination_host.back() == ']') { + // Support [IPv6]:port, in a sort of hackish way. + global_flags.srt_destination_host = global_flags.srt_destination_host.substr(1, global_flags.srt_destination_host.size() - 2); + } + global_flags.srt_destination_port = ptr + 1; + break; + } + case OPTION_SRT_STREAMID: + global_flags.srt_streamid = optarg; + break; + case OPTION_SRT_PASSPHRASE: + global_flags.srt_passphrase = optarg; + break; + case OPTION_SRT_YOUTUBE_STREAM_KEY: + global_flags.srt_destination_host = "a.srt.youtube.com"; + global_flags.srt_destination_port = "2010"; + global_flags.srt_streamid = string("#!::u=") + optarg + ",copy=0,encoder=Nageru " NAGERU_VERSION; + break; + case OPTION_SRT_LATENCY: + global_flags.srt_output_latency_ms = atoi(optarg); + break; +#endif case OPTION_NO_TRANSCODE_VIDEO: global_flags.transcode_video = false; break; @@ -823,4 +890,9 @@ void parse_flags(Program program, int argc, char * const argv[]) global_flags.card_to_mjpeg_stream_export[card_idx] = card_idx; } } + + if (global_flags.srt_destination_host == "a.srt.youtube.com" && global_flags.srt_passphrase.empty()) { + fprintf(stderr, "ERROR: Cannot stream to YouTube without --srt-passphrase (get it from the YouTube streaming console)\n"); + exit(1); + } }