On 30/06/15 20:24, Anton Khirnov wrote:
> ---
> configure | 1 +
> libavcodec/Makefile | 1 +
> libavcodec/allcodecs.c | 1 +
> libavcodec/hevc.h | 3 +
> libavcodec/qsv.c | 14 +++
> libavcodec/qsv_internal.h | 4 +
> libavcodec/qsvenc.c | 22 +++--
> libavcodec/qsvenc_hevc.c | 236
> ++++++++++++++++++++++++++++++++++++++++++++++
> 8 files changed, 273 insertions(+), 9 deletions(-)
> create mode 100644 libavcodec/qsvenc_hevc.c
>
> diff --git a/configure b/configure
> index f9e46b4..a3aa62a 100755
> --- a/configure
> +++ b/configure
> @@ -1841,6 +1841,7 @@ h264_qsv_decoder_select="h264_mp4toannexb_bsf
> h264_parser qsvdec h264_qsv_hwacce
> h264_qsv_encoder_deps="libmfx"
> h264_qsv_encoder_select="qsvenc"
> hevc_decoder_select="bswapdsp cabac golomb videodsp"
> +hevc_qsv_encoder_select="qsvenc"
> huffyuv_decoder_select="bswapdsp huffyuvdsp"
> huffyuv_encoder_select="bswapdsp huffman huffyuvencdsp"
> iac_decoder_select="imc_decoder"
> diff --git a/libavcodec/Makefile b/libavcodec/Makefile
> index c751729..a560469 100644
> --- a/libavcodec/Makefile
> +++ b/libavcodec/Makefile
> @@ -231,6 +231,7 @@ OBJS-$(CONFIG_H264_QSV_ENCODER) += qsvenc_h264.o
> OBJS-$(CONFIG_HEVC_DECODER) += hevc.o hevc_mvs.o hevc_ps.o
> hevc_sei.o \
> hevc_cabac.o hevc_refs.o
> hevcpred.o \
> hevcdsp.o hevc_filter.o
> hevc_parse.o
> +OBJS-$(CONFIG_HEVC_QSV_ENCODER) += qsvenc_hevc.o hevc_ps_enc.o
> hevc_parse.o
> OBJS-$(CONFIG_HNM4_VIDEO_DECODER) += hnm4video.o
> OBJS-$(CONFIG_HQX_DECODER) += hqx.o hqxvlc.o
> OBJS-$(CONFIG_HUFFYUV_DECODER) += huffyuv.o huffyuvdec.o
> diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
> index 223c994..f0496b9 100644
> --- a/libavcodec/allcodecs.c
> +++ b/libavcodec/allcodecs.c
> @@ -473,6 +473,7 @@ void avcodec_register_all(void)
> * above is available */
> REGISTER_ENCODER(LIBOPENH264, libopenh264);
> REGISTER_ENCODER(H264_QSV, h264_qsv);
> + REGISTER_ENCODER(HEVC_QSV, hevc_qsv);
> REGISTER_ENCODER(MPEG2_QSV, mpeg2_qsv);
>
> /* parsers */
> diff --git a/libavcodec/hevc.h b/libavcodec/hevc.h
> index 8b06e1f..60377c2 100644
> --- a/libavcodec/hevc.h
> +++ b/libavcodec/hevc.h
> @@ -1008,6 +1008,9 @@ void ff_hevc_pred_init(HEVCPredContext *hpc, int
> bit_depth);
> int ff_hevc_extract_rbsp(const uint8_t *src, int length,
> HEVCNAL *nal);
>
> +int ff_hevc_encode_nal_vps(HEVCVPS *vps, unsigned int id,
> + uint8_t *buf, int buf_size);
> +
> extern const uint8_t ff_hevc_qpel_extra_before[4];
> extern const uint8_t ff_hevc_qpel_extra_after[4];
> extern const uint8_t ff_hevc_qpel_extra[4];
> diff --git a/libavcodec/qsv.c b/libavcodec/qsv.c
> index f563100..482b908 100644
> --- a/libavcodec/qsv.c
> +++ b/libavcodec/qsv.c
> @@ -32,6 +32,10 @@ int ff_qsv_codec_id_to_mfx(enum AVCodecID codec_id)
> switch (codec_id) {
> case AV_CODEC_ID_H264:
> return MFX_CODEC_AVC;
> +#if QSV_VERSION_ATLEAST(1, 8)
> + case AV_CODEC_ID_HEVC:
> + return MFX_CODEC_HEVC;
> +#endif
> case AV_CODEC_ID_MPEG1VIDEO:
> case AV_CODEC_ID_MPEG2VIDEO:
> return MFX_CODEC_MPEG2;
> @@ -113,5 +117,15 @@ int ff_qsv_init_internal_session(AVCodecContext *avctx,
> mfxSession *session)
> "Initialized an internal MFX session using %s implementation\n",
> desc);
>
> +#if QSV_VERSION_ATLEAST(1, 8)
> + if (avctx->codec_id == AV_CODEC_ID_HEVC) {
> + ret = MFXVideoUSER_Load(*session, &MFX_PLUGINID_HEVCE_SW, 1);
> + if (ret < 0) {
> + av_log(avctx, AV_LOG_WARNING,
> + "Could not load the HEVC encoding plugin, encoding will
> likely fail\n");
> + }
> + }
> +#endif
> +
> return 0;
> }
> diff --git a/libavcodec/qsv_internal.h b/libavcodec/qsv_internal.h
> index d13848a..4b6d9c4 100644
> --- a/libavcodec/qsv_internal.h
> +++ b/libavcodec/qsv_internal.h
> @@ -30,6 +30,10 @@
>
> #define ASYNC_DEPTH_DEFAULT 4 // internal parallelism
>
> +#define QSV_VERSION_ATLEAST(MAJOR, MINOR) \
> + (MFX_VERSION_MAJOR > (MAJOR) || \
> + MFX_VERSION_MAJOR == (MAJOR) && MFX_VERSION_MINOR >= (MINOR))
> +
> typedef struct QSVFrame {
> AVFrame *frame;
> mfxFrameSurface1 *surface;
> diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c
> index 690d5aa..a724611 100644
> --- a/libavcodec/qsvenc.c
> +++ b/libavcodec/qsvenc.c
> @@ -124,15 +124,19 @@ static int init_video_param(AVCodecContext *avctx,
> QSVEncContext *q)
> break;
> }
>
> - q->extco.Header.BufferId = MFX_EXTBUFF_CODING_OPTION;
> - q->extco.Header.BufferSz = sizeof(q->extco);
> - q->extco.CAVLC = avctx->coder_type == FF_CODER_TYPE_VLC ?
> - MFX_CODINGOPTION_ON :
> MFX_CODINGOPTION_UNKNOWN;
> -
> - q->extparam[0] = (mfxExtBuffer *)&q->extco;
> -
> - q->param.ExtParam = q->extparam;
> - q->param.NumExtParam = FF_ARRAY_ELEMS(q->extparam);
> + // the HEVC encoder plugin currently fails if coding options
> + // are provided
> + if (avctx->codec_id != AV_CODEC_ID_HEVC) {
> + q->extco.Header.BufferId = MFX_EXTBUFF_CODING_OPTION;
> + q->extco.Header.BufferSz = sizeof(q->extco);
> + q->extco.CAVLC = avctx->coder_type ==
> FF_CODER_TYPE_VLC ?
> + MFX_CODINGOPTION_ON :
> MFX_CODINGOPTION_UNKNOWN;
> +
> + q->extparam[0] = (mfxExtBuffer *)&q->extco;
> +
> + q->param.ExtParam = q->extparam;
> + q->param.NumExtParam = FF_ARRAY_ELEMS(q->extparam);
> + }
>
> return 0;
> }
> diff --git a/libavcodec/qsvenc_hevc.c b/libavcodec/qsvenc_hevc.c
> new file mode 100644
> index 0000000..9934472
> --- /dev/null
> +++ b/libavcodec/qsvenc_hevc.c
> @@ -0,0 +1,236 @@
> +/*
> + * Intel MediaSDK QSV based H.264 enccoder
HEVC encoder
> +static int generate_fake_vps(QSVEncContext *q, AVCodecContext *avctx)
> +{
> + GetByteContext gbc;
> + PutByteContext pbc;
> +
> + GetBitContext gb;
> + HEVCNAL sps_nal = { NULL };
> + HEVCSPS sps = { 0 };
> + HEVCVPS vps = { 0 };
> + uint8_t vps_buf[128], vps_rbsp_buf[128];
> + uint8_t *new_extradata;
> + unsigned int sps_id;
> + int ret, i, type, vps_size;
> +
> + if (!avctx->extradata_size) {
> 4 is needed (or you can add the check always in the extract function.
The rest is fine.
_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel