Commit 38014692 authored by Derek Buitenhuis's avatar Derek Buitenhuis Committed by Luca Barbato

x264: Add option to force IDR frames

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.
parent eb02387a
...@@ -77,6 +77,7 @@ typedef struct X264Context { ...@@ -77,6 +77,7 @@ typedef struct X264Context {
char *stats; char *stats;
int nal_hrd; int nal_hrd;
int motion_est; int motion_est;
int forced_idr;
char *x264_params; char *x264_params;
} X264Context; } X264Context;
...@@ -235,11 +236,22 @@ static int X264_frame(AVCodecContext *ctx, AVPacket *pkt, const AVFrame *frame, ...@@ -235,11 +236,22 @@ static int X264_frame(AVCodecContext *ctx, AVPacket *pkt, const AVFrame *frame,
} }
x4->pic.i_pts = frame->pts; x4->pic.i_pts = frame->pts;
x4->pic.i_type =
frame->pict_type == AV_PICTURE_TYPE_I ? X264_TYPE_KEYFRAME : switch (frame->pict_type) {
frame->pict_type == AV_PICTURE_TYPE_P ? X264_TYPE_P : case AV_PICTURE_TYPE_I:
frame->pict_type == AV_PICTURE_TYPE_B ? X264_TYPE_B : x4->pic.i_type = x4->forced_idr ? X264_TYPE_IDR
X264_TYPE_AUTO; : X264_TYPE_KEYFRAME;
break;
case AV_PICTURE_TYPE_P:
x4->pic.i_type = X264_TYPE_P;
break;
case AV_PICTURE_TYPE_B:
x4->pic.i_type = X264_TYPE_B;
break;
default:
x4->pic.i_type = X264_TYPE_AUTO;
break;
}
reconfig_encoder(ctx, frame); reconfig_encoder(ctx, frame);
} }
do { do {
...@@ -696,6 +708,7 @@ static const AVOption options[] = { ...@@ -696,6 +708,7 @@ static const AVOption options[] = {
{ "umh", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = X264_ME_UMH }, INT_MIN, INT_MAX, VE, "motion-est" }, { "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" }, { "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" }, { "tesa", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = X264_ME_TESA }, INT_MIN, INT_MAX, VE, "motion-est" },
{ "forced-idr", "If forwarding iframes, require them to be IDR frames.", OFFSET(forced_idr), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 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 }, { "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 }, { NULL },
}; };
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment