lavc/qsvenc_jpeg: set a default quality
[libav.git] / libavcodec / qsvenc_jpeg.c
1 /*
2 * Intel MediaSDK QSV based MJPEG encoder
3 *
4 * This file is part of Libav.
5 *
6 * Libav is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * Libav is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with Libav; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21
22 #include <stdint.h>
23 #include <sys/types.h>
24
25 #include <mfx/mfxvideo.h>
26
27 #include "libavutil/common.h"
28 #include "libavutil/opt.h"
29
30 #include "avcodec.h"
31 #include "internal.h"
32 #include "h264.h"
33 #include "qsv.h"
34 #include "qsv_internal.h"
35 #include "qsvenc.h"
36
37 typedef struct QSVMJPEGEncContext {
38 AVClass *class;
39 QSVEncContext qsv;
40 } QSVMJPEGEncContext;
41
42 static av_cold int qsv_enc_init(AVCodecContext *avctx)
43 {
44 QSVMJPEGEncContext *q = avctx->priv_data;
45
46 return ff_qsv_enc_init(avctx, &q->qsv);
47 }
48
49 static int qsv_enc_frame(AVCodecContext *avctx, AVPacket *pkt,
50 const AVFrame *frame, int *got_packet)
51 {
52 QSVMJPEGEncContext *q = avctx->priv_data;
53
54 return ff_qsv_encode(avctx, &q->qsv, pkt, frame, got_packet);
55 }
56
57 static av_cold int qsv_enc_close(AVCodecContext *avctx)
58 {
59 QSVMJPEGEncContext *q = avctx->priv_data;
60
61 return ff_qsv_enc_close(avctx, &q->qsv);
62 }
63
64 #define OFFSET(x) offsetof(QSVMJPEGEncContext, x)
65 #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
66 static const AVOption options[] = {
67 { "async_depth", "Maximum processing parallelism", OFFSET(qsv.async_depth), AV_OPT_TYPE_INT, { .i64 = ASYNC_DEPTH_DEFAULT }, 1, INT_MAX, VE },
68 { NULL },
69 };
70
71 static const AVClass class = {
72 .class_name = "mjpeg_qsv encoder",
73 .item_name = av_default_item_name,
74 .option = options,
75 .version = LIBAVUTIL_VERSION_INT,
76 };
77
78 static const AVCodecDefault qsv_enc_defaults[] = {
79 { "global_quality", "80" },
80 { NULL },
81 };
82
83 AVCodec ff_mjpeg_qsv_encoder = {
84 .name = "mjpeg_qsv",
85 .long_name = NULL_IF_CONFIG_SMALL("MJPEG (Intel Quick Sync Video acceleration)"),
86 .priv_data_size = sizeof(QSVMJPEGEncContext),
87 .type = AVMEDIA_TYPE_VIDEO,
88 .id = AV_CODEC_ID_MJPEG,
89 .init = qsv_enc_init,
90 .encode2 = qsv_enc_frame,
91 .close = qsv_enc_close,
92 .capabilities = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_HYBRID,
93 .pix_fmts = (const enum AVPixelFormat[]){ AV_PIX_FMT_NV12,
94 AV_PIX_FMT_QSV,
95 AV_PIX_FMT_NONE },
96 .priv_class = &class,
97 .defaults = qsv_enc_defaults,
98 .wrapper_name = "qsv",
99 };