FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
qsvenc_mpeg2.c
Go to the documentation of this file.
1 /*
2  * Intel MediaSDK QSV based MPEG-2 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 QSVMpeg2EncContext {
37  AVClass *class;
40 
42 {
43  QSVMpeg2EncContext *q = avctx->priv_data;
44 
45  return ff_qsv_enc_init(avctx, &q->qsv);
46 }
47 
49  const AVFrame *frame, int *got_packet)
50 {
51  QSVMpeg2EncContext *q = avctx->priv_data;
52 
53  return ff_qsv_encode(avctx, &q->qsv, pkt, frame, got_packet);
54 }
55 
57 {
58  QSVMpeg2EncContext *q = avctx->priv_data;
59 
60  return ff_qsv_enc_close(avctx, &q->qsv);
61 }
62 
63 #define OFFSET(x) offsetof(QSVMpeg2EncContext, x)
64 #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
65 static const AVOption options[] = {
66  { "async_depth", "Maximum processing parallelism", OFFSET(qsv.async_depth), AV_OPT_TYPE_INT, { .i64 = ASYNC_DEPTH_DEFAULT }, 0, INT_MAX, VE },
67  { "avbr_accuracy", "Accuracy of the AVBR ratecontrol", OFFSET(qsv.avbr_accuracy), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, VE },
68  { "avbr_convergence", "Convergence of the AVBR ratecontrol", OFFSET(qsv.avbr_convergence), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, VE },
69 
70  { "profile", NULL, OFFSET(qsv.profile), AV_OPT_TYPE_INT, { .i64 = MFX_PROFILE_UNKNOWN }, 0, INT_MAX, VE, "profile" },
71  { "unknown", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = MFX_PROFILE_UNKNOWN }, INT_MIN, INT_MAX, VE, "profile" },
72  { "simple", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = MFX_PROFILE_MPEG2_SIMPLE }, INT_MIN, INT_MAX, VE, "profile" },
73  { "main", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = MFX_PROFILE_MPEG2_MAIN }, INT_MIN, INT_MAX, VE, "profile" },
74  { "high", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = MFX_PROFILE_MPEG2_HIGH }, INT_MIN, INT_MAX, VE, "profile" },
75 
76  { "preset", NULL, OFFSET(qsv.preset), AV_OPT_TYPE_INT, { .i64 = MFX_TARGETUSAGE_BALANCED }, 0, 7, VE, "preset" },
77  { "fast", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = MFX_TARGETUSAGE_BEST_SPEED }, INT_MIN, INT_MAX, VE, "preset" },
78  { "medium", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = MFX_TARGETUSAGE_BALANCED }, INT_MIN, INT_MAX, VE, "preset" },
79  { "slow", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = MFX_TARGETUSAGE_BEST_QUALITY }, INT_MIN, INT_MAX, VE, "preset" },
80 
81  { NULL },
82 };
83 
84 static const AVClass class = {
85  .class_name = "mpeg2_qsv encoder",
86  .item_name = av_default_item_name,
87  .option = options,
89 };
90 
91 static const AVCodecDefault qsv_enc_defaults[] = {
92  { "b", "1M" },
93  { "refs", "0" },
94  // same as the x264 default
95  { "g", "250" },
96  { "bf", "3" },
97 
98  { "flags", "+cgop" },
99  { NULL },
100 };
101 
103  .name = "mpeg2_qsv",
104  .long_name = NULL_IF_CONFIG_SMALL("MPEG-2 video (Intel Quick Sync Video acceleration)"),
105  .priv_data_size = sizeof(QSVMpeg2EncContext),
108  .init = qsv_enc_init,
109  .encode2 = qsv_enc_frame,
110  .close = qsv_enc_close,
111  .capabilities = AV_CODEC_CAP_DELAY,
112  .pix_fmts = (const enum AVPixelFormat[]){ AV_PIX_FMT_NV12,
114  AV_PIX_FMT_NONE },
115  .priv_class = &class,
116  .defaults = qsv_enc_defaults,
117 };
#define NULL
Definition: coverity.c:32
This structure describes decoded (raw) audio or video data.
Definition: frame.h:171
AVOption.
Definition: opt.h:255
#define LIBAVUTIL_VERSION_INT
Definition: version.h:62
static const AVOption options[]
Definition: qsvenc_mpeg2.c:65
static av_cold int init(AVCodecContext *avctx)
Definition: avrndec.c:35
static AVPacket pkt
static av_cold int qsv_enc_close(AVCodecContext *avctx)
Definition: qsvenc_mpeg2.c:56
AVCodec.
Definition: avcodec.h:3472
AVCodec ff_mpeg2_qsv_encoder
Definition: qsvenc_mpeg2.c:102
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
#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: avcodec.h:882
int ff_qsv_encode(AVCodecContext *avctx, QSVEncContext *q, AVPacket *pkt, const AVFrame *frame, int *got_packet)
Definition: qsvenc.c:417
#define av_cold
Definition: attributes.h:74
AVOptions.
#define VE
Definition: qsvenc_mpeg2.c:64
static AVFrame * frame
int ff_qsv_enc_close(AVCodecContext *avctx, QSVEncContext *q)
Definition: qsvenc.c:536
av_default_item_name
static int qsv_enc_frame(AVCodecContext *avctx, AVPacket *pkt, const AVFrame *frame, int *got_packet)
Definition: qsvenc_mpeg2.c:48
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:175
planar YUV 4:2:0, 12bpp, 1 plane for Y and 1 plane for the UV components, which are interleaved (firs...
Definition: pixfmt.h:91
const char * name
Name of the codec implementation.
Definition: avcodec.h:3479
Libavcodec external API header.
#define ASYNC_DEPTH_DEFAULT
Definition: qsv_internal.h:46
#define OFFSET(x)
Definition: qsvenc_mpeg2.c:63
preferred ID for MPEG-1/2 video decoding
Definition: avcodec.h:107
static av_cold int qsv_enc_init(AVCodecContext *avctx)
Definition: qsvenc_mpeg2.c:41
main external API structure.
Definition: avcodec.h:1502
GLint GLenum type
Definition: opengl_enc.c:105
Describe the class of an AVClass context structure.
Definition: log.h:67
int ff_qsv_enc_init(AVCodecContext *avctx, QSVEncContext *q)
Definition: qsvenc.c:235
HW acceleration through QSV, data[3] contains a pointer to the mfxFrameSurface1 structure.
Definition: pixfmt.h:261
static enum AVPixelFormat pix_fmts[]
Definition: libkvazaar.c:209
common internal api header.
common internal and external API header
QSVEncContext qsv
Definition: qsvenc_mpeg2.c:38
void * priv_data
Definition: avcodec.h:1544
AVPixelFormat
Pixel format.
Definition: pixfmt.h:61
This structure stores compressed data.
Definition: avcodec.h:1400
static const AVCodecDefault qsv_enc_defaults[]
Definition: qsvenc_mpeg2.c:91