Thank you for your contribution, here some comments :) On 7/17/17 10:40 AM, Huang, Zhengxu wrote: > +#include <mfx/mfxjpeg.h>
Is the header necessary? > +++ b/libavcodec/qsvenc.c > @@ -435,6 +435,15 @@ static int init_video_param(AVCodecContext *avctx, > QSVEncContext *q) > q->param.mfx.FrameInfo.FrameRateExtD = avctx->time_base.num; > } > > + if (AV_CODEC_ID_MJPEG == avctx->codec_id) { > + av_log(avctx, AV_LOG_DEBUG, " Init codec is QSV JPEG encode \n"); > + q->param.mfx.Interleaved = 1; > + q->param.mfx.Quality = q->quality;; > + q->param.mfx.RestartInterval = 0; > + > + return 0; > + } > + This should be moved in the specific encoder init function > ret = select_rc_mode(avctx, q); > if (ret < 0) > return ret; > @@ -623,6 +632,11 @@ static int qsv_retrieve_enc_params(AVCodecContext > *avctx, QSVEncContext *q) > > q->packet_size = q->param.mfx.BufferSizeInKB * 1000; > > + // for qsv mjpeg the return value maybe 0 so alloc the buffer > + if (0 == q->packet_size) { > + q->packet_size = q->param.mfx.FrameInfo.Height * > q->param.mfx.FrameInfo.Width * 4; > + } > + This should be moved there as well. > if (!extradata.SPSBufSize || (need_pps && !extradata.PPSBufSize)) { > av_log(avctx, AV_LOG_ERROR, "No extradata returned from libmfx.\n"); > return AVERROR_UNKNOWN; > diff --git a/libavcodec/qsvenc.h b/libavcodec/qsvenc.h > index a639904..1384068 100644 > --- a/libavcodec/qsvenc.h > +++ b/libavcodec/qsvenc.h > @@ -132,6 +132,9 @@ typedef struct QSVEncContext { > int int_ref_qp_delta; > int recovery_point_sei; > > + // options for MJPEG > + unsigned short quality; > + There is a global quality option that probably could be reused. > char *load_plugins; > } QSVEncContext; > > diff --git a/libavcodec/qsvenc_jpeg.c b/libavcodec/qsvenc_jpeg.c > new file mode 100644 > index 0000000..fc9226d > --- /dev/null > +++ b/libavcodec/qsvenc_jpeg.c > @@ -0,0 +1,93 @@ > +/* > + * Intel MediaSDK QSV based MJPEG encoder > + * > + * This file is part of Libav. > + * > + * Libav 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. > + * > + * Libav 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 Libav; if not, write to the Free Software > + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 > USA > + */ > + > + > +#include <stdint.h> > +#include <sys/types.h> > + > +#include <mfx/mfxvideo.h> > + > +#include "libavutil/common.h" > +#include "libavutil/opt.h" > + > +#include "avcodec.h" > +#include "internal.h" > +#include "h264.h" > +#include "qsv.h" > +#include "qsv_internal.h" > +#include "qsvenc.h" > + > +typedef struct QSVMJPEGEncContext { > + AVClass *class; > + QSVEncContext qsv; > +} QSVMJPEGEncContext; > + > +static av_cold int qsv_enc_init(AVCodecContext *avctx) > +{ > + QSVMJPEGEncContext *q = avctx->priv_data; > + > + return ff_qsv_enc_init(avctx, &q->qsv); > +} > + > +static int qsv_enc_frame(AVCodecContext *avctx, AVPacket *pkt, > + const AVFrame *frame, int *got_packet) > +{ > + QSVMJPEGEncContext *q = avctx->priv_data; > + > + return ff_qsv_encode(avctx, &q->qsv, pkt, frame, got_packet); > +} > + > +static av_cold int qsv_enc_close(AVCodecContext *avctx) > +{ > + QSVMJPEGEncContext *q = avctx->priv_data; > + > + return ff_qsv_enc_close(avctx, &q->qsv); > +} > + > +#define OFFSET(x) offsetof(QSVMJPEGEncContext, x) > +#define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM > +static const AVOption options[] = { > + { "quality", "Specifies the image quality", OFFSET(qsv.quality), > AV_OPT_TYPE_INT, { .i64 = 90 }, 1, 100, VE }, > + > + { NULL }, > +}; > + > +static const AVClass class = { > + .class_name = "mjpeg_qsv encoder", > + .item_name = av_default_item_name, > + .option = options, > + .version = LIBAVUTIL_VERSION_INT, > +}; > + > +AVCodec ff_mjpeg_qsv_encoder = { > + .name = "mjpeg_qsv", > + .long_name = NULL_IF_CONFIG_SMALL("MJPEG (Intel Quick Sync Video > acceleration)"), > + .priv_data_size = sizeof(QSVMJPEGEncContext), > + .type = AVMEDIA_TYPE_VIDEO, > + .id = AV_CODEC_ID_MJPEG, > + .init = qsv_enc_init, > + .encode2 = qsv_enc_frame, > + .close = qsv_enc_close, > + .capabilities = AV_CODEC_CAP_DELAY, > + .pix_fmts = (const enum AVPixelFormat[]){ AV_PIX_FMT_NV12, > + AV_PIX_FMT_QSV, > + AV_PIX_FMT_NONE }, > + .priv_class = &class, > +}; _______________________________________________ libav-devel mailing list libav-devel@libav.org https://lists.libav.org/mailman/listinfo/libav-devel