[FFmpeg-cvslog] libavfilter: add transpose_vaapi filter
ffmpeg | branch: master | Zachary Zhou | Thu Jan 17 11:33:05 2019 +0800| [b8ebce4f84b653b8a50a23398e3d12a607b5cddb] | committer: Mark Thompson libavfilter: add transpose_vaapi filter Swap width and height when do clock/cclock rotation Add reversal/hflip/vflip options ffmpeg -hwaccel vaapi -vaapi_device /dev/dri/renderD128 -hwaccel_output_format vaapi -i input.264 -vf "transpose_vaapi=clock_flip" -c:v h264_vaapi output.h264 Signed-off-by: Zachary Zhou Signed-off-by: Mark Thompson > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=b8ebce4f84b653b8a50a23398e3d12a607b5cddb --- configure| 2 + libavfilter/Makefile | 1 + libavfilter/allfilters.c | 1 + libavfilter/transpose.h | 3 + libavfilter/vf_transpose_vaapi.c | 319 +++ 5 files changed, 326 insertions(+) diff --git a/configure b/configure index c2b8fac0ed..e1412352fa 100755 --- a/configure +++ b/configure @@ -3483,6 +3483,7 @@ tinterlace_pad_test_deps="tinterlace_filter" tonemap_filter_deps="const_nan" tonemap_opencl_filter_deps="opencl const_nan" transpose_opencl_filter_deps="opencl" +transpose_vaapi_filter_deps="vaapi VAProcPipelineCaps_rotation_flags" unsharp_opencl_filter_deps="opencl" uspp_filter_deps="gpl avcodec" vaguedenoiser_filter_deps="gpl" @@ -5986,6 +5987,7 @@ check_type "d3d9.h dxva2api.h" DXVA2_ConfigPictureDecode -D_WIN32_WINNT=0x0602 check_type "va/va.h va/va_dec_hevc.h" "VAPictureParameterBufferHEVC" check_struct "va/va.h" "VADecPictureParameterBufferVP9" bit_depth +check_struct "va/va.h va/va_vpp.h" "VAProcPipelineCaps" rotation_flags check_type "va/va.h va/va_enc_hevc.h" "VAEncPictureParameterBufferHEVC" check_type "va/va.h va/va_enc_jpeg.h" "VAEncPictureParameterBufferJPEG" check_type "va/va.h va/va_enc_vp8.h" "VAEncPictureParameterBufferVP8" diff --git a/libavfilter/Makefile b/libavfilter/Makefile index 8283389f6e..bc642acb01 100644 --- a/libavfilter/Makefile +++ b/libavfilter/Makefile @@ -396,6 +396,7 @@ OBJS-$(CONFIG_TPAD_FILTER) += vf_tpad.o OBJS-$(CONFIG_TRANSPOSE_FILTER) += vf_transpose.o OBJS-$(CONFIG_TRANSPOSE_NPP_FILTER) += vf_transpose_npp.o cuda_check.o OBJS-$(CONFIG_TRANSPOSE_OPENCL_FILTER) += vf_transpose_opencl.o opencl.o opencl/transpose.o +OBJS-$(CONFIG_TRANSPOSE_VAAPI_FILTER)+= vf_transpose_vaapi.o vaapi_vpp.o OBJS-$(CONFIG_TRIM_FILTER) += trim.o OBJS-$(CONFIG_UNPREMULTIPLY_FILTER) += vf_premultiply.o framesync.o OBJS-$(CONFIG_UNSHARP_FILTER)+= vf_unsharp.o diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c index b91cff2ce7..c51ae0f3c7 100644 --- a/libavfilter/allfilters.c +++ b/libavfilter/allfilters.c @@ -375,6 +375,7 @@ extern AVFilter ff_vf_tpad; extern AVFilter ff_vf_transpose; extern AVFilter ff_vf_transpose_npp; extern AVFilter ff_vf_transpose_opencl; +extern AVFilter ff_vf_transpose_vaapi; extern AVFilter ff_vf_trim; extern AVFilter ff_vf_unpremultiply; extern AVFilter ff_vf_unsharp; diff --git a/libavfilter/transpose.h b/libavfilter/transpose.h index d4bb4da1ae..aa262b9487 100644 --- a/libavfilter/transpose.h +++ b/libavfilter/transpose.h @@ -29,6 +29,9 @@ enum TransposeDir { TRANSPOSE_CLOCK, TRANSPOSE_CCLOCK, TRANSPOSE_CLOCK_FLIP, +TRANSPOSE_REVERSAL,// rotate by half-turn +TRANSPOSE_HFLIP, +TRANSPOSE_VFLIP, }; #endif diff --git a/libavfilter/vf_transpose_vaapi.c b/libavfilter/vf_transpose_vaapi.c new file mode 100644 index 00..0e2acc9983 --- /dev/null +++ b/libavfilter/vf_transpose_vaapi.c @@ -0,0 +1,319 @@ +/* + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ +#include + +#include "libavutil/avassert.h" +#include "libavutil/mem.h" +#include "libavutil/opt.h" +#include "libavutil/pixdesc.h" + +#include "avfilter.h" +#include "formats.h" +#include "internal.h" +#include "transpose.h" +#include "vaapi_vpp.h" + +typedef struct TransposeVAAPIContext { +VAAPIVPPContext vpp_ctx; // must be the first field +int passthrough; // PassthroughType, landscape passthrough mode enabled +int dir; // TransposeDir + +int rotation_state; +int mirror_state; +} TransposeVAAP
[FFmpeg-cvslog] vaapi_encode_h264: Support more complex reference structures
ffmpeg | branch: master | Mark Thompson | Thu Dec 20 20:39:58 2018 +| [25c0ede93b9cb3542e631d6e449d50aa3fb1c2e8] | committer: Mark Thompson vaapi_encode_h264: Support more complex reference structures > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=25c0ede93b9cb3542e631d6e449d50aa3fb1c2e8 --- libavcodec/vaapi_encode_h264.c | 375 + 1 file changed, 309 insertions(+), 66 deletions(-) diff --git a/libavcodec/vaapi_encode_h264.c b/libavcodec/vaapi_encode_h264.c index 684c8ed96f..4ea62d96f3 100644 --- a/libavcodec/vaapi_encode_h264.c +++ b/libavcodec/vaapi_encode_h264.c @@ -47,6 +47,20 @@ static const uint8_t vaapi_encode_h264_sei_identifier_uuid[16] = { 0x96, 0x75, 0x19, 0xd4, 0x1f, 0xea, 0xa9, 0x4d, }; +typedef struct VAAPIEncodeH264Picture { +int frame_num; +int pic_order_cnt; + +int64_t last_idr_frame; +uint16_t idr_pic_id; + +int primary_pic_type; +int slice_type; + +int cpb_delay; +int dpb_delay; +} VAAPIEncodeH264Picture; + typedef struct VAAPIEncodeH264Context { VAAPIEncodeContext common; @@ -67,18 +81,7 @@ typedef struct VAAPIEncodeH264Context { int fixed_qp_p; int fixed_qp_b; -// Stream state. -int frame_num; -int pic_order_cnt; -int next_frame_num; -int64_t last_idr_frame; -int64_t idr_pic_count; - -int primary_pic_type; -int slice_type; - -int cpb_delay; -int dpb_delay; +int dpb_frames; // Writer structures. CodedBitstreamContext *cbc; @@ -295,7 +298,6 @@ static int vaapi_encode_h264_init_sequence_params(AVCodecContext *avctx) H264RawPPS*pps = &priv->raw_pps; VAEncSequenceParameterBufferH264 *vseq = ctx->codec_sequence_params; VAEncPictureParameterBufferH264 *vpic = ctx->codec_picture_params; -int dpb_frames; memset(&priv->current_access_unit, 0, sizeof(priv->current_access_unit)); @@ -322,9 +324,9 @@ static int vaapi_encode_h264_init_sequence_params(AVCodecContext *avctx) } if (ctx->gop_size == 1) -dpb_frames = 0; +priv->dpb_frames = 0; else -dpb_frames = 1 + (ctx->b_per_p > 0); +priv->dpb_frames = 1 + ctx->max_b_depth; if (avctx->level != FF_LEVEL_UNKNOWN) { sps->level_idc = avctx->level; @@ -335,7 +337,7 @@ static int vaapi_encode_h264_init_sequence_params(AVCodecContext *avctx) avctx->bit_rate, priv->mb_width * 16, priv->mb_height * 16, -dpb_frames); +priv->dpb_frames); if (level) { av_log(avctx, AV_LOG_VERBOSE, "Using level %s.\n", level->name); if (level->constraint_set3_flag) @@ -353,10 +355,9 @@ static int vaapi_encode_h264_init_sequence_params(AVCodecContext *avctx) sps->log2_max_frame_num_minus4 = 4; sps->pic_order_cnt_type= 0; -sps->log2_max_pic_order_cnt_lsb_minus4 = -av_clip(av_log2(ctx->b_per_p + 1) - 2, 0, 12); +sps->log2_max_pic_order_cnt_lsb_minus4 = 4; -sps->max_num_ref_frames = dpb_frames; +sps->max_num_ref_frames = priv->dpb_frames; sps->pic_width_in_mbs_minus1= priv->mb_width - 1; sps->pic_height_in_map_units_minus1 = priv->mb_height - 1; @@ -495,8 +496,8 @@ static int vaapi_encode_h264_init_sequence_params(AVCodecContext *avctx) sps->vui.motion_vectors_over_pic_boundaries_flag = 1; sps->vui.log2_max_mv_length_horizontal = 15; sps->vui.log2_max_mv_length_vertical = 15; -sps->vui.max_num_reorder_frames= (ctx->b_per_p > 0); -sps->vui.max_dec_frame_buffering = sps->max_num_ref_frames; +sps->vui.max_num_reorder_frames= ctx->max_b_depth; +sps->vui.max_dec_frame_buffering = ctx->max_b_depth + 1; pps->nal_unit_header.nal_ref_idc = 3; pps->nal_unit_header.nal_unit_type = H264_NAL_PPS; @@ -617,7 +618,9 @@ static int vaapi_encode_h264_init_picture_params(AVCodecContext *avctx, { VAAPIEncodeContext *ctx = avctx->priv_data; VAAPIEncodeH264Context *priv = avctx->priv_data; -H264RawSPS *sps = &priv->raw_sps; +VAAPIEncodeH264Picture *hpic = pic->priv_data; +VAAPIEncodePicture *prev = pic->prev; +VAAPIEncodeH264Picture *hprev = prev ? prev->priv_data : NULL; VAEncPictureParameterBufferH264 *vpic = pic->codec_picture_params; int i; @@ -626,37 +629,35 @@ static int vaapi_encode_h264_init_picture_params(AVCodecContext *avctx, if (pic->type == PICTURE_TYPE_IDR) { av_assert0(pic->display_order == pic->encode_order); -priv->frame_num = 0; -priv->next_frame_num = 1; -priv->cpb_delay = 0; -priv->last_idr_frame = pic->display_order; -++priv->idr_pic_count; - -
[FFmpeg-cvslog] vaapi_encode_h265: Support more complex reference structures
ffmpeg | branch: master | Mark Thompson | Thu Dec 20 20:39:59 2018 +| [362992e94bccca225d180e791f7e24858efb857d] | committer: Mark Thompson vaapi_encode_h265: Support more complex reference structures The reference picture sets are now constructed directly from the DPB information. > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=362992e94bccca225d180e791f7e24858efb857d --- libavcodec/vaapi_encode_h265.c | 191 - 1 file changed, 111 insertions(+), 80 deletions(-) diff --git a/libavcodec/vaapi_encode_h265.c b/libavcodec/vaapi_encode_h265.c index 58005c03a3..1d40e06667 100644 --- a/libavcodec/vaapi_encode_h265.c +++ b/libavcodec/vaapi_encode_h265.c @@ -42,6 +42,16 @@ enum { SEI_CONTENT_LIGHT_LEVEL = 0x10, }; +typedef struct VAAPIEncodeH265Picture { +int pic_order_cnt; + +int64_t last_idr_frame; + +int slice_nal_unit; +int slice_type; +int pic_type; +} VAAPIEncodeH265Picture; + typedef struct VAAPIEncodeH265Context { VAAPIEncodeContext common; @@ -58,14 +68,6 @@ typedef struct VAAPIEncodeH265Context { int fixed_qp_p; int fixed_qp_b; -// Stream state. -int64_t last_idr_frame; -int pic_order_cnt; - -int slice_nal_unit; -int slice_type; -int pic_type; - // Writer structures. H265RawAUD raw_aud; H265RawVPS raw_vps; @@ -361,8 +363,8 @@ static int vaapi_encode_h265_init_sequence_params(AVCodecContext *avctx) } vps->vps_sub_layer_ordering_info_present_flag = 0; -vps->vps_max_dec_pic_buffering_minus1[0] = (ctx->b_per_p > 0) + 1; -vps->vps_max_num_reorder_pics[0] = (ctx->b_per_p > 0); +vps->vps_max_dec_pic_buffering_minus1[0] = ctx->max_b_depth + 1; +vps->vps_max_num_reorder_pics[0] = ctx->max_b_depth; vps->vps_max_latency_increase_plus1[0]= 0; vps->vps_max_layer_id = 0; @@ -673,41 +675,54 @@ static int vaapi_encode_h265_init_sequence_params(AVCodecContext *avctx) static int vaapi_encode_h265_init_picture_params(AVCodecContext *avctx, VAAPIEncodePicture *pic) { +VAAPIEncodeContext *ctx = avctx->priv_data; VAAPIEncodeH265Context *priv = avctx->priv_data; +VAAPIEncodeH265Picture *hpic = pic->priv_data; +VAAPIEncodePicture *prev = pic->prev; +VAAPIEncodeH265Picture *hprev = prev ? prev->priv_data : NULL; VAEncPictureParameterBufferHEVC *vpic = pic->codec_picture_params; int i; if (pic->type == PICTURE_TYPE_IDR) { av_assert0(pic->display_order == pic->encode_order); -priv->last_idr_frame = pic->display_order; +hpic->last_idr_frame = pic->display_order; -priv->slice_nal_unit = HEVC_NAL_IDR_W_RADL; -priv->slice_type = HEVC_SLICE_I; -priv->pic_type = 0; +hpic->slice_nal_unit = HEVC_NAL_IDR_W_RADL; +hpic->slice_type = HEVC_SLICE_I; +hpic->pic_type = 0; } else { -av_assert0(pic->encode_order > priv->last_idr_frame); +av_assert0(prev); +hpic->last_idr_frame = hprev->last_idr_frame; if (pic->type == PICTURE_TYPE_I) { -priv->slice_nal_unit = HEVC_NAL_CRA_NUT; -priv->slice_type = HEVC_SLICE_I; -priv->pic_type = 0; +hpic->slice_nal_unit = HEVC_NAL_CRA_NUT; +hpic->slice_type = HEVC_SLICE_I; +hpic->pic_type = 0; } else if (pic->type == PICTURE_TYPE_P) { av_assert0(pic->refs[0]); -priv->slice_nal_unit = HEVC_NAL_TRAIL_R; -priv->slice_type = HEVC_SLICE_P; -priv->pic_type = 1; +hpic->slice_nal_unit = HEVC_NAL_TRAIL_R; +hpic->slice_type = HEVC_SLICE_P; +hpic->pic_type = 1; } else { +VAAPIEncodePicture *irap_ref; av_assert0(pic->refs[0] && pic->refs[1]); -if (pic->refs[1]->type == PICTURE_TYPE_I) -priv->slice_nal_unit = HEVC_NAL_RASL_N; -else -priv->slice_nal_unit = HEVC_NAL_TRAIL_N; -priv->slice_type = HEVC_SLICE_B; -priv->pic_type = 2; +for (irap_ref = pic; irap_ref; irap_ref = irap_ref->refs[1]) { +if (irap_ref->type == PICTURE_TYPE_I) +break; +} +if (pic->b_depth == ctx->max_b_depth) { +hpic->slice_nal_unit = irap_ref ? HEVC_NAL_RASL_N +: HEVC_NAL_TRAIL_N; +} else { +hpic->slice_nal_unit = irap_ref ? HEVC_NAL_RASL_R +: HEVC_NAL_TRAIL_R; +} +hpic->slice_type = HEVC_SLICE_B; +hpic->pic_type = 2; } } -priv->pic_order_cnt = pic->disp
[FFmpeg-cvslog] vaapi_encode_vp9: Support more complex reference structures
ffmpeg | branch: master | Mark Thompson | Thu Dec 20 20:40:00 2018 +| [916b3b9079f783f0e00823e19bba85fa0f7d012f] | committer: Mark Thompson vaapi_encode_vp9: Support more complex reference structures > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=916b3b9079f783f0e00823e19bba85fa0f7d012f --- libavcodec/vaapi_encode_vp9.c | 104 +- 1 file changed, 51 insertions(+), 53 deletions(-) diff --git a/libavcodec/vaapi_encode_vp9.c b/libavcodec/vaapi_encode_vp9.c index 94f29c0483..97142dcc49 100644 --- a/libavcodec/vaapi_encode_vp9.c +++ b/libavcodec/vaapi_encode_vp9.c @@ -32,6 +32,10 @@ #define VP9_MAX_QUANT 255 +typedef struct VAAPIEncodeVP9Picture { +int slot; +} VAAPIEncodeVP9Picture; + typedef struct VAAPIEncodeVP9Context { VAAPIEncodeContext common; @@ -43,22 +47,9 @@ typedef struct VAAPIEncodeVP9Context { int q_idx_idr; int q_idx_p; int q_idx_b; - -// Stream state. - -// Reference direction for B-like frames: -// 0 - most recent P/IDR frame is last. -// 1 - most recent P frame is golden. -int last_ref_dir; } VAAPIEncodeVP9Context; -#define vseq_var(name) vseq->name, name -#define vseq_field(name) vseq->seq_fields.bits.name, name -#define vpic_var(name) vpic->name, name -#define vpic_field(name) vpic->pic_fields.bits.name, name - - static int vaapi_encode_vp9_init_sequence_params(AVCodecContext *avctx) { VAAPIEncodeContext *ctx = avctx->priv_data; @@ -88,6 +79,7 @@ static int vaapi_encode_vp9_init_picture_params(AVCodecContext *avctx, { VAAPIEncodeContext *ctx = avctx->priv_data; VAAPIEncodeVP9Context *priv = avctx->priv_data; +VAAPIEncodeVP9Picture *hpic = pic->priv_data; VAEncPictureParameterBufferVP9 *vpic = pic->codec_picture_params; int i; @@ -98,65 +90,71 @@ static int vaapi_encode_vp9_init_picture_params(AVCodecContext *avctx, case PICTURE_TYPE_IDR: av_assert0(pic->nb_refs == 0); vpic->ref_flags.bits.force_kf = 1; -vpic->refresh_frame_flags = 0x01; -priv->last_ref_dir = 0; +vpic->refresh_frame_flags = 0xff; +hpic->slot = 0; break; case PICTURE_TYPE_P: av_assert0(pic->nb_refs == 1); -if (ctx->b_per_p > 0) { -if (priv->last_ref_dir) { -vpic->ref_flags.bits.ref_frame_ctrl_l0 = 2; -vpic->ref_flags.bits.ref_gf_idx = 1; -vpic->ref_flags.bits.ref_gf_sign_bias = 1; -vpic->refresh_frame_flags = 0x01; +{ +VAAPIEncodeVP9Picture *href = pic->refs[0]->priv_data; +av_assert0(href->slot == 0 || href->slot == 1); + +if (ctx->max_b_depth > 0) { +hpic->slot = !href->slot; +vpic->refresh_frame_flags = 1 << hpic->slot | 0xfc; } else { -vpic->ref_flags.bits.ref_frame_ctrl_l0 = 1; -vpic->ref_flags.bits.ref_last_idx = 0; -vpic->ref_flags.bits.ref_last_sign_bias = 1; -vpic->refresh_frame_flags = 0x02; +hpic->slot = 0; +vpic->refresh_frame_flags = 0xff; } -} else { vpic->ref_flags.bits.ref_frame_ctrl_l0 = 1; -vpic->ref_flags.bits.ref_last_idx = 0; +vpic->ref_flags.bits.ref_last_idx = href->slot; vpic->ref_flags.bits.ref_last_sign_bias = 1; -vpic->refresh_frame_flags = 0x01; } break; case PICTURE_TYPE_B: av_assert0(pic->nb_refs == 2); -if (priv->last_ref_dir) { +{ +VAAPIEncodeVP9Picture *href0 = pic->refs[0]->priv_data, + *href1 = pic->refs[1]->priv_data; +av_assert0(href0->slot < pic->b_depth + 1 && + href1->slot < pic->b_depth + 1); + +if (pic->b_depth == ctx->max_b_depth) { +// Unreferenced frame. +vpic->refresh_frame_flags = 0x00; +hpic->slot = 8; +} else { +vpic->refresh_frame_flags = 0xfe << pic->b_depth & 0xff; +hpic->slot = 1 + pic->b_depth; +} vpic->ref_flags.bits.ref_frame_ctrl_l0 = 1; vpic->ref_flags.bits.ref_frame_ctrl_l1 = 2; -vpic->ref_flags.bits.ref_last_idx = 0; +vpic->ref_flags.bits.ref_last_idx = href0->slot; vpic->ref_flags.bits.ref_last_sign_bias = 1; -vpic->ref_flags.bits.ref_gf_idx = 1; +vpic->ref_flags.bits.ref_gf_idx = href1->slot; vpic->ref_flags.bits.ref_gf_sign_bias = 0; -} else { -vpic->ref_flags.bits.ref_frame_ctrl_l0 = 2; -vpic->ref_flags.bits.ref_frame_ctrl_l1 = 1; -vpic->ref_flags.bits.ref_last_idx = 0; -
[FFmpeg-cvslog] vaapi_encode: Allocate picture-private data in generic code
ffmpeg | branch: master | Mark Thompson | Thu Dec 20 20:39:55 2018 +| [26ce3a43a35fe3a43c895945252aa22c6b46ffb7] | committer: Mark Thompson vaapi_encode: Allocate picture-private data in generic code > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=26ce3a43a35fe3a43c895945252aa22c6b46ffb7 --- libavcodec/vaapi_encode.c | 15 --- libavcodec/vaapi_encode.h | 4 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/libavcodec/vaapi_encode.c b/libavcodec/vaapi_encode.c index eda8a36299..d8bedbe162 100644 --- a/libavcodec/vaapi_encode.c +++ b/libavcodec/vaapi_encode.c @@ -570,14 +570,23 @@ static int vaapi_encode_discard(AVCodecContext *avctx, return 0; } -static VAAPIEncodePicture *vaapi_encode_alloc(void) +static VAAPIEncodePicture *vaapi_encode_alloc(AVCodecContext *avctx) { +VAAPIEncodeContext *ctx = avctx->priv_data; VAAPIEncodePicture *pic; pic = av_mallocz(sizeof(*pic)); if (!pic) return NULL; +if (ctx->codec->picture_priv_data_size > 0) { +pic->priv_data = av_mallocz(ctx->codec->picture_priv_data_size); +if (!pic->priv_data) { +av_freep(&pic); +return NULL; +} +} + pic->input_surface = VA_INVALID_ID; pic->recon_surface = VA_INVALID_ID; pic->output_buffer = VA_INVALID_ID; @@ -710,7 +719,7 @@ static int vaapi_encode_get_next(AVCodecContext *avctx, } } -pic = vaapi_encode_alloc(); +pic = vaapi_encode_alloc(avctx); if (!pic) return AVERROR(ENOMEM); @@ -739,7 +748,7 @@ static int vaapi_encode_get_next(AVCodecContext *avctx, for (i = 0; i < ctx->b_per_p && ctx->gop_counter < ctx->gop_size; i++) { -pic = vaapi_encode_alloc(); +pic = vaapi_encode_alloc(avctx); if (!pic) goto fail; diff --git a/libavcodec/vaapi_encode.h b/libavcodec/vaapi_encode.h index 965fe65c0b..6204c5171f 100644 --- a/libavcodec/vaapi_encode.h +++ b/libavcodec/vaapi_encode.h @@ -268,6 +268,10 @@ typedef struct VAAPIEncodeType { // add any necessary global parameters). int (*configure)(AVCodecContext *avctx); +// The size of any private data structure associated with each +// picture (can be zero if not required). +size_t picture_priv_data_size; + // The size of the parameter structures: // sizeof(VAEnc{type}ParameterBuffer{codec}). size_t sequence_params_size; ___ ffmpeg-cvslog mailing list ffmpeg-cvslog@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog
[FFmpeg-cvslog] vaapi_encode: Convert to send/receive API
ffmpeg | branch: master | Mark Thompson | Thu Dec 20 20:39:56 2018 +| [5fdcf85bbffe7451c227478fda62da5c0938f27d] | committer: Mark Thompson vaapi_encode: Convert to send/receive API This attaches the logic of picking the mode of for the next picture to the output, which simplifies some choices by removing the concept of the picture for which input is not yet available. At the same time, we allow more complex reference structures and track more reference metadata (particularly the contents of the DPB) for use in the codec-specific code. It also adds flags to explicitly track the available features of the different codecs. The new structure also allows open-GOP support, so that is now available for codecs which can do it. > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=5fdcf85bbffe7451c227478fda62da5c0938f27d --- doc/encoders.texi | 19 +- libavcodec/vaapi_encode.c | 635 +--- libavcodec/vaapi_encode.h | 74 - libavcodec/vaapi_encode_h264.c | 7 +- libavcodec/vaapi_encode_h265.c | 7 +- libavcodec/vaapi_encode_mjpeg.c | 9 +- libavcodec/vaapi_encode_mpeg2.c | 5 +- libavcodec/vaapi_encode_vp8.c | 3 +- libavcodec/vaapi_encode_vp9.c | 5 +- 9 files changed, 433 insertions(+), 331 deletions(-) diff --git a/doc/encoders.texi b/doc/encoders.texi index 0a85c191e3..e86ae69cc5 100644 --- a/doc/encoders.texi +++ b/doc/encoders.texi @@ -2807,15 +2807,24 @@ Size / quality tradeoff: higher values are smaller / worse quality. @end itemize All encoders support the following options: -@itemize -@item -@option{low_power} - +@table @option +@item low_power Some drivers/platforms offer a second encoder for some codecs intended to use less power than the default encoder; setting this option will attempt to use that encoder. Note that it may support a reduced feature set, so some other options may not be available in this mode. -@end itemize + +@item idr_interval +Set the number of normal intra frames between full-refresh (IDR) frames in +open-GOP mode. The intra frames are still IRAPs, but will not include global +headers and may have non-decodable leading pictures. + +@item b_depth +Set the B-frame reference depth. When set to one (the default), all B-frames +will refer only to P- or I-frames. When set to greater values multiple layers +of B-frames will be present, frames in each layer only referring to frames in +higher layers. +@end table Each encoder also has its own specific options: @table @option diff --git a/libavcodec/vaapi_encode.c b/libavcodec/vaapi_encode.c index d8bedbe162..eec083da4f 100644 --- a/libavcodec/vaapi_encode.c +++ b/libavcodec/vaapi_encode.c @@ -158,16 +158,10 @@ static int vaapi_encode_issue(AVCodecContext *avctx, av_log(avctx, AV_LOG_DEBUG, ".\n"); } -av_assert0(pic->input_available && !pic->encode_issued); +av_assert0(!pic->encode_issued); for (i = 0; i < pic->nb_refs; i++) { av_assert0(pic->refs[i]); -// If we are serialised then the references must have already -// completed. If not, they must have been issued but need not -// have completed yet. -if (ctx->issue_mode == ISSUE_MODE_SERIALISE_EVERYTHING) -av_assert0(pic->refs[i]->encode_complete); -else -av_assert0(pic->refs[i]->encode_issued); +av_assert0(pic->refs[i]->encode_issued); } av_log(avctx, AV_LOG_DEBUG, "Input surface is %#x.\n", pic->input_surface); @@ -466,10 +460,7 @@ static int vaapi_encode_issue(AVCodecContext *avctx, pic->encode_issued = 1; -if (ctx->issue_mode == ISSUE_MODE_SERIALISE_EVERYTHING) -return vaapi_encode_wait(avctx, pic); -else -return 0; +return 0; fail_with_picture: vaEndPicture(ctx->hwctx->display, ctx->va_context); @@ -626,315 +617,330 @@ static int vaapi_encode_free(AVCodecContext *avctx, return 0; } -static int vaapi_encode_step(AVCodecContext *avctx, - VAAPIEncodePicture *target) +static void vaapi_encode_add_ref(AVCodecContext *avctx, + VAAPIEncodePicture *pic, + VAAPIEncodePicture *target, + int is_ref, int in_dpb, int prev) { -VAAPIEncodeContext *ctx = avctx->priv_data; -VAAPIEncodePicture *pic; -int i, err; +int refs = 0; -if (ctx->issue_mode == ISSUE_MODE_SERIALISE_EVERYTHING || -ctx->issue_mode == ISSUE_MODE_MINIMISE_LATENCY) { -// These two modes are equivalent, except that we wait for -// immediate completion on each operation if serialised. - -if (!target) { -// No target, nothing to do yet. -return 0; -} - -if (target->encode_complete) { -// Already done. -return 0; -} - -pic = target; -for (i = 0; i < pic->nb_refs; i++) { -i
[FFmpeg-cvslog] vaapi_encode: Let the reconstructed frame pool be sized dynamically
ffmpeg | branch: master | Mark Thompson | Thu Dec 20 20:39:57 2018 +| [494bd8df782efe53e85de8ce258a079cea4eca72] | committer: Mark Thompson vaapi_encode: Let the reconstructed frame pool be sized dynamically No supported encode driver requires the pool to be fixed-size, so just remove this constraint. > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=494bd8df782efe53e85de8ce258a079cea4eca72 --- libavcodec/vaapi_encode.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/libavcodec/vaapi_encode.c b/libavcodec/vaapi_encode.c index eec083da4f..b4e9fadaee 100644 --- a/libavcodec/vaapi_encode.c +++ b/libavcodec/vaapi_encode.c @@ -1867,9 +1867,6 @@ static av_cold int vaapi_encode_create_recon_frames(AVCodecContext *avctx) ctx->recon_frames->sw_format = recon_format; ctx->recon_frames->width = ctx->surface_width; ctx->recon_frames->height= ctx->surface_height; -// At most three IDR/I/P frames and two runs of B frames can be in -// flight at any one time. -ctx->recon_frames->initial_pool_size = 3 + 2 * ctx->b_per_p; err = av_hwframe_ctx_init(ctx->recon_frames_ref); if (err < 0) { ___ ffmpeg-cvslog mailing list ffmpeg-cvslog@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog
[FFmpeg-cvslog] cbs_h2645: Avoid memcpy when splitting fragment #2
ffmpeg | branch: master | Andreas Rheinhardt | Wed Nov 28 01:24:10 2018 +0100| [8ca55a2b9e95e79956ae0a9069f08e72c63fde16] | committer: Mark Thompson cbs_h2645: Avoid memcpy when splitting fragment #2 Now memcpy can be avoided for NAL units containing escapes, too. Particularly improves performance for files with hardcoded black bars. For such a file, time spent in cbs_h2645_split_fragment went down from 369410 decicycles to 327677 decicycles. (It were 379114 decicycles when every NAL unit was copied.) Signed-off-by: Andreas Rheinhardt > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=8ca55a2b9e95e79956ae0a9069f08e72c63fde16 --- libavcodec/cbs_h2645.c | 33 +++-- 1 file changed, 11 insertions(+), 22 deletions(-) diff --git a/libavcodec/cbs_h2645.c b/libavcodec/cbs_h2645.c index 574a53a60a..e74f8dce81 100644 --- a/libavcodec/cbs_h2645.c +++ b/libavcodec/cbs_h2645.c @@ -531,6 +531,7 @@ static int cbs_h2645_fragment_add_nals(CodedBitstreamContext *ctx, for (i = 0; i < packet->nb_nals; i++) { const H2645NAL *nal = &packet->nals[i]; +AVBufferRef *ref; size_t size = nal->size; // Remove trailing zeroes. @@ -538,25 +539,13 @@ static int cbs_h2645_fragment_add_nals(CodedBitstreamContext *ctx, --size; av_assert0(size > 0); -if (nal->data == nal->raw_data) { -err = ff_cbs_insert_unit_data(ctx, frag, -1, nal->type, -(uint8_t*)nal->data, size, frag->data_ref); -if (err < 0) -return err; -} else { -uint8_t *data = av_malloc(size + AV_INPUT_BUFFER_PADDING_SIZE); -if (!data) -return AVERROR(ENOMEM); -memcpy(data, nal->data, size); -memset(data + size, 0, AV_INPUT_BUFFER_PADDING_SIZE); +ref = (nal->data == nal->raw_data) ? frag->data_ref + : packet->rbsp.rbsp_buffer_ref; -err = ff_cbs_insert_unit_data(ctx, frag, -1, nal->type, - data, size, NULL); -if (err < 0) { -av_freep(&data); -return err; -} -} +err = ff_cbs_insert_unit_data(ctx, frag, -1, nal->type, +(uint8_t*)nal->data, size, ref); +if (err < 0) +return err; } return 0; @@ -612,7 +601,7 @@ static int cbs_h2645_split_fragment(CodedBitstreamContext *ctx, err = ff_h2645_packet_split(&priv->read_packet, frag->data + start, end - start, -ctx->log_ctx, 1, 2, AV_CODEC_ID_H264, 1, 0); +ctx->log_ctx, 1, 2, AV_CODEC_ID_H264, 1, 1); if (err < 0) { av_log(ctx->log_ctx, AV_LOG_ERROR, "Failed to split AVCC SPS array.\n"); return err; @@ -636,7 +625,7 @@ static int cbs_h2645_split_fragment(CodedBitstreamContext *ctx, err = ff_h2645_packet_split(&priv->read_packet, frag->data + start, end - start, -ctx->log_ctx, 1, 2, AV_CODEC_ID_H264, 1, 0); +ctx->log_ctx, 1, 2, AV_CODEC_ID_H264, 1, 1); if (err < 0) { av_log(ctx->log_ctx, AV_LOG_ERROR, "Failed to split AVCC PPS array.\n"); return err; @@ -690,7 +679,7 @@ static int cbs_h2645_split_fragment(CodedBitstreamContext *ctx, err = ff_h2645_packet_split(&priv->read_packet, frag->data + start, end - start, -ctx->log_ctx, 1, 2, AV_CODEC_ID_HEVC, 1, 0); +ctx->log_ctx, 1, 2, AV_CODEC_ID_HEVC, 1, 1); if (err < 0) { av_log(ctx->log_ctx, AV_LOG_ERROR, "Failed to split " "HVCC array %d (%d NAL units of type %d).\n", @@ -709,7 +698,7 @@ static int cbs_h2645_split_fragment(CodedBitstreamContext *ctx, frag->data, frag->data_size, ctx->log_ctx, priv->mp4, priv->nal_length_size, -codec_id, 1, 0); +codec_id, 1, 1); if (err < 0) return err; ___ ffmpeg-cvslog mailing list ffmpeg-cvslog@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog
[FFmpeg-cvslog] h2645_parse: Make ff_h2645_packet_split reference-compatible
ffmpeg | branch: master | Andreas Rheinhardt | Wed Nov 28 01:24:09 2018 +0100| [992532ee3122d7938a7581988eea401b57de8189] | committer: Mark Thompson h2645_parse: Make ff_h2645_packet_split reference-compatible This is in preparation for a patch for cbs_h2645. Now the packet's rbsp_buffer can be owned by an AVBuffer. Signed-off-by: Andreas Rheinhardt > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=992532ee3122d7938a7581988eea401b57de8189 --- libavcodec/cbs_h2645.c | 8 +++--- libavcodec/extract_extradata_bsf.c | 2 +- libavcodec/h2645_parse.c | 53 +++--- libavcodec/h2645_parse.h | 9 ++- libavcodec/h264_parse.c| 2 +- libavcodec/h264dec.c | 4 +-- libavcodec/hevc_parse.c| 3 ++- libavcodec/hevc_parser.c | 2 +- libavcodec/hevcdec.c | 2 +- 9 files changed, 70 insertions(+), 15 deletions(-) diff --git a/libavcodec/cbs_h2645.c b/libavcodec/cbs_h2645.c index 666970ed03..574a53a60a 100644 --- a/libavcodec/cbs_h2645.c +++ b/libavcodec/cbs_h2645.c @@ -612,7 +612,7 @@ static int cbs_h2645_split_fragment(CodedBitstreamContext *ctx, err = ff_h2645_packet_split(&priv->read_packet, frag->data + start, end - start, -ctx->log_ctx, 1, 2, AV_CODEC_ID_H264, 1); +ctx->log_ctx, 1, 2, AV_CODEC_ID_H264, 1, 0); if (err < 0) { av_log(ctx->log_ctx, AV_LOG_ERROR, "Failed to split AVCC SPS array.\n"); return err; @@ -636,7 +636,7 @@ static int cbs_h2645_split_fragment(CodedBitstreamContext *ctx, err = ff_h2645_packet_split(&priv->read_packet, frag->data + start, end - start, -ctx->log_ctx, 1, 2, AV_CODEC_ID_H264, 1); +ctx->log_ctx, 1, 2, AV_CODEC_ID_H264, 1, 0); if (err < 0) { av_log(ctx->log_ctx, AV_LOG_ERROR, "Failed to split AVCC PPS array.\n"); return err; @@ -690,7 +690,7 @@ static int cbs_h2645_split_fragment(CodedBitstreamContext *ctx, err = ff_h2645_packet_split(&priv->read_packet, frag->data + start, end - start, -ctx->log_ctx, 1, 2, AV_CODEC_ID_HEVC, 1); +ctx->log_ctx, 1, 2, AV_CODEC_ID_HEVC, 1, 0); if (err < 0) { av_log(ctx->log_ctx, AV_LOG_ERROR, "Failed to split " "HVCC array %d (%d NAL units of type %d).\n", @@ -709,7 +709,7 @@ static int cbs_h2645_split_fragment(CodedBitstreamContext *ctx, frag->data, frag->data_size, ctx->log_ctx, priv->mp4, priv->nal_length_size, -codec_id, 1); +codec_id, 1, 0); if (err < 0) return err; diff --git a/libavcodec/extract_extradata_bsf.c b/libavcodec/extract_extradata_bsf.c index f37427c7e1..17e5deb96b 100644 --- a/libavcodec/extract_extradata_bsf.c +++ b/libavcodec/extract_extradata_bsf.c @@ -157,7 +157,7 @@ static int extract_extradata_h2645(AVBSFContext *ctx, AVPacket *pkt, } ret = ff_h2645_packet_split(&s->h2645_pkt, pkt->data, pkt->size, -ctx, 0, 0, ctx->par_in->codec_id, 1); +ctx, 0, 0, ctx->par_in->codec_id, 1, 0); if (ret < 0) return ret; diff --git a/libavcodec/h2645_parse.c b/libavcodec/h2645_parse.c index aaa4b8f443..942f2c5d71 100644 --- a/libavcodec/h2645_parse.c +++ b/libavcodec/h2645_parse.c @@ -343,9 +343,51 @@ static int find_next_start_code(const uint8_t *buf, const uint8_t *next_avc) return i + 3; } +static void alloc_rbsp_buffer(H2645RBSP *rbsp, unsigned int size, int use_ref) +{ +if (size > INT_MAX - AV_INPUT_BUFFER_PADDING_SIZE) +goto fail; +size += AV_INPUT_BUFFER_PADDING_SIZE; + +if (rbsp->rbsp_buffer_alloc_size >= size && +(!rbsp->rbsp_buffer_ref || av_buffer_is_writable(rbsp->rbsp_buffer_ref))) +return; + +size = FFMIN(size + size / 16 + 32, INT_MAX); + +if (rbsp->rbsp_buffer_ref) +av_buffer_unref(&rbsp->rbsp_buffer_ref); +else +av_free(rbsp->rbsp_buffer); + +rbsp->rbsp_buffer = av_malloc(size); +if (!rbsp->rbsp_buffer) +goto fail; +rbsp->rbsp_buffer_alloc_size = size; + +if (use_ref) { +rbsp->rbsp_buffer_ref = av_buffer_create(rbsp->rbsp_buffer, size, + NULL, NULL, 0); +if (!rbsp->rbsp_buffer_ref) +goto fail; +} + +return; + +fail: +rbsp->rbsp_buffer_alloc_size = 0; +if (rbsp->rbsp_buffer_ref) { +av_buffer_unre
[FFmpeg-cvslog] lavc/g723_1enc: Set the default bitrate to 6300.
ffmpeg | branch: master | Carl Eugen Hoyos | Tue Jan 22 12:22:23 2019 +0100| [cf81284b1c14ef28d3f94e6d28c46188ba4e82f2] | committer: Carl Eugen Hoyos lavc/g723_1enc: Set the default bitrate to 6300. > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=cf81284b1c14ef28d3f94e6d28c46188ba4e82f2 --- libavcodec/g723_1enc.c | 6 ++ 1 file changed, 6 insertions(+) diff --git a/libavcodec/g723_1enc.c b/libavcodec/g723_1enc.c index fe3fd09c1d..592840566e 100644 --- a/libavcodec/g723_1enc.c +++ b/libavcodec/g723_1enc.c @@ -1191,6 +1191,11 @@ static int g723_1_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, return 0; } +static const AVCodecDefault defaults[] = { +{ "b", "6300" }, +{ NULL }, +}; + AVCodec ff_g723_1_encoder = { .name = "g723_1", .long_name = NULL_IF_CONFIG_SMALL("G.723.1"), @@ -1199,6 +1204,7 @@ AVCodec ff_g723_1_encoder = { .priv_data_size = sizeof(G723_1_Context), .init = g723_1_encode_init, .encode2= g723_1_encode_frame, +.defaults = defaults, .sample_fmts= (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_NONE }, ___ ffmpeg-cvslog mailing list ffmpeg-cvslog@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog
[FFmpeg-cvslog] lavf/hlsproto: Replace a wrong eol comma with a semicolon.
ffmpeg | branch: master | caohui | Wed Jan 23 11:13:27 2019 +0800| [ee1c63eb821887f9af088519abf136fc9ef2f389] | committer: Carl Eugen Hoyos lavf/hlsproto: Replace a wrong eol comma with a semicolon. > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=ee1c63eb821887f9af088519abf136fc9ef2f389 --- libavformat/hlsproto.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libavformat/hlsproto.c b/libavformat/hlsproto.c index e7ef2d88ea..e5673e5e03 100644 --- a/libavformat/hlsproto.c +++ b/libavformat/hlsproto.c @@ -295,7 +295,7 @@ retry: } goto retry; } -url = s->segments[s->cur_seq_no - s->start_seq_no]->url, +url = s->segments[s->cur_seq_no - s->start_seq_no]->url; av_log(h, AV_LOG_DEBUG, "opening %s\n", url); ret = ffurl_open_whitelist(&s->seg_hd, url, AVIO_FLAG_READ, &h->interrupt_callback, NULL, ___ ffmpeg-cvslog mailing list ffmpeg-cvslog@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog