]> git.sesse.net Git - nageru/commitdiff
Make it possible to set x264 preset/tune from the command line.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Mon, 18 Apr 2016 14:16:41 +0000 (16:16 +0200)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Mon, 18 Apr 2016 14:16:41 +0000 (16:16 +0200)
defs.h
flags.cpp
flags.h
x264encode.cpp

diff --git a/defs.h b/defs.h
index 0e5378c4d07e5fbee67e888c1e5adab7ad88ae5c..aa577bb607af039e8136c9e609e6e9027a872ea5 100644 (file)
--- a/defs.h
+++ b/defs.h
 // For mov, you want this at 10MB or so (for the reason mentioned above),
 // but for nut, there's no flushing, so such a large mux buffer would cause
 // the output to be very uneven.
-#define MUX_BUFFER_SIZE 65536
+#define MUX_BUFFER_SIZE 10485760
 
 // In number of frames. Comes in addition to any internal queues in x264
 // (frame threading, lookahead, etc.).
 #define X264_QUEUE_LENGTH 50
 
+#define X264_DEFAULT_PRESET "ultrafast"
+#define X264_DEFAULT_TUNE "film"
+
 #endif  // !defined(_DEFS_H)
index 853f6fbeed6aba0a207be046714929afc200e67b..01f563f5ca8c6ac155ffcc152e0e767af985eabc 100644 (file)
--- a/flags.cpp
+++ b/flags.cpp
@@ -17,6 +17,8 @@ void usage()
        fprintf(stderr, "                                    ($DISPLAY spec or /dev/dri/render* path)\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, "      --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, "      --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");
@@ -40,6 +42,8 @@ void parse_flags(int argc, char * const argv[])
                { "va-display", required_argument, 0, 1000 },
                { "http-uncompressed-video", no_argument, 0, 1001 },
                { "http-x264-video", no_argument, 0, 1008 },
+               { "x264-preset", required_argument, 0, 1009 },
+               { "x264-tune", required_argument, 0, 1010 },
                { "http-mux", required_argument, 0, 1004 },
                { "http-coarse-timebase", no_argument, 0, 1005 },
                { "http-audio-codec", required_argument, 0, 1006 },
@@ -83,6 +87,12 @@ void parse_flags(int argc, char * const argv[])
                case 1008:
                        global_flags.x264_video_to_http = true;
                        break;
+               case 1009:
+                       global_flags.x264_preset = optarg;
+                       break;
+               case 1010:
+                       global_flags.x264_tune = optarg;
+                       break;
                case 1002:
                        global_flags.flat_audio = true;
                        break;
diff --git a/flags.h b/flags.h
index cfef0fa5ae1c22b18646403079a23e64d3757097..b157822a0a3295e974d2d18bd2f4725b7328ecb4 100644 (file)
--- a/flags.h
+++ b/flags.h
@@ -17,6 +17,8 @@ struct Flags {
        bool stream_coarse_timebase = false;
        std::string stream_audio_codec_name;  // Blank = use the same as for the recording.
        int stream_audio_codec_bitrate = DEFAULT_AUDIO_OUTPUT_BIT_RATE;  // Ignored if stream_audio_codec_name is blank.
+       std::string x264_preset = X264_DEFAULT_PRESET;
+       std::string x264_tune = X264_DEFAULT_TUNE;
 };
 extern Flags global_flags;
 
index a72d940f8a115eb8bde0be93fb7adb953b02d7e1..cafb64d813c83a778051c99bb085d8b77064e892 100644 (file)
@@ -2,6 +2,7 @@
 #include <unistd.h>
 
 #include "defs.h"
+#include "flags.h"
 #include "mux.h"
 #include "timebase.h"
 #include "x264encode.h"
@@ -60,7 +61,7 @@ void X264Encoder::end_encoding()
 void X264Encoder::init_x264()
 {
        x264_param_t param;
-       x264_param_default_preset(&param, "ultrafast", "film");  // TODO: flags
+       x264_param_default_preset(&param, global_flags.x264_preset.c_str(), global_flags.x264_tune.c_str());
 
        param.i_width = WIDTH;
        param.i_height = HEIGHT;