FFmpeg
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 <mfxvideo.h>
26 
27 #include "libavutil/common.h"
28 #include "libavutil/opt.h"
29 
30 #include "avcodec.h"
31 #include "codec_internal.h"
32 #include "qsv.h"
33 #include "qsvenc.h"
34 
35 typedef struct QSVMpeg2EncContext {
36  AVClass *class;
39 
41 {
42  QSVMpeg2EncContext *q = avctx->priv_data;
43 
44  return ff_qsv_enc_init(avctx, &q->qsv);
45 }
46 
48  const AVFrame *frame, int *got_packet)
49 {
50  QSVMpeg2EncContext *q = avctx->priv_data;
51 
52  return ff_qsv_encode(avctx, &q->qsv, pkt, frame, got_packet);
53 }
54 
56 {
57  QSVMpeg2EncContext *q = avctx->priv_data;
58 
59  return ff_qsv_enc_close(avctx, &q->qsv);
60 }
61 
62 #define OFFSET(x) offsetof(QSVMpeg2EncContext, x)
63 #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
64 static const AVOption options[] = {
67 
68  { "profile", NULL, OFFSET(qsv.profile), AV_OPT_TYPE_INT, { .i64 = MFX_PROFILE_UNKNOWN }, 0, INT_MAX, VE, .unit = "profile" },
69  { "unknown", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = MFX_PROFILE_UNKNOWN }, INT_MIN, INT_MAX, VE, .unit = "profile" },
70  { "simple", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = MFX_PROFILE_MPEG2_SIMPLE }, INT_MIN, INT_MAX, VE, .unit = "profile" },
71  { "main", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = MFX_PROFILE_MPEG2_MAIN }, INT_MIN, INT_MAX, VE, .unit = "profile" },
72  { "high", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = MFX_PROFILE_MPEG2_HIGH }, INT_MIN, INT_MAX, VE, .unit = "profile" },
73 
74  { NULL },
75 };
76 
77 static const AVClass class = {
78  .class_name = "mpeg2_qsv encoder",
79  .item_name = av_default_item_name,
80  .option = options,
82 };
83 
84 static const FFCodecDefault qsv_enc_defaults[] = {
85  { "b", "0" },
86  { "refs", "0" },
87  // same as the x264 default
88  { "g", "250" },
89  { "bf", "3" },
90  { "trellis", "-1" },
91  { "flags", "+cgop" },
92  { NULL },
93 };
94 
96  .p.name = "mpeg2_qsv",
97  CODEC_LONG_NAME("MPEG-2 video (Intel Quick Sync Video acceleration)"),
98  .priv_data_size = sizeof(QSVMpeg2EncContext),
99  .p.type = AVMEDIA_TYPE_VIDEO,
100  .p.id = AV_CODEC_ID_MPEG2VIDEO,
101  .init = qsv_enc_init,
103  .close = qsv_enc_close,
104  .p.capabilities = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_HYBRID,
105  .p.pix_fmts = (const enum AVPixelFormat[]){ AV_PIX_FMT_NV12,
107  AV_PIX_FMT_NONE },
108  .p.priv_class = &class,
109  .defaults = qsv_enc_defaults,
110  .caps_internal = FF_CODEC_CAP_NOT_INIT_THREADSAFE |
112  .p.wrapper_name = "qsv",
113  .hw_configs = ff_qsv_enc_hw_configs,
114 };
AVPixelFormat
AVPixelFormat
Pixel format.
Definition: pixfmt.h:71
FF_CODEC_CAP_INIT_CLEANUP
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
Definition: codec_internal.h:42
opt.h
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:344
AVOption
AVOption.
Definition: opt.h:346
FF_CODEC_CAP_NOT_INIT_THREADSAFE
#define FF_CODEC_CAP_NOT_INIT_THREADSAFE
The codec is not known to be init-threadsafe (i.e.
Definition: codec_internal.h:34
FFCodec
Definition: codec_internal.h:127
ff_mpeg2_qsv_encoder
const FFCodec ff_mpeg2_qsv_encoder
Definition: qsvenc_mpeg2.c:95
FFCodecDefault
Definition: codec_internal.h:97
FFCodec::p
AVCodec p
The public AVCodec.
Definition: codec_internal.h:131
VE
#define VE
Definition: qsvenc_mpeg2.c:63
options
static const AVOption options[]
Definition: qsvenc_mpeg2.c:64
FF_CODEC_ENCODE_CB
#define FF_CODEC_ENCODE_CB(func)
Definition: codec_internal.h:296
ff_qsv_enc_hw_configs
const AVCodecHWConfigInternal *const ff_qsv_enc_hw_configs[]
Definition: qsvenc.c:2689
pkt
AVPacket * pkt
Definition: movenc.c:59
av_cold
#define av_cold
Definition: attributes.h:90
QSVEncContext
Definition: qsvenc.h:156
qsv_enc_close
static av_cold int qsv_enc_close(AVCodecContext *avctx)
Definition: qsvenc_mpeg2.c:55
qsvenc.h
qsv_enc_frame
static int qsv_enc_frame(AVCodecContext *avctx, AVPacket *pkt, const AVFrame *frame, int *got_packet)
Definition: qsvenc_mpeg2.c:47
OFFSET
#define OFFSET(x)
Definition: qsvenc_mpeg2.c:62
qsv_enc_defaults
static const FFCodecDefault qsv_enc_defaults[]
Definition: qsvenc_mpeg2.c:84
CODEC_LONG_NAME
#define CODEC_LONG_NAME(str)
Definition: codec_internal.h:272
frame
static AVFrame * frame
Definition: demux_decode.c:54
QSV_OPTION_RDO
#define QSV_OPTION_RDO
Definition: qsvenc.h:77
LIBAVUTIL_VERSION_INT
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:66
NULL
#define NULL
Definition: coverity.c:32
qsv.h
QSV_COMMON_OPTS
#define QSV_COMMON_OPTS
Definition: qsvenc.h:56
av_default_item_name
const char * av_default_item_name(void *ptr)
Return the context name.
Definition: log.c:237
AV_PIX_FMT_QSV
@ AV_PIX_FMT_QSV
HW acceleration through QSV, data[3] contains a pointer to the mfxFrameSurface1 structure.
Definition: pixfmt.h:247
codec_internal.h
QSVMpeg2EncContext
Definition: qsvenc_mpeg2.c:35
ff_qsv_enc_close
int ff_qsv_enc_close(AVCodecContext *avctx, QSVEncContext *q)
Definition: qsvenc.c:2641
common.h
AVCodec::name
const char * name
Name of the codec implementation.
Definition: codec.h:194
qsv_enc_init
static av_cold int qsv_enc_init(AVCodecContext *avctx)
Definition: qsvenc_mpeg2.c:40
avcodec.h
AV_PIX_FMT_NV12
@ 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:96
AVClass::class_name
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:71
AVCodecContext
main external API structure.
Definition: avcodec.h:445
QSVMpeg2EncContext::qsv
QSVEncContext qsv
Definition: qsvenc_mpeg2.c:37
AV_PIX_FMT_NONE
@ AV_PIX_FMT_NONE
Definition: pixfmt.h:72
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Definition: opt.h:235
AV_CODEC_CAP_DELAY
#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:76
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
ff_qsv_enc_init
int ff_qsv_enc_init(AVCodecContext *avctx, QSVEncContext *q)
Definition: qsvenc.c:1631
AV_CODEC_CAP_HYBRID
#define AV_CODEC_CAP_HYBRID
Codec is potentially backed by a hardware implementation, but not necessarily.
Definition: codec.h:152
AVPacket
This structure stores compressed data.
Definition: packet.h:499
AVCodecContext::priv_data
void * priv_data
Definition: avcodec.h:472
AV_CODEC_ID_MPEG2VIDEO
@ AV_CODEC_ID_MPEG2VIDEO
preferred ID for MPEG-1/2 video decoding
Definition: codec_id.h:54
AV_OPT_TYPE_CONST
@ AV_OPT_TYPE_CONST
Definition: opt.h:244
ff_qsv_encode
int ff_qsv_encode(AVCodecContext *avctx, QSVEncContext *q, AVPacket *pkt, const AVFrame *frame, int *got_packet)
Definition: qsvenc.c:2573