]> git.sesse.net Git - nageru/blobdiff - flags.cpp
Support loading 10-bit x264 dynamically.
[nageru] / flags.cpp
index f81f96d65aea9eab5853ace1027d5d1387a30160..e6c306be52d23b38614aa8361aac6331404c5cca 100644 (file)
--- a/flags.cpp
+++ b/flags.cpp
@@ -19,6 +19,7 @@ enum LongOption {
        OPTION_FAKE_CARDS_AUDIO,
        OPTION_HTTP_UNCOMPRESSED_VIDEO,
        OPTION_HTTP_X264_VIDEO,
+       OPTION_RECORD_X264_VIDEO,
        OPTION_X264_PRESET,
        OPTION_X264_TUNE,
        OPTION_X264_SPEEDCONTROL,
@@ -26,6 +27,7 @@ enum LongOption {
        OPTION_X264_BITRATE,
        OPTION_X264_VBV_BUFSIZE,
        OPTION_X264_VBV_MAX_BITRATE,
+       OPTION_X264_10_BIT,
        OPTION_X264_PARAM,
        OPTION_HTTP_MUX,
        OPTION_HTTP_COARSE_TIMEBASE,
@@ -46,10 +48,14 @@ enum LongOption {
        OPTION_DISABLE_ALSA_OUTPUT,
        OPTION_NO_FLUSH_PBOS,
        OPTION_PRINT_VIDEO_LATENCY,
+       OPTION_MAX_INPUT_QUEUE_FRAMES,
        OPTION_AUDIO_QUEUE_LENGTH_MS,
        OPTION_OUTPUT_YCBCR_COEFFICIENTS,
        OPTION_OUTPUT_BUFFER_FRAMES,
        OPTION_OUTPUT_SLOP_FRAMES,
+       OPTION_TIMECODE_STREAM,
+       OPTION_TIMECODE_STDOUT,
+       OPTION_10_BIT_INPUT,
 };
 
 void usage()
@@ -72,6 +78,8 @@ void usage()
        fprintf(stderr, "      --fake-cards-audio          make fake (disconnected) cards output a simple tone\n");
        fprintf(stderr, "      --http-uncompressed-video   send uncompressed NV12 video to HTTP clients\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");
        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");
@@ -82,6 +90,7 @@ void usage()
        fprintf(stderr, "                                  default: same as --x264-bitrate, that is, one-second VBV)\n");
        fprintf(stderr, "      --x264-vbv-max-bitrate      x264 local max bitrate (in kilobit/sec per --vbv-bufsize,\n");
        fprintf(stderr, "                                  0 = no limit, default: same as --x264-bitrate, i.e., CBR)\n");
+       fprintf(stderr, "      --x264-10-bit               enable 10-bit x264 encoding\n");
        fprintf(stderr, "      --x264-param=NAME[,VALUE]   set any x264 parameter, for fine tuning\n");
        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");
@@ -105,17 +114,22 @@ void usage()
        fprintf(stderr, "                                    (will give display corruption, but makes it\n");
        fprintf(stderr, "                                    possible to run with apitrace in real time)\n");
        fprintf(stderr, "      --print-video-latency       print out measurements of video latency on stdout\n");
+       fprintf(stderr, "      --max-input-queue-frames=FRAMES  never keep more than FRAMES frames for each card\n");
+       fprintf(stderr, "                                    (default 6, minimum 1)\n");
        fprintf(stderr, "      --audio-queue-length-ms=MS  length of audio resampling queue (default 100.0)\n");
        fprintf(stderr, "      --output-ycbcr-coefficients={rec601,rec709,auto}\n");
        fprintf(stderr, "                                  Y'CbCr coefficient standard of output (default auto)\n");
-       fprintf(stderr, "                                    auto is rec709 if and only if --output-card is used\n");
-       fprintf(stderr, "                                    and a HD resolution is set\n");
+       fprintf(stderr, "                                    auto is rec601, unless --output-card is used\n");
+       fprintf(stderr, "                                    and a Rec. 709 mode (typically HD modes) is in use\n");
        fprintf(stderr, "      --output-buffer-frames=NUM  number of frames in output buffer for --output-card,\n");
        fprintf(stderr, "                                    can be fractional (default 6.0); note also\n");
        fprintf(stderr, "                                    the audio queue can't be much longer than this\n");
        fprintf(stderr, "      --output-slop-frames=NUM    if more less than this number of frames behind for\n");
        fprintf(stderr, "                                    --output-card, try to submit anyway instead of\n");
        fprintf(stderr, "                                    dropping the frame (default 0.5)\n");
+       fprintf(stderr, "      --timecode-stream           show timestamp and timecode in stream\n");
+       fprintf(stderr, "      --timecode-stdout           show timestamp and timecode on standard output\n");
+       fprintf(stderr, "      --10-bit-input              use 10-bit video input (requires compute shaders)\n");
 }
 
 void parse_flags(int argc, char * const argv[])
@@ -136,6 +150,7 @@ void parse_flags(int argc, char * const argv[])
                { "fake-cards-audio", no_argument, 0, OPTION_FAKE_CARDS_AUDIO },
                { "http-uncompressed-video", no_argument, 0, OPTION_HTTP_UNCOMPRESSED_VIDEO },
                { "http-x264-video", no_argument, 0, OPTION_HTTP_X264_VIDEO },
+               { "record-x264-video", no_argument, 0, OPTION_RECORD_X264_VIDEO },
                { "x264-preset", required_argument, 0, OPTION_X264_PRESET },
                { "x264-tune", required_argument, 0, OPTION_X264_TUNE },
                { "x264-speedcontrol", no_argument, 0, OPTION_X264_SPEEDCONTROL },
@@ -143,6 +158,7 @@ void parse_flags(int argc, char * const argv[])
                { "x264-bitrate", required_argument, 0, OPTION_X264_BITRATE },
                { "x264-vbv-bufsize", required_argument, 0, OPTION_X264_VBV_BUFSIZE },
                { "x264-vbv-max-bitrate", required_argument, 0, OPTION_X264_VBV_MAX_BITRATE },
+               { "x264-10-bit", no_argument, 0, OPTION_X264_10_BIT },
                { "x264-param", required_argument, 0, OPTION_X264_PARAM },
                { "http-mux", required_argument, 0, OPTION_HTTP_MUX },
                { "http-coarse-timebase", no_argument, 0, OPTION_HTTP_COARSE_TIMEBASE },
@@ -163,10 +179,14 @@ void parse_flags(int argc, char * const argv[])
                { "disable-alsa-output", no_argument, 0, OPTION_DISABLE_ALSA_OUTPUT },
                { "no-flush-pbos", no_argument, 0, OPTION_NO_FLUSH_PBOS },
                { "print-video-latency", no_argument, 0, OPTION_PRINT_VIDEO_LATENCY },
+               { "max-input-queue-frames", required_argument, 0, OPTION_MAX_INPUT_QUEUE_FRAMES },
                { "audio-queue-length-ms", required_argument, 0, OPTION_AUDIO_QUEUE_LENGTH_MS },
                { "output-ycbcr-coefficients", required_argument, 0, OPTION_OUTPUT_YCBCR_COEFFICIENTS },
                { "output-buffer-frames", required_argument, 0, OPTION_OUTPUT_BUFFER_FRAMES },
                { "output-slop-frames", required_argument, 0, OPTION_OUTPUT_SLOP_FRAMES },
+               { "timecode-stream", no_argument, 0, OPTION_TIMECODE_STREAM },
+               { "timecode-stdout", no_argument, 0, OPTION_TIMECODE_STDOUT },
+               { "10-bit-input", no_argument, 0, OPTION_10_BIT_INPUT },
                { 0, 0, 0, 0 }
        };
        vector<string> theme_dirs;
@@ -248,6 +268,10 @@ void parse_flags(int argc, char * const argv[])
                case OPTION_HTTP_X264_VIDEO:
                        global_flags.x264_video_to_http = true;
                        break;
+               case OPTION_RECORD_X264_VIDEO:
+                       global_flags.x264_video_to_disk = true;
+                       global_flags.x264_video_to_http = true;
+                       break;
                case OPTION_X264_PRESET:
                        global_flags.x264_preset = optarg;
                        break;
@@ -266,6 +290,9 @@ void parse_flags(int argc, char * const argv[])
                case OPTION_X264_VBV_BUFSIZE:
                        global_flags.x264_vbv_buffer_size = atoi(optarg);
                        break;
+               case OPTION_X264_10_BIT:
+                       global_flags.x264_bit_depth = 10;
+                       break;
                case OPTION_X264_VBV_MAX_BITRATE:
                        global_flags.x264_vbv_max_bitrate = atoi(optarg);
                        break;
@@ -323,6 +350,9 @@ void parse_flags(int argc, char * const argv[])
                case OPTION_PRINT_VIDEO_LATENCY:
                        global_flags.print_video_latency = true;
                        break;
+               case OPTION_MAX_INPUT_QUEUE_FRAMES:
+                       global_flags.max_input_queue_frames = atoi(optarg);
+                       break;
                case OPTION_AUDIO_QUEUE_LENGTH_MS:
                        global_flags.audio_queue_length_ms = atof(optarg);
                        break;
@@ -335,6 +365,15 @@ void parse_flags(int argc, char * const argv[])
                case OPTION_OUTPUT_SLOP_FRAMES:
                        global_flags.output_slop_frames = atof(optarg);
                        break;
+               case OPTION_TIMECODE_STREAM:
+                       global_flags.display_timecode_in_stream = true;
+                       break;
+               case OPTION_TIMECODE_STDOUT:
+                       global_flags.display_timecode_on_stdout = true;
+                       break;
+               case OPTION_10_BIT_INPUT:
+                       global_flags.ten_bit_input = true;
+                       break;
                case OPTION_HELP:
                        usage();
                        exit(0);
@@ -405,17 +444,17 @@ void parse_flags(int argc, char * const argv[])
        // On the other hand, HDMI/SDI output typically requires Rec. 709 for
        // HD resolutions (with no way of signaling anything else), which is
        // a conflicting demand. In this case, we typically let the HDMI/SDI
-       // output win, but the user can override this.
+       // output win if it is active, but the user can override this.
        if (output_ycbcr_coefficients == "auto") {
-               if (global_flags.output_card >= 0 && global_flags.width >= 1280) {
-                       global_flags.ycbcr_rec709_coefficients = true;
-               } else {
-                       global_flags.ycbcr_rec709_coefficients = false;
-               }
+               // Essentially: BT.709 if HDMI/SDI output is on, otherwise BT.601.
+               global_flags.ycbcr_rec709_coefficients = false;
+               global_flags.ycbcr_auto_coefficients = true;
        } else if (output_ycbcr_coefficients == "rec709") {
                global_flags.ycbcr_rec709_coefficients = true;
+               global_flags.ycbcr_auto_coefficients = false;
        } else if (output_ycbcr_coefficients == "rec601") {
                global_flags.ycbcr_rec709_coefficients = false;
+               global_flags.ycbcr_auto_coefficients = false;
        } else {
                fprintf(stderr, "ERROR: --output-ycbcr-coefficients must be “rec601”, “rec709” or “auto”\n");
                exit(1);
@@ -431,4 +470,11 @@ void parse_flags(int argc, char * const argv[])
                fprintf(stderr, "ERROR: --output-slop-frames can't be negative.\n");
                exit(1);
        }
+       if (global_flags.max_input_queue_frames < 1) {
+               fprintf(stderr, "ERROR: --max-input-queue-frames must be at least 1.\n");
+               exit(1);
+       }
+       if (global_flags.max_input_queue_frames > 10) {
+               fprintf(stderr, "WARNING: --max-input-queue-frames has little effect over 10.\n");
+       }
 }