]> git.sesse.net Git - ffmpeg/commitdiff
libx264: Add option to force IDR frames
authorDerek Buitenhuis <derek.buitenhuis@gmail.com>
Tue, 18 Aug 2015 20:39:01 +0000 (17:39 -0300)
committerJames Almer <jamrial@gmail.com>
Tue, 18 Aug 2015 20:40:36 +0000 (17:40 -0300)
Currently, when forcing an I frame, via API, or via the ffmpeg cli,
using -force_key_frames, we still let x264 decide what sort of
keyframe to user. In some cases, it is useful to be able to force
an IDR frame, e.g. for cutting streams.

Signed-off-by: Derek Buitenhuis <derek.buitenhuis@gmail.com>
libavcodec/libx264.c
libavcodec/version.h

index c017685bb986d44ebc690ddf504d859204c1a341..a54743e4b452a248f3769cd766ceccd867ac4b3f 100644 (file)
@@ -82,6 +82,7 @@ typedef struct X264Context {
     int nal_hrd;
     int avcintra_class;
     int motion_est;
+    int forced_idr;
     char *x264_params;
 } X264Context;
 
@@ -270,7 +271,8 @@ static int X264_frame(AVCodecContext *ctx, AVPacket *pkt, const AVFrame *frame,
 
         x4->pic.i_pts  = frame->pts;
         x4->pic.i_type =
-            frame->pict_type == AV_PICTURE_TYPE_I ? X264_TYPE_KEYFRAME :
+            frame->pict_type == AV_PICTURE_TYPE_I ?
+                                (x4->forced_idr >= 0 ? X264_TYPE_IDR : X264_TYPE_KEYFRAME) :
             frame->pict_type == AV_PICTURE_TYPE_P ? X264_TYPE_P :
             frame->pict_type == AV_PICTURE_TYPE_B ? X264_TYPE_B :
                                             X264_TYPE_AUTO;
@@ -875,6 +877,7 @@ static const AVOption options[] = {
     { "umh",           NULL, 0, AV_OPT_TYPE_CONST, { .i64 = X264_ME_UMH },  INT_MIN, INT_MAX, VE, "motion-est" },
     { "esa",           NULL, 0, AV_OPT_TYPE_CONST, { .i64 = X264_ME_ESA },  INT_MIN, INT_MAX, VE, "motion-est" },
     { "tesa",          NULL, 0, AV_OPT_TYPE_CONST, { .i64 = X264_ME_TESA }, INT_MIN, INT_MAX, VE, "motion-est" },
+    { "forced-idr",   "If forcing keyframes, force them as IDR frames.",                                  OFFSET(forced_idr),  AV_OPT_TYPE_INT,    { .i64 = -1 }, -1, 1, VE },
     { "x264-params",  "Override the x264 configuration using a :-separated list of key=value parameters", OFFSET(x264_params), AV_OPT_TYPE_STRING, { 0 }, 0, 0, VE },
     { NULL },
 };
index 1b37a9e68a6cd5acad60b0556582d6d7d9e8f212..2e7cf409617d1074017a0bef5d07fa0a19ab1053 100644 (file)
@@ -30,7 +30,7 @@
 
 #define LIBAVCODEC_VERSION_MAJOR 56
 #define LIBAVCODEC_VERSION_MINOR  57
-#define LIBAVCODEC_VERSION_MICRO 100
+#define LIBAVCODEC_VERSION_MICRO 101
 
 #define LIBAVCODEC_VERSION_INT  AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
                                                LIBAVCODEC_VERSION_MINOR, \