FFmpeg
qsvenc_jpeg.c
Go to the documentation of this file.
1 /*
2  * Intel MediaSDK QSV based MJPEG 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 QSVMJPEGEncContext {
37  AVClass *class;
40 
42 {
43  QSVMJPEGEncContext *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  QSVMJPEGEncContext *q = avctx->priv_data;
52 
53  return ff_qsv_encode(avctx, &q->qsv, pkt, frame, got_packet);
54 }
55 
57 {
58  QSVMJPEGEncContext *q = avctx->priv_data;
59 
60  return ff_qsv_enc_close(avctx, &q->qsv);
61 }
62 
63 #define OFFSET(x) offsetof(QSVMJPEGEncContext, 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 }, 1, INT_MAX, VE },
67  { NULL },
68 };
69 
70 static const AVClass class = {
71  .class_name = "mjpeg_qsv encoder",
72  .item_name = av_default_item_name,
73  .option = options,
75 };
76 
77 static const AVCodecDefault qsv_enc_defaults[] = {
78  { "global_quality", "80" },
79  { NULL },
80 };
81 
83  .name = "mjpeg_qsv",
84  .long_name = NULL_IF_CONFIG_SMALL("MJPEG (Intel Quick Sync Video acceleration)"),
85  .priv_data_size = sizeof(QSVMJPEGEncContext),
87  .id = AV_CODEC_ID_MJPEG,
88  .init = qsv_enc_init,
89  .encode2 = qsv_enc_frame,
90  .close = qsv_enc_close,
91  .capabilities = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_HYBRID,
92  .pix_fmts = (const enum AVPixelFormat[]){ AV_PIX_FMT_NV12,
95  .priv_class = &class,
96  .defaults = qsv_enc_defaults,
97  .wrapper_name = "qsv",
98  .hw_configs = ff_qsv_enc_hw_configs,
99 };
OFFSET
#define OFFSET(x)
Definition: qsvenc_jpeg.c:63
AVCodec
AVCodec.
Definition: codec.h:190
AVPixelFormat
AVPixelFormat
Pixel format.
Definition: pixfmt.h:64
init
static av_cold int init(AVCodecContext *avctx)
Definition: avrndec.c:35
opt.h
qsv_enc_init
static av_cold int qsv_enc_init(AVCodecContext *avctx)
Definition: qsvenc_jpeg.c:41
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:300
internal.h
AVOption
AVOption.
Definition: opt.h:246
type
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf type
Definition: writing_filters.txt:86
qsv_internal.h
ASYNC_DEPTH_DEFAULT
#define ASYNC_DEPTH_DEFAULT
Definition: qsv_internal.h:49
av_cold
#define av_cold
Definition: attributes.h:90
QSVEncContext
Definition: qsvenc.h:105
qsvenc.h
VE
#define VE
Definition: qsvenc_jpeg.c:64
pix_fmts
static enum AVPixelFormat pix_fmts[]
Definition: libkvazaar.c:275
QSVMJPEGEncContext
Definition: qsvenc_jpeg.c:36
AVCodecDefault
Definition: internal.h:201
ff_qsv_enc_hw_configs
const AVCodecHWConfigInternal * ff_qsv_enc_hw_configs[]
Definition: qsvenc.c:1659
ff_mjpeg_qsv_encoder
AVCodec ff_mjpeg_qsv_encoder
Definition: qsvenc_jpeg.c:82
LIBAVUTIL_VERSION_INT
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:67
NULL
#define NULL
Definition: coverity.c:32
qsv.h
QSVMJPEGEncContext::qsv
QSVEncContext qsv
Definition: qsvenc_jpeg.c:38
av_default_item_name
const char * av_default_item_name(void *ptr)
Return the context name.
Definition: log.c:235
qsv_enc_defaults
static const AVCodecDefault qsv_enc_defaults[]
Definition: qsvenc_jpeg.c:77
AV_PIX_FMT_QSV
@ AV_PIX_FMT_QSV
HW acceleration through QSV, data[3] contains a pointer to the mfxFrameSurface1 structure.
Definition: pixfmt.h:222
options
static const AVOption options[]
Definition: qsvenc_jpeg.c:65
NULL_IF_CONFIG_SMALL
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition: internal.h:188
qsv_enc_frame
static int qsv_enc_frame(AVCodecContext *avctx, AVPacket *pkt, const AVFrame *frame, int *got_packet)
Definition: qsvenc_jpeg.c:48
qsv_enc_close
static av_cold int qsv_enc_close(AVCodecContext *avctx)
Definition: qsvenc_jpeg.c:56
AV_CODEC_ID_MJPEG
@ AV_CODEC_ID_MJPEG
Definition: codec_id.h:56
ff_qsv_enc_close
int ff_qsv_enc_close(AVCodecContext *avctx, QSVEncContext *q)
Definition: qsvenc.c:1613
common.h
AVCodec::name
const char * name
Name of the codec implementation.
Definition: codec.h:197
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:89
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:72
frame
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return or at least make progress towards producing a frame
Definition: filter_design.txt:264
AVCodecContext
main external API structure.
Definition: avcodec.h:526
pkt
static AVPacket pkt
Definition: demuxing_decoding.c:54
AV_PIX_FMT_NONE
@ AV_PIX_FMT_NONE
Definition: pixfmt.h:65
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Definition: opt.h:223
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:75
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:1101
AV_CODEC_CAP_HYBRID
#define AV_CODEC_CAP_HYBRID
Codec is potentially backed by a hardware implementation, but not necessarily.
Definition: codec.h:157
AVPacket
This structure stores compressed data.
Definition: packet.h:332
AVCodecContext::priv_data
void * priv_data
Definition: avcodec.h:553
ff_qsv_encode
int ff_qsv_encode(AVCodecContext *avctx, QSVEncContext *q, AVPacket *pkt, const AVFrame *frame, int *got_packet)
Definition: qsvenc.c:1521