]> git.sesse.net Git - nageru/commitdiff
Add support for arbitrary x264 parameters.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Tue, 14 Jun 2016 23:05:39 +0000 (00:05 +0100)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Tue, 14 Jun 2016 23:05:39 +0000 (00:05 +0100)
flags.cpp
flags.h
x264_encoder.cpp

index 25f11b46d9fbe835a1e03dbaafcf67162fd360b5..06add31d388d2e844018555ef3e146fa036b4920 100644 (file)
--- a/flags.cpp
+++ b/flags.cpp
@@ -33,6 +33,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-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");
        fprintf(stderr, "                                  (default is to use the same as for the recording)\n");
@@ -65,6 +66,7 @@ void parse_flags(int argc, char * const argv[])
                { "x264-bitrate", required_argument, 0, 1011 },
                { "x264-vbv-bufsize", required_argument, 0, 1012 },
                { "x264-vbv-max-bitrate", required_argument, 0, 1013 },
+               { "x264-param", required_argument, 0, 1017 },
                { "http-mux", required_argument, 0, 1004 },
                { "http-coarse-timebase", no_argument, 0, 1005 },
                { "http-audio-codec", required_argument, 0, 1006 },
@@ -147,6 +149,9 @@ void parse_flags(int argc, char * const argv[])
                case 1013:
                        global_flags.x264_vbv_max_bitrate = atoi(optarg);
                        break;
+               case 1017:
+                       global_flags.x264_extra_param.push_back(optarg);
+                       break;
                case 1002:
                        global_flags.flat_audio = true;
                        break;
diff --git a/flags.h b/flags.h
index edc47dd96cecff038b8a39b8f79685c63364e329..ad9606e7b7393afcb4d7548216bfb30570b8f261 100644 (file)
--- a/flags.h
+++ b/flags.h
@@ -3,6 +3,7 @@
 
 #include <map>
 #include <string>
+#include <vector>
 
 #include "defs.h"
 
@@ -25,6 +26,7 @@ struct Flags {
        int x264_bitrate = DEFAULT_X264_OUTPUT_BIT_RATE;  // In kilobit/sec.
        int x264_vbv_max_bitrate = -1;  // In kilobits. 0 = no limit, -1 = same as <x264_bitrate> (CBR).
        int x264_vbv_buffer_size = -1;  // In kilobits. 0 = one-frame VBV, -1 = same as <x264_bitrate> (one-second VBV).
+       std::vector<std::string> x264_extra_param;  // In “key[,value]” format.
        bool enable_alsa_output = true;
        std::map<int, int> default_stream_mapping;
 };
index 8ee486734a9dc72b239298db5b587f9b01b62800..5017e7357913ce5d33c74efc95e262e5889fcd69 100644 (file)
@@ -125,7 +125,21 @@ void X264Encoder::init_x264()
        // be on the safe side. Shouldn't affect quality in any meaningful way.
        param.rc.i_qp_min = 5;
 
-       // TODO: more flags here, via x264_param_parse().
+       for (const string &str : global_flags.x264_extra_param) {
+               const size_t pos = str.find(',');
+               if (pos == string::npos) {
+                       if (x264_param_parse(&param, str.c_str(), nullptr) != 0) {
+                               fprintf(stderr, "ERROR: x264 rejected parameter '%s'\n", str.c_str());
+                       }
+               } else {
+                       const string key = str.substr(0, pos);
+                       const string value = str.substr(pos + 1);
+                       if (x264_param_parse(&param, key.c_str(), value.c_str()) != 0) {
+                               fprintf(stderr, "ERROR: x264 rejected parameter '%s' set to '%s'\n",
+                                       key.c_str(), value.c_str());
+                       }
+               }
+       }
 
        x264_param_apply_profile(&param, "high");