changeset 32476:af9ef007bec6

Add the -force-key-frames option.
author cigaes
date Fri, 29 Oct 2010 13:50:05 +0000
parents 87d55484ceaa
children 2f95644eb8cb
files Changelog DOCS/man/en/mplayer.1 cfg-mencoder.h libmpcodecs/ve.c libmpcodecs/ve.h
diffstat 5 files changed, 77 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/Changelog	Fri Oct 29 13:48:12 2010 +0000
+++ b/Changelog	Fri Oct 29 13:50:05 2010 +0000
@@ -8,6 +8,9 @@
     * experimental support for PGS (BluRay-compatible), DVB and XSUB subtitles.
     * experimental af_cmdline slave command to change e.g. audio equalizer options at runtime.
 
+    MEncoder:
+    * -force-key-frames option to set explicit seek points.
+
   rc4: "Yes We Can"
 
     GUI: Changes towards removing the GUI
--- a/DOCS/man/en/mplayer.1	Fri Oct 29 13:48:12 2010 +0000
+++ b/DOCS/man/en/mplayer.1	Fri Oct 29 13:50:05 2010 +0000
@@ -8000,6 +8000,21 @@
 .B \-vobsuboutindex <index>
 Specify the index of the subtitles in the output files (default: 0).
 .
+.TP
+.B \-force\-key\-frames <time>,<time>,...
+Force key frames at the specified timestamps, more precisely at the first
+frame after each specified time.
+.sp 1
+This option can be used to ensure that a seek point is present at a chapter
+mark or any other designated place in the output file.
+.sp 1
+The timestamps must be specified in ascending order.
+.sp 1
+Since MEncoder does not send timestamps along the filter chain, you probably
+need to use the fixpts filter for this option to work.
+.sp 1
+Not all codecs support forced key frames.
+.
 .
 .
 .SH "CODEC SPECIFIC ENCODING OPTIONS (MENCODER ONLY)"
--- a/cfg-mencoder.h	Fri Oct 29 13:48:12 2010 +0000
+++ b/cfg-mencoder.h	Fri Oct 29 13:50:05 2010 +0000
@@ -220,6 +220,8 @@
     // info header strings
     {"info", info_conf, CONF_TYPE_SUBCONFIG, CONF_GLOBAL, 0, 0, NULL},
 
+    {"force-key-frames", parse_forced_key_frames, CONF_TYPE_FUNC_PARAM, CONF_GLOBAL, 0, 0, NULL},
+
 #ifdef CONFIG_MP3LAME
     {"lameopts", lameopts_conf, CONF_TYPE_SUBCONFIG, CONF_GLOBAL, 0, 0, NULL},
 #endif
--- a/libmpcodecs/ve.c	Fri Oct 29 13:48:12 2010 +0000
+++ b/libmpcodecs/ve.c	Fri Oct 29 13:50:05 2010 +0000
@@ -26,6 +26,7 @@
 #include "img_format.h"
 #include "mp_image.h"
 #include "vf.h"
+#include "ve.h"
 
 extern const vf_info_t ve_info_lavc;
 extern const vf_info_t ve_info_vfw;
@@ -73,3 +74,56 @@
     char* vf_args[] = { "_oldargs_", args, NULL };
     return vf_open_plugin(encoder_list,next,name,vf_args);
 }
+
+static double *forced_key_frames_ts;
+static int forced_key_frames_number;
+static int forced_key_frames_idx;
+
+int parse_forced_key_frames(const m_option_t *opt, const char *arg)
+{
+    double ts;
+    const char *p;
+    int nts = 1, idx = 0, len;
+
+    for (p = arg; *p; p++)
+        nts += *p == ',';
+    free(forced_key_frames_ts);
+    forced_key_frames_ts = calloc(sizeof(*forced_key_frames_ts), nts);
+    p = arg;
+    while (1) {
+        len = parse_timestring(p, &ts, ',');
+        if (!len) {
+            mp_msg(MSGT_CFGPARSER, MSGL_ERR,
+                   "Option force-key-frames: invalid time: '%s'\n", p);
+            return M_OPT_INVALID;
+        }
+        forced_key_frames_ts[idx++] = ts;
+        if (!p[len])
+            break;
+        p += len + 1;
+    }
+    forced_key_frames_number = idx;
+    forced_key_frames_idx = 0;
+    for (idx = 1; idx < forced_key_frames_number; idx++) {
+        if (forced_key_frames_ts[idx - 1] >= forced_key_frames_ts[idx]) {
+            mp_msg(MSGT_CFGPARSER, MSGL_ERR, "Option force-key-frames: "
+                   "timestamps are not in ascending order\n");
+            return M_OPT_INVALID;
+        }
+    }
+    return 0;
+}
+
+int is_forced_key_frame(double pts)
+{
+    if (forced_key_frames_idx < forced_key_frames_number &&
+        pts >= forced_key_frames_ts[forced_key_frames_idx]) {
+        forced_key_frames_idx++;
+        if (forced_key_frames_idx >= forced_key_frames_number) {
+            free(forced_key_frames_ts);
+            forced_key_frames_number = 0;
+        }
+        return 1;
+    }
+    return 0;
+}
--- a/libmpcodecs/ve.h	Fri Oct 29 13:48:12 2010 +0000
+++ b/libmpcodecs/ve.h	Fri Oct 29 13:50:05 2010 +0000
@@ -31,4 +31,7 @@
 extern int   lavc_param_atag;
 extern int   lavc_param_audio_global_header;
 
+int parse_forced_key_frames(const m_option_t *opt, const char *arg);
+int is_forced_key_frame(double pts);
+
 #endif /* MPLAYER_VE_H */