2017-07-21 06:12:44 +02:00
|
|
|
/*
|
|
|
|
* Intel MediaSDK QSV based MJPEG encoder
|
|
|
|
*
|
2017-11-08 19:58:36 +02:00
|
|
|
* This file is part of FFmpeg.
|
2017-07-21 06:12:44 +02:00
|
|
|
*
|
2017-11-08 19:58:36 +02:00
|
|
|
* FFmpeg is free software; you can redistribute it and/or
|
2017-07-21 06:12:44 +02: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 19:58:36 +02:00
|
|
|
* FFmpeg is distributed in the hope that it will be useful,
|
2017-07-21 06:12:44 +02: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 19:58:36 +02:00
|
|
|
* License along with FFmpeg; if not, write to the Free Software
|
2017-07-21 06:12:44 +02:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
|
2020-09-08 05:17:27 +02:00
|
|
|
#include <mfxvideo.h>
|
2017-07-21 06:12:44 +02:00
|
|
|
|
|
|
|
#include "libavutil/common.h"
|
|
|
|
#include "libavutil/opt.h"
|
|
|
|
|
|
|
|
#include "avcodec.h"
|
2022-03-16 19:18:28 +02:00
|
|
|
#include "codec_internal.h"
|
2017-07-21 06:12:44 +02:00
|
|
|
#include "qsv.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 11:26:12 +02: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 06:12:44 +02:00
|
|
|
{ NULL },
|
|
|
|
};
|
|
|
|
|
|
|
|
static const AVClass class = {
|
|
|
|
.class_name = "mjpeg_qsv encoder",
|
|
|
|
.item_name = av_default_item_name,
|
|
|
|
.option = options,
|
|
|
|
.version = LIBAVUTIL_VERSION_INT,
|
|
|
|
};
|
|
|
|
|
2022-03-16 22:26:11 +02:00
|
|
|
static const FFCodecDefault qsv_enc_defaults[] = {
|
2018-10-11 11:26:13 +02:00
|
|
|
{ "global_quality", "80" },
|
|
|
|
{ NULL },
|
|
|
|
};
|
|
|
|
|
2022-03-16 22:09:54 +02:00
|
|
|
const FFCodec ff_mjpeg_qsv_encoder = {
|
|
|
|
.p.name = "mjpeg_qsv",
|
2022-08-29 13:38:02 +02:00
|
|
|
CODEC_LONG_NAME("MJPEG (Intel Quick Sync Video acceleration)"),
|
2017-07-21 06:12:44 +02:00
|
|
|
.priv_data_size = sizeof(QSVMJPEGEncContext),
|
2022-03-16 22:09:54 +02:00
|
|
|
.p.type = AVMEDIA_TYPE_VIDEO,
|
|
|
|
.p.id = AV_CODEC_ID_MJPEG,
|
2017-07-21 06:12:44 +02:00
|
|
|
.init = qsv_enc_init,
|
2022-03-30 23:28:24 +02:00
|
|
|
FF_CODEC_ENCODE_CB(qsv_enc_frame),
|
2017-07-21 06:12:44 +02:00
|
|
|
.close = qsv_enc_close,
|
2022-03-16 22:09:54 +02:00
|
|
|
.p.capabilities = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_HYBRID,
|
|
|
|
.p.pix_fmts = (const enum AVPixelFormat[]){ AV_PIX_FMT_NV12,
|
2017-07-21 06:12:44 +02:00
|
|
|
AV_PIX_FMT_QSV,
|
|
|
|
AV_PIX_FMT_NONE },
|
2022-03-16 22:09:54 +02:00
|
|
|
.p.priv_class = &class,
|
2018-10-11 11:26:13 +02:00
|
|
|
.defaults = qsv_enc_defaults,
|
2022-03-16 22:09:54 +02:00
|
|
|
.p.wrapper_name = "qsv",
|
2020-04-13 17:33:16 +02:00
|
|
|
.hw_configs = ff_qsv_enc_hw_configs,
|
2022-07-09 22:25:41 +02:00
|
|
|
.caps_internal = FF_CODEC_CAP_NOT_INIT_THREADSAFE,
|
2017-07-21 06:12:44 +02:00
|
|
|
};
|