2017-07-21 04:12:44 +00:00
|
|
|
/*
|
|
|
|
* Intel MediaSDK QSV based MJPEG encoder
|
|
|
|
*
|
2017-11-08 17:58:36 +00:00
|
|
|
* This file is part of FFmpeg.
|
2017-07-21 04:12:44 +00:00
|
|
|
*
|
2017-11-08 17:58:36 +00:00
|
|
|
* FFmpeg is free software; you can redistribute it and/or
|
2017-07-21 04:12:44 +00:00
|
|
|
* 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.
|
|
|
|
*
|
2017-11-08 17:58:36 +00:00
|
|
|
* FFmpeg is distributed in the hope that it will be useful,
|
2017-07-21 04:12:44 +00:00
|
|
|
* 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
|
2017-11-08 17:58:36 +00:00
|
|
|
* License along with FFmpeg; if not, write to the Free Software
|
2017-07-21 04:12:44 +00:00
|
|
|
* 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 "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[] = {
|
2018-10-11 09:26:12 +00:00
|
|
|
{ "async_depth", "Maximum processing parallelism", OFFSET(qsv.async_depth), AV_OPT_TYPE_INT, { .i64 = ASYNC_DEPTH_DEFAULT }, 1, INT_MAX, VE },
|
2017-07-21 04:12:44 +00:00
|
|
|
{ NULL },
|
|
|
|
};
|
|
|
|
|
|
|
|
static const AVClass class = {
|
|
|
|
.class_name = "mjpeg_qsv encoder",
|
|
|
|
.item_name = av_default_item_name,
|
|
|
|
.option = options,
|
|
|
|
.version = LIBAVUTIL_VERSION_INT,
|
|
|
|
};
|
|
|
|
|
2018-10-11 09:26:13 +00:00
|
|
|
static const AVCodecDefault qsv_enc_defaults[] = {
|
|
|
|
{ "global_quality", "80" },
|
|
|
|
{ NULL },
|
|
|
|
};
|
|
|
|
|
2017-07-21 04:12:44 +00:00
|
|
|
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,
|
2017-12-11 15:18:44 +00:00
|
|
|
.capabilities = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_HYBRID,
|
2017-07-21 04:12:44 +00:00
|
|
|
.pix_fmts = (const enum AVPixelFormat[]){ AV_PIX_FMT_NV12,
|
|
|
|
AV_PIX_FMT_QSV,
|
|
|
|
AV_PIX_FMT_NONE },
|
|
|
|
.priv_class = &class,
|
2018-10-11 09:26:13 +00:00
|
|
|
.defaults = qsv_enc_defaults,
|
2017-12-11 15:18:44 +00:00
|
|
|
.wrapper_name = "qsv",
|
2017-07-21 04:12:44 +00:00
|
|
|
};
|