FFmpeg  4.4.4
qsvenc_vp9.c
Go to the documentation of this file.
1 /*
2  * Intel MediaSDK QSV based VP9 encoder
3  *
4  * This file is part of FFmpeg.
5  *
6  * FFmpeg 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  * FFmpeg 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 FFmpeg; 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 "qsv.h"
33 #include "qsv_internal.h"
34 #include "qsvenc.h"
35 
36 typedef struct QSVVP9EncContext {
37  AVClass *class;
40 
42 {
43  QSVVP9EncContext *q = avctx->priv_data;
44  q->qsv.low_power = 1;
45 
46  return ff_qsv_enc_init(avctx, &q->qsv);
47 }
48 
50  const AVFrame *frame, int *got_packet)
51 {
52  QSVVP9EncContext *q = avctx->priv_data;
53 
54  return ff_qsv_encode(avctx, &q->qsv, pkt, frame, got_packet);
55 }
56 
58 {
59  QSVVP9EncContext *q = avctx->priv_data;
60 
61  return ff_qsv_enc_close(avctx, &q->qsv);
62 }
63 
64 #define OFFSET(x) offsetof(QSVVP9EncContext, x)
65 #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
66 static const AVOption options[] = {
68 
69  { "profile", NULL, OFFSET(qsv.profile), AV_OPT_TYPE_INT, { .i64 = MFX_PROFILE_UNKNOWN }, 0, INT_MAX, VE, "profile" },
70  { "unknown", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = MFX_PROFILE_UNKNOWN}, INT_MIN, INT_MAX, VE, "profile" },
71  { "profile0", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = MFX_PROFILE_VP9_0 }, INT_MIN, INT_MAX, VE, "profile" },
72  { "profile1", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = MFX_PROFILE_VP9_1 }, INT_MIN, INT_MAX, VE, "profile" },
73  { "profile2", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = MFX_PROFILE_VP9_2 }, INT_MIN, INT_MAX, VE, "profile" },
74  { "profile3", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = MFX_PROFILE_VP9_3 }, INT_MIN, INT_MAX, VE, "profile" },
75 
76  { NULL },
77 };
78 
79 static const AVClass class = {
80  .class_name = "vp9_qsv encoder",
81  .item_name = av_default_item_name,
82  .option = options,
84 };
85 
86 static const AVCodecDefault qsv_enc_defaults[] = {
87  { "b", "1M" },
88  { "refs", "0" },
89  { "g", "250" },
90  { "trellis", "-1" },
91  { "flags", "+cgop" },
92  { NULL },
93 };
94 
96  .name = "vp9_qsv",
97  .long_name = NULL_IF_CONFIG_SMALL("VP9 video (Intel Quick Sync Video acceleration)"),
98  .priv_data_size = sizeof(QSVVP9EncContext),
100  .id = AV_CODEC_ID_VP9,
101  .init = qsv_enc_init,
102  .encode2 = qsv_enc_frame,
103  .close = qsv_enc_close,
104  .capabilities = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_HYBRID,
105  .pix_fmts = (const enum AVPixelFormat[]){ AV_PIX_FMT_NV12,
108  AV_PIX_FMT_NONE },
109  .priv_class = &class,
110  .defaults = qsv_enc_defaults,
111  .caps_internal = FF_CODEC_CAP_INIT_CLEANUP,
112  .wrapper_name = "qsv",
113  .hw_configs = ff_qsv_enc_hw_configs,
114 };
#define av_cold
Definition: attributes.h:88
Libavcodec external API header.
static av_cold int init(AVCodecContext *avctx)
Definition: avrndec.c:31
common internal and external API header
#define NULL
Definition: coverity.c:32
static AVFrame * frame
@ AV_OPT_TYPE_CONST
Definition: opt.h:234
@ AV_OPT_TYPE_INT
Definition: opt.h:225
#define AV_CODEC_CAP_DELAY
Encoder or decoder requires flushing with NULL input at the end in order to give the complete and cor...
Definition: codec.h:77
#define AV_CODEC_CAP_HYBRID
Codec is potentially backed by a hardware implementation, but not necessarily.
Definition: codec.h:164
@ AV_CODEC_ID_VP9
Definition: codec_id.h:217
const char * av_default_item_name(void *ptr)
Return the context name.
Definition: log.c:235
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85
cl_device_type type
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
Definition: internal.h:49
common internal API header
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition: internal.h:117
static enum AVPixelFormat pix_fmts[]
Definition: libkvazaar.c:309
AVOptions.
#define AV_PIX_FMT_P010
Definition: pixfmt.h:448
AVPixelFormat
Pixel format.
Definition: pixfmt.h:64
@ AV_PIX_FMT_NV12
planar YUV 4:2:0, 12bpp, 1 plane for Y and 1 plane for the UV components, which are interleaved (firs...
Definition: pixfmt.h:89
@ AV_PIX_FMT_NONE
Definition: pixfmt.h:65
@ AV_PIX_FMT_QSV
HW acceleration through QSV, data[3] contains a pointer to the mfxFrameSurface1 structure.
Definition: pixfmt.h:222
int ff_qsv_enc_close(AVCodecContext *avctx, QSVEncContext *q)
Definition: qsvenc.c:1613
int ff_qsv_enc_init(AVCodecContext *avctx, QSVEncContext *q)
Definition: qsvenc.c:1100
int ff_qsv_encode(AVCodecContext *avctx, QSVEncContext *q, AVPacket *pkt, const AVFrame *frame, int *got_packet)
Definition: qsvenc.c:1521
const AVCodecHWConfigInternal *const ff_qsv_enc_hw_configs[]
Definition: qsvenc.c:1659
#define QSV_COMMON_OPTS
Definition: qsvenc.h:77
static int qsv_enc_frame(AVCodecContext *avctx, AVPacket *pkt, const AVFrame *frame, int *got_packet)
Definition: qsvenc_vp9.c:49
static const AVCodecDefault qsv_enc_defaults[]
Definition: qsvenc_vp9.c:86
AVCodec ff_vp9_qsv_encoder
Definition: qsvenc_vp9.c:95
static const AVOption options[]
Definition: qsvenc_vp9.c:66
#define VE
Definition: qsvenc_vp9.c:65
static av_cold int qsv_enc_init(AVCodecContext *avctx)
Definition: qsvenc_vp9.c:41
static av_cold int qsv_enc_close(AVCodecContext *avctx)
Definition: qsvenc_vp9.c:57
#define OFFSET(x)
Definition: qsvenc_vp9.c:64
Describe the class of an AVClass context structure.
Definition: log.h:67
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
Definition: log.h:72
main external API structure.
Definition: avcodec.h:536
void * priv_data
Definition: avcodec.h:563
AVCodec.
Definition: codec.h:197
const char * name
Name of the codec implementation.
Definition: codec.h:204
This structure describes decoded (raw) audio or video data.
Definition: frame.h:318
AVOption.
Definition: opt.h:248
This structure stores compressed data.
Definition: packet.h:346
int low_power
Definition: qsvenc.h:193
QSVEncContext qsv
Definition: qsvenc_vp9.c:38
AVPacket * pkt
Definition: movenc.c:59