]> git.sesse.net Git - nageru/commitdiff
Make Futatabi output frame rate adjustable.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Fri, 14 Dec 2018 19:15:06 +0000 (20:15 +0100)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Fri, 14 Dec 2018 19:15:06 +0000 (20:15 +0100)
futatabi/flags.cpp
futatabi/flags.h
futatabi/player.cpp

index 11ae71da864bdc62d9e9240b02ccf54bf7b86559..7a8246030abf7d485836d467800612aaef5a7c95 100644 (file)
@@ -25,6 +25,8 @@ void usage()
        fprintf(stderr, "      --help                      print usage information\n");
        fprintf(stderr, "  -w, --width                     output width in pixels (default 1280)\n");
        fprintf(stderr, "  -h, --height                    output height in pixels (default 720)\n");
+       fprintf(stderr, "  -r, --frame-rate NUM[/NUM]      output frame rate, as a float or fraction\n");
+       fprintf(stderr, "                                    (default 60000/1001 ~= 59.94)\n");
        fprintf(stderr, "      --slow-down-input           slow down input to realtime (default on if no\n");
        fprintf(stderr, "                                    source URL given)\n");
        fprintf(stderr, "  -q, --interpolation-quality N   0 = off\n");
@@ -42,6 +44,7 @@ void parse_flags(int argc, char * const argv[])
                { "help", no_argument, 0, OPTION_HELP },
                { "width", required_argument, 0, 'w' },
                { "height", required_argument, 0, 'h' },
+               { "frame-rate", required_argument, 0, 'r' },
                { "slow-down-input", no_argument, 0, OPTION_SLOW_DOWN_INPUT },
                { "interpolation-quality", required_argument, 0, 'q' },
                { "working-directory", required_argument, 0, 'd' },
@@ -50,7 +53,7 @@ void parse_flags(int argc, char * const argv[])
        };
        for ( ;; ) {
                int option_index = 0;
-               int c = getopt_long(argc, argv, "w:h:q:d:", long_options, &option_index);
+               int c = getopt_long(argc, argv, "w:h:r:q:d:", long_options, &option_index);
 
                if (c == -1) {
                        break;
@@ -62,6 +65,18 @@ void parse_flags(int argc, char * const argv[])
                case 'h':
                        global_flags.height = atoi(optarg);
                        break;
+               case 'r': {
+                       double num, den;
+                       if (sscanf(optarg, "%lf/%lf", &num, &den) == 2) {
+                               global_flags.output_framerate = num / den;
+                       } else if (sscanf(optarg, "%lf", &num) == 1) {
+                               global_flags.output_framerate = num;
+                       } else {
+                               fprintf(stderr, "Invalid frame rate given (must be on the form N or N/M)\n");
+                               exit(1);
+                       }
+                       break;
+               }
                case OPTION_SLOW_DOWN_INPUT:
                        global_flags.slow_down_input = true;
                        break;
index 395093640c9081c4e598603675139decfc02108d..23be12ccf8f6ea239dfa9f7b4fe287d4cce05afb 100644 (file)
@@ -12,6 +12,7 @@ struct Flags {
        bool slow_down_input = false;
        int interpolation_quality = 2;
        uint16_t http_port = DEFAULT_HTTPD_PORT;
+       double output_framerate = 60000.0 / 1001.0;
 };
 extern Flags global_flags;
 
index 80e77d1bda6fccf2faf2bb276e740cff05b20635..2fb3939ec65d4f7c09276494845ab1abe51fe2ae 100644 (file)
@@ -47,7 +47,6 @@ void Player::thread_func(Player::StreamOutput stream_output, AVFormatContext *fi
 
        check_error();
 
-       constexpr double output_framerate = 60000.0 / 1001.0;  // FIXME: make configurable
        int64_t pts = 0;
        Clip next_clip;
        size_t next_clip_idx = size_t(-1);
@@ -115,10 +114,10 @@ got_clip:
                int64_t in_pts_start_next_clip = -1;
                steady_clock::time_point next_frame_start;
                for (int frameno = 0; !should_quit; ++frameno) {  // Ends when the clip ends.
-                       double out_pts = out_pts_origin + TIMEBASE * frameno / output_framerate;
+                       double out_pts = out_pts_origin + TIMEBASE * frameno / global_flags.output_framerate;
                        next_frame_start =
                                origin + microseconds(lrint((out_pts - out_pts_origin) * 1e6 / TIMEBASE));
-                       int64_t in_pts = lrint(in_pts_origin + TIMEBASE * frameno * speed / output_framerate);
+                       int64_t in_pts = lrint(in_pts_origin + TIMEBASE * frameno * speed / global_flags.output_framerate);
                        pts = lrint(out_pts);
 
                        if (in_pts >= clip.pts_out) {
@@ -264,7 +263,7 @@ got_clip:
                        // TODO: Snap secondary (fade-to) clips in the same fashion.
                        bool snapped = false;
                        for (FrameOnDisk snap_frame : { frame_lower, frame_upper }) {
-                               double snap_pts_as_frameno = (snap_frame.pts - in_pts_origin) * output_framerate / TIMEBASE / speed;
+                               double snap_pts_as_frameno = (snap_frame.pts - in_pts_origin) * global_flags.output_framerate / TIMEBASE / speed;
                                if (fabs(snap_pts_as_frameno - frameno) < 0.01) {
                                        auto display_func = [this, primary_stream_idx, snap_frame, secondary_frame, fade_alpha]{
                                                if (destination != nullptr) {