FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
qsvenc.c
Go to the documentation of this file.
1 /*
2  * Intel MediaSDK QSV encoder utility functions
3  *
4  * copyright (c) 2013 Yukinori Yamazoe
5  * copyright (c) 2015 Anton Khirnov
6  *
7  * This file is part of FFmpeg.
8  *
9  * FFmpeg is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License as published by the Free Software Foundation; either
12  * version 2.1 of the License, or (at your option) any later version.
13  *
14  * FFmpeg is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with FFmpeg; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22  */
23 
24 #include <string.h>
25 #include <sys/types.h>
26 #include <mfx/mfxvideo.h>
27 
28 #include "libavutil/common.h"
29 #include "libavutil/mem.h"
30 #include "libavutil/log.h"
31 #include "libavutil/time.h"
32 #include "libavutil/imgutils.h"
33 
34 #include "avcodec.h"
35 #include "internal.h"
36 #include "qsv.h"
37 #include "qsv_internal.h"
38 #include "qsvenc.h"
39 
41 {
42  const char *ratecontrol_desc;
43 
44  float quant;
45  int ret;
46 
47  ret = ff_qsv_codec_id_to_mfx(avctx->codec_id);
48  if (ret < 0)
49  return AVERROR_BUG;
50  q->param.mfx.CodecId = ret;
51 
52  if (avctx->level > 0)
53  q->param.mfx.CodecLevel = avctx->level;
54 
55  q->param.mfx.CodecProfile = q->profile;
56  q->param.mfx.TargetUsage = q->preset;
57  q->param.mfx.GopPicSize = FFMAX(0, avctx->gop_size);
58  q->param.mfx.GopRefDist = FFMAX(-1, avctx->max_b_frames) + 1;
59  q->param.mfx.GopOptFlag = avctx->flags & CODEC_FLAG_CLOSED_GOP ?
60  MFX_GOP_CLOSED : 0;
61  q->param.mfx.IdrInterval = q->idr_interval;
62  q->param.mfx.NumSlice = avctx->slices;
63  q->param.mfx.NumRefFrame = FFMAX(0, avctx->refs);
64  q->param.mfx.EncodedOrder = 0;
65  q->param.mfx.BufferSizeInKB = 0;
66 
67  q->param.mfx.FrameInfo.FourCC = MFX_FOURCC_NV12;
68  q->param.mfx.FrameInfo.Width = FFALIGN(avctx->width, 16);
69  q->param.mfx.FrameInfo.Height = FFALIGN(avctx->height, 32);
70  q->param.mfx.FrameInfo.CropX = 0;
71  q->param.mfx.FrameInfo.CropY = 0;
72  q->param.mfx.FrameInfo.CropW = avctx->width;
73  q->param.mfx.FrameInfo.CropH = avctx->height;
74  q->param.mfx.FrameInfo.AspectRatioW = avctx->sample_aspect_ratio.num;
75  q->param.mfx.FrameInfo.AspectRatioH = avctx->sample_aspect_ratio.den;
76  q->param.mfx.FrameInfo.PicStruct = MFX_PICSTRUCT_PROGRESSIVE;
77  q->param.mfx.FrameInfo.ChromaFormat = MFX_CHROMAFORMAT_YUV420;
78  q->param.mfx.FrameInfo.BitDepthLuma = 8;
79  q->param.mfx.FrameInfo.BitDepthChroma = 8;
80 
81  if (avctx->framerate.den > 0 && avctx->framerate.num > 0) {
82  q->param.mfx.FrameInfo.FrameRateExtN = avctx->framerate.num;
83  q->param.mfx.FrameInfo.FrameRateExtD = avctx->framerate.den;
84  } else {
85  q->param.mfx.FrameInfo.FrameRateExtN = avctx->time_base.den;
86  q->param.mfx.FrameInfo.FrameRateExtD = avctx->time_base.num;
87  }
88 
89  if (avctx->flags & CODEC_FLAG_QSCALE) {
90  q->param.mfx.RateControlMethod = MFX_RATECONTROL_CQP;
91  ratecontrol_desc = "constant quantization parameter (CQP)";
92  } else if (avctx->rc_max_rate == avctx->bit_rate) {
93  q->param.mfx.RateControlMethod = MFX_RATECONTROL_CBR;
94  ratecontrol_desc = "constant bitrate (CBR)";
95  } else if (!avctx->rc_max_rate) {
96  q->param.mfx.RateControlMethod = MFX_RATECONTROL_AVBR;
97  ratecontrol_desc = "average variable bitrate (AVBR)";
98  } else {
99  q->param.mfx.RateControlMethod = MFX_RATECONTROL_VBR;
100  ratecontrol_desc = "variable bitrate (VBR)";
101  }
102 
103  av_log(avctx, AV_LOG_VERBOSE, "Using the %s ratecontrol method\n", ratecontrol_desc);
104 
105  switch (q->param.mfx.RateControlMethod) {
106  case MFX_RATECONTROL_CBR:
107  case MFX_RATECONTROL_VBR:
108  q->param.mfx.InitialDelayInKB = avctx->rc_initial_buffer_occupancy / 1000;
109  q->param.mfx.TargetKbps = avctx->bit_rate / 1000;
110  q->param.mfx.MaxKbps = avctx->bit_rate / 1000;
111  break;
112  case MFX_RATECONTROL_CQP:
113  quant = avctx->global_quality / FF_QP2LAMBDA;
114 
115  q->param.mfx.QPI = av_clip(quant * fabs(avctx->i_quant_factor) + avctx->i_quant_offset, 0, 51);
116  q->param.mfx.QPP = av_clip(quant, 0, 51);
117  q->param.mfx.QPB = av_clip(quant * fabs(avctx->b_quant_factor) + avctx->b_quant_offset, 0, 51);
118 
119  break;
120  case MFX_RATECONTROL_AVBR:
121  q->param.mfx.TargetKbps = avctx->bit_rate / 1000;
122  q->param.mfx.Convergence = q->avbr_convergence;
123  q->param.mfx.Accuracy = q->avbr_accuracy;
124  break;
125  }
126 
127  q->extco.Header.BufferId = MFX_EXTBUFF_CODING_OPTION;
128  q->extco.Header.BufferSz = sizeof(q->extco);
129  q->extco.CAVLC = avctx->coder_type == FF_CODER_TYPE_VLC ?
130  MFX_CODINGOPTION_ON : MFX_CODINGOPTION_UNKNOWN;
131 
132  q->extparam[0] = (mfxExtBuffer *)&q->extco;
133 
134  q->param.ExtParam = q->extparam;
135  q->param.NumExtParam = FF_ARRAY_ELEMS(q->extparam);
136 
137  return 0;
138 }
139 
141 {
142  uint8_t sps_buf[128];
143  uint8_t pps_buf[128];
144 
145  mfxExtCodingOptionSPSPPS extradata = {
146  .Header.BufferId = MFX_EXTBUFF_CODING_OPTION_SPSPPS,
147  .Header.BufferSz = sizeof(extradata),
148  .SPSBuffer = sps_buf, .SPSBufSize = sizeof(sps_buf),
149  .PPSBuffer = pps_buf, .PPSBufSize = sizeof(pps_buf)
150  };
151 
152  mfxExtBuffer *ext_buffers[] = {
153  (mfxExtBuffer*)&extradata,
154  };
155 
156  int ret;
157 
158  q->param.ExtParam = ext_buffers;
159  q->param.NumExtParam = FF_ARRAY_ELEMS(ext_buffers);
160 
161  ret = MFXVideoENCODE_GetVideoParam(q->session, &q->param);
162  if (ret < 0)
163  return ff_qsv_error(ret);
164 
165  q->packet_size = q->param.mfx.BufferSizeInKB * 1000;
166 
167  if (!extradata.SPSBufSize || !extradata.PPSBufSize) {
168  av_log(avctx, AV_LOG_ERROR, "No extradata returned from libmfx.\n");
169  return AVERROR_UNKNOWN;
170  }
171 
172  avctx->extradata = av_malloc(extradata.SPSBufSize + extradata.PPSBufSize +
174  if (!avctx->extradata)
175  return AVERROR(ENOMEM);
176 
177  memcpy(avctx->extradata, sps_buf, extradata.SPSBufSize);
178  memcpy(avctx->extradata + extradata.SPSBufSize, pps_buf, extradata.PPSBufSize);
179  avctx->extradata_size = extradata.SPSBufSize + extradata.PPSBufSize;
180  memset(avctx->extradata + avctx->extradata_size, 0, FF_INPUT_BUFFER_PADDING_SIZE);
181 
182  return 0;
183 }
184 
186 {
187  int ret;
188 
189  q->param.IOPattern = MFX_IOPATTERN_IN_SYSTEM_MEMORY;
190  q->param.AsyncDepth = q->async_depth;
191 
192  if (avctx->hwaccel_context) {
193  AVQSVContext *qsv = avctx->hwaccel_context;
194 
195  q->session = qsv->session;
196  q->param.IOPattern = qsv->iopattern;
197  }
198 
199  if (!q->session) {
201  if (ret < 0)
202  return ret;
203 
204  q->session = q->internal_session;
205  }
206 
207  ret = init_video_param(avctx, q);
208  if (ret < 0)
209  return ret;
210 
211  ret = MFXVideoENCODE_QueryIOSurf(q->session, &q->param, &q->req);
212  if (ret < 0) {
213  av_log(avctx, AV_LOG_ERROR, "Error querying the encoding parameters\n");
214  return ff_qsv_error(ret);
215  }
216 
217  ret = MFXVideoENCODE_Init(q->session, &q->param);
218  if (ret < 0) {
219  av_log(avctx, AV_LOG_ERROR, "Error initializing the encoder\n");
220  return ff_qsv_error(ret);
221  }
222 
223  ret = qsv_retrieve_enc_params(avctx, q);
224  if (ret < 0) {
225  av_log(avctx, AV_LOG_ERROR, "Error retrieving encoding parameters.\n");
226  return ret;
227  }
228 
229  avctx->coded_frame = av_frame_alloc();
230  if (!avctx->coded_frame)
231  return AVERROR(ENOMEM);
232 
233  q->avctx = avctx;
234 
235  return 0;
236 }
237 
239 {
240  QSVFrame *cur = q->work_frames;
241  while (cur) {
242  if (cur->surface && !cur->surface->Data.Locked) {
243  cur->surface = NULL;
244  av_frame_unref(cur->frame);
245  }
246  cur = cur->next;
247  }
248 }
249 
251 {
252  QSVFrame *frame, **last;
253 
255 
256  frame = q->work_frames;
257  last = &q->work_frames;
258  while (frame) {
259  if (!frame->surface) {
260  *f = frame;
261  return 0;
262  }
263 
264  last = &frame->next;
265  frame = frame->next;
266  }
267 
268  frame = av_mallocz(sizeof(*frame));
269  if (!frame)
270  return AVERROR(ENOMEM);
271  frame->frame = av_frame_alloc();
272  if (!frame->frame) {
273  av_freep(&frame);
274  return AVERROR(ENOMEM);
275  }
276  *last = frame;
277 
278  *f = frame;
279 
280  return 0;
281 }
282 
283 static int submit_frame(QSVEncContext *q, const AVFrame *frame,
284  mfxFrameSurface1 **surface)
285 {
286  QSVFrame *qf;
287  int ret;
288 
289  ret = get_free_frame(q, &qf);
290  if (ret < 0)
291  return ret;
292 
293  if (frame->format == AV_PIX_FMT_QSV) {
294  ret = av_frame_ref(qf->frame, frame);
295  if (ret < 0)
296  return ret;
297 
298  qf->surface = (mfxFrameSurface1*)qf->frame->data[3];
299  *surface = qf->surface;
300  return 0;
301  }
302 
303  /* make a copy if the input is not padded as libmfx requires */
304  if (frame->height & 31 || frame->linesize[0] & 15) {
305  qf->frame->height = FFALIGN(frame->height, 32);
306  qf->frame->width = FFALIGN(frame->width, 16);
307 
309  if (ret < 0)
310  return ret;
311 
312  qf->frame->height = frame->height;
313  qf->frame->width = frame->width;
314  ret = av_frame_copy(qf->frame, frame);
315  if (ret < 0) {
316  av_frame_unref(qf->frame);
317  return ret;
318  }
319  } else {
320  ret = av_frame_ref(qf->frame, frame);
321  if (ret < 0)
322  return ret;
323  }
324 
325  qf->surface_internal.Info = q->param.mfx.FrameInfo;
326 
327  qf->surface_internal.Info.PicStruct =
328  !frame->interlaced_frame ? MFX_PICSTRUCT_PROGRESSIVE :
329  frame->top_field_first ? MFX_PICSTRUCT_FIELD_TFF :
330  MFX_PICSTRUCT_FIELD_BFF;
331  if (frame->repeat_pict == 1)
332  qf->surface_internal.Info.PicStruct |= MFX_PICSTRUCT_FIELD_REPEATED;
333  else if (frame->repeat_pict == 2)
334  qf->surface_internal.Info.PicStruct |= MFX_PICSTRUCT_FRAME_DOUBLING;
335  else if (frame->repeat_pict == 4)
336  qf->surface_internal.Info.PicStruct |= MFX_PICSTRUCT_FRAME_TRIPLING;
337 
338  qf->surface_internal.Data.PitchLow = qf->frame->linesize[0];
339  qf->surface_internal.Data.Y = qf->frame->data[0];
340  qf->surface_internal.Data.UV = qf->frame->data[1];
341  qf->surface_internal.Data.TimeStamp = av_rescale_q(frame->pts, q->avctx->time_base, (AVRational){1, 90000});
342 
343  qf->surface = &qf->surface_internal;
344 
345  *surface = qf->surface;
346 
347  return 0;
348 }
349 
351 {
352  if (q->param.mfx.CodecId == MFX_CODEC_AVC) {
353  if (q->param.mfx.CodecProfile == MFX_PROFILE_AVC_BASELINE ||
354  q->param.mfx.CodecLevel < MFX_LEVEL_AVC_21 ||
355  q->param.mfx.CodecLevel > MFX_LEVEL_AVC_41)
356  av_log(avctx, AV_LOG_WARNING,
357  "Interlaced coding is supported"
358  " at Main/High Profile Level 2.1-4.1\n");
359  }
360 }
361 
363  AVPacket *pkt, const AVFrame *frame, int *got_packet)
364 {
365  mfxBitstream bs = { { { 0 } } };
366 
367  mfxFrameSurface1 *surf = NULL;
368  mfxSyncPoint sync = NULL;
369  int ret;
370 
371  if (frame) {
372  ret = submit_frame(q, frame, &surf);
373  if (ret < 0) {
374  av_log(avctx, AV_LOG_ERROR, "Error submitting the frame for encoding.\n");
375  return ret;
376  }
377  }
378 
379  ret = ff_alloc_packet(pkt, q->packet_size);
380  if (ret < 0) {
381  av_log(avctx, AV_LOG_ERROR, "Error allocating the output packet\n");
382  return ret;
383  }
384  bs.Data = pkt->data;
385  bs.MaxLength = pkt->size;
386 
387  do {
388  ret = MFXVideoENCODE_EncodeFrameAsync(q->session, NULL, surf, &bs, &sync);
389  if (ret == MFX_WRN_DEVICE_BUSY)
390  av_usleep(1);
391  } while (ret > 0);
392 
393  if (ret < 0)
394  return (ret == MFX_ERR_MORE_DATA) ? 0 : ff_qsv_error(ret);
395 
396  if (ret == MFX_WRN_INCOMPATIBLE_VIDEO_PARAM && frame->interlaced_frame)
397  print_interlace_msg(avctx, q);
398 
399  if (sync) {
400  MFXVideoCORE_SyncOperation(q->session, sync, 60000);
401 
402  if (bs.FrameType & MFX_FRAMETYPE_I || bs.FrameType & MFX_FRAMETYPE_xI)
404  else if (bs.FrameType & MFX_FRAMETYPE_P || bs.FrameType & MFX_FRAMETYPE_xP)
406  else if (bs.FrameType & MFX_FRAMETYPE_B || bs.FrameType & MFX_FRAMETYPE_xB)
408 
409  pkt->dts = av_rescale_q(bs.DecodeTimeStamp, (AVRational){1, 90000}, avctx->time_base);
410  pkt->pts = av_rescale_q(bs.TimeStamp, (AVRational){1, 90000}, avctx->time_base);
411  pkt->size = bs.DataLength;
412 
413  if (bs.FrameType & MFX_FRAMETYPE_IDR ||
414  bs.FrameType & MFX_FRAMETYPE_xIDR)
416 
417  *got_packet = 1;
418  }
419 
420  return 0;
421 }
422 
424 {
425  QSVFrame *cur;
426 
427  MFXVideoENCODE_Close(q->session);
428  if (q->internal_session)
429  MFXClose(q->internal_session);
430  q->session = NULL;
431  q->internal_session = NULL;
432 
433  cur = q->work_frames;
434  while (cur) {
435  q->work_frames = cur->next;
436  av_frame_free(&cur->frame);
437  av_freep(&cur);
438  cur = q->work_frames;
439  }
440 
441  av_frame_free(&avctx->coded_frame);
442 
443  return 0;
444 }
#define NULL
Definition: coverity.c:32
AVRational framerate
Definition: avcodec.h:3023
This structure describes decoded (raw) audio or video data.
Definition: frame.h:171
misc image utilities
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:182
memory handling functions
AVFrame * coded_frame
the picture in the bitstream
Definition: avcodec.h:2745
int max_b_frames
maximum number of B-frames between non-B-frames Note: The output will be delayed by max_b_frames+1 re...
Definition: avcodec.h:1503
int rc_initial_buffer_occupancy
Number of bits which should be loaded into the rc buffer before decoding starts.
Definition: avcodec.h:2366
mfxFrameAllocRequest req
Definition: qsvenc.h:47
int avbr_accuracy
Definition: qsvenc.h:57
QSVFrame * work_frames
Definition: qsvenc.h:39
int num
numerator
Definition: rational.h:44
int repeat_pict
When decoding, this signals how much the picture must be delayed.
Definition: frame.h:362
static int get_free_frame(QSVEncContext *q, QSVFrame **f)
Definition: qsvenc.c:250
int size
Definition: avcodec.h:1163
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown) That is the width of a pixel divided by the height of the pixel...
Definition: avcodec.h:1623
int packet_size
Definition: qsvenc.h:44
#define FF_ARRAY_ELEMS(a)
mfxFrameSurface1 * surface
Definition: qsv_internal.h:35
int av_usleep(unsigned usec)
Sleep for a period of time.
Definition: time.c:76
static AVPacket pkt
mfxSession internal_session
Definition: qsvenc.h:42
static void print_interlace_msg(AVCodecContext *avctx, QSVEncContext *q)
Definition: qsvenc.c:350
float i_quant_offset
qscale offset between P and I-frames
Definition: avcodec.h:1556
#define FFALIGN(x, a)
Definition: common.h:71
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented...
Definition: avcodec.h:1369
int ff_qsv_encode(AVCodecContext *avctx, QSVEncContext *q, AVPacket *pkt, const AVFrame *frame, int *got_packet)
Definition: qsvenc.c:362
mfxVideoParam param
Definition: qsvenc.h:46
uint8_t
#define av_malloc(s)
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
Definition: frame.c:135
void * hwaccel_context
Hardware accelerator context.
Definition: avcodec.h:2656
mfxExtCodingOption extco
Definition: qsvenc.h:49
float b_quant_factor
qscale factor between IP and B-frames If > 0 then the last P-frame quantizer will be used (q= lastp_q...
Definition: avcodec.h:1512
int av_frame_ref(AVFrame *dst, const AVFrame *src)
Set up a new reference to the data described by the source frame.
Definition: frame.c:363
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
Definition: frame.h:257
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
Definition: avcodec.h:1355
static AVFrame * frame
int coder_type
coder type
Definition: avcodec.h:2380
uint8_t * data
Definition: avcodec.h:1162
#define AV_LOG_VERBOSE
Detailed information.
Definition: log.h:192
int interlaced_frame
The content of the picture is interlaced.
Definition: frame.h:367
int ff_qsv_enc_close(AVCodecContext *avctx, QSVEncContext *q)
Definition: qsvenc.c:423
#define av_log(a,...)
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
Definition: avcodec.h:1208
static int submit_frame(QSVEncContext *q, const AVFrame *frame, mfxFrameSurface1 **surface)
Definition: qsvenc.c:283
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
Definition: mathematics.c:140
int width
width and height of the video frame
Definition: frame.h:220
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:176
struct QSVFrame * next
Definition: qsv_internal.h:39
#define AVERROR(e)
Definition: error.h:43
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:148
int flags
CODEC_FLAG_*.
Definition: avcodec.h:1335
#define CODEC_FLAG_QSCALE
Use fixed qscale.
Definition: avcodec.h:712
int rc_max_rate
maximum bitrate
Definition: avcodec.h:2327
float i_quant_factor
qscale factor between P and I-frames If > 0 then the last p frame quantizer will be used (q= lastp_q*...
Definition: avcodec.h:1549
#define FF_CODER_TYPE_VLC
Definition: avcodec.h:2368
int iopattern
Definition: qsv.h:28
#define FFMAX(a, b)
Definition: common.h:64
Libavcodec external API header.
static int qsv_retrieve_enc_params(AVCodecContext *avctx, QSVEncContext *q)
Definition: qsvenc.c:140
int av_frame_copy(AVFrame *dst, const AVFrame *src)
Copy the frame data from src to dst.
Definition: frame.c:678
int flags
A combination of AV_PKT_FLAG values.
Definition: avcodec.h:1168
AVFrame * frame
Definition: qsv_internal.h:34
#define FF_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding...
Definition: avcodec.h:630
int refs
number of reference frames
Definition: avcodec.h:1901
int bit_rate
the average bitrate
Definition: avcodec.h:1305
AVCodecContext * avctx
Definition: qsvenc.h:37
enum AVPictureType pict_type
Picture type of the frame.
Definition: frame.h:242
int idr_interval
Definition: qsvenc.h:54
ret
Definition: avfilter.c:974
int width
picture width / height.
Definition: avcodec.h:1414
int preset
Definition: qsvenc.h:56
int ff_qsv_codec_id_to_mfx(enum AVCodecID codec_id)
Definition: qsv.c:28
int level
level
Definition: avcodec.h:2925
int ff_alloc_packet(AVPacket *avpkt, int size)
Definition: utils.c:1792
mfxFrameSurface1 surface_internal
Definition: qsv_internal.h:37
int async_depth
Definition: qsvenc.h:53
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames...
Definition: frame.h:232
enum AVCodecID codec_id
Definition: avcodec.h:1258
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
Definition: frame.h:199
main external API structure.
Definition: avcodec.h:1241
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
Definition: utils.c:1035
int profile
Definition: qsvenc.h:55
int extradata_size
Definition: avcodec.h:1356
#define AVERROR_BUG
Internal bug, also see AVERROR_BUG2.
Definition: error.h:50
int ff_qsv_init_internal_session(AVCodecContext *avctx, mfxSession *session)
Definition: qsv.c:80
int ff_qsv_enc_init(AVCodecContext *avctx, QSVEncContext *q)
Definition: qsvenc.c:185
rational number numerator/denominator
Definition: rational.h:43
HW acceleration through QSV, data[3] contains a pointer to the mfxFrameSurface1 structure.
Definition: pixfmt.h:249
float b_quant_offset
qscale offset between IP and B-frames
Definition: avcodec.h:1525
#define CODEC_FLAG_CLOSED_GOP
Definition: avcodec.h:764
const uint8_t * quant
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
Definition: frame.c:462
int global_quality
Global quality for codecs which cannot change it per frame.
Definition: avcodec.h:1321
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:182
int gop_size
the number of pictures in a group of pictures, or 0 for intra_only
Definition: avcodec.h:1435
common internal api header.
common internal and external API header
Bi-dir predicted.
Definition: avutil.h:269
int avbr_convergence
Definition: qsvenc.h:58
int ff_qsv_error(int mfx_err)
Convert a libmfx error code into a ffmpeg error code.
Definition: qsv.c:45
int den
denominator
Definition: rational.h:45
#define AVERROR_UNKNOWN
Unknown error, typically from an external library.
Definition: error.h:71
int slices
Number of slices.
Definition: avcodec.h:1976
int top_field_first
If the content is interlaced, is top field displayed first.
Definition: frame.h:372
#define FF_QP2LAMBDA
factor to convert from H.263 QP to lambda
Definition: avutil.h:220
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed...
Definition: avcodec.h:1161
static int init_video_param(AVCodecContext *avctx, QSVEncContext *q)
Definition: qsvenc.c:40
int height
Definition: frame.h:220
#define av_freep(p)
mfxExtBuffer * extparam[1]
Definition: qsvenc.h:50
This structure stores compressed data.
Definition: avcodec.h:1139
mfxSession session
Definition: qsvenc.h:41
#define AV_GET_BUFFER_FLAG_REF
The decoder will keep a reference to the frame and may reuse it later.
Definition: avcodec.h:969
mfxSession session
Definition: qsv.h:27
void * av_mallocz(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
Definition: mem.c:250
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
Definition: avcodec.h:1155
Predicted.
Definition: avutil.h:268
static void clear_unused_frames(QSVEncContext *q)
Definition: qsvenc.c:238