From: Derek Buitenhuis <[email protected]>

When forwarding the frame type information, by default x264 can
decide which kind of keyframe output, add an option to force it
to output IDR frames in to support use-cases such as preparing
the content for segmented streams formats.
---
 libavcodec/libx264.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/libavcodec/libx264.c b/libavcodec/libx264.c
index a3d9484..76fa50b 100644
--- a/libavcodec/libx264.c
+++ b/libavcodec/libx264.c
@@ -78,6 +78,7 @@ typedef struct X264Context {
     int nal_hrd;
     int motion_est;
     int match_frame_type;
+    int forced_idr;
     char *x264_params;
 } X264Context;
 
@@ -248,7 +249,7 @@ static int X264_frame(AVCodecContext *ctx, AVPacket *pkt, 
const AVFrame *frame,
         if (x4->match_frame_type) {
             if ((x4->match_frame_type & MATCH_IFRAME) &&
                 frame->pict_type == AV_PICTURE_TYPE_I)
-                x4->pic.i_type = X264_TYPE_KEYFRAME;
+                x4->pic.i_type = (x4->forced_idr > 0) ? X264_TYPE_IDR : 
X264_TYPE_KEYFRAME;
             if ((x4->match_frame_type & MATCH_PFRAME) &&
                 frame->pict_type == AV_PICTURE_TYPE_P)
                 x4->pic.i_type = X264_TYPE_P;
@@ -711,6 +712,7 @@ static const AVOption options[] = {
     { "iframe",        NULL, 0, AV_OPT_TYPE_CONST, { .i64 = MATCH_IFRAME },  
INT_MIN, INT_MAX, VE, "match-frame" },
     { "pframe",        NULL, 0, AV_OPT_TYPE_CONST, { .i64 = MATCH_PFRAME },  
INT_MIN, INT_MAX, VE, "match-frame" },
     { "bframe",        NULL, 0, AV_OPT_TYPE_CONST, { .i64 = MATCH_BFRAME },  
INT_MIN, INT_MAX, VE, "match-frame" },
+    { "forced-idr",   "If forwarding iframes, require them to be 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 },
 };
-- 
2.5.0

_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel

Reply via email to