FFmpeg
libopenh264enc.c
Go to the documentation of this file.
1 /*
2  * OpenH264 video encoder
3  * Copyright (C) 2014 Martin Storsjo
4  *
5  * This file is part of FFmpeg.
6  *
7  * FFmpeg is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * FFmpeg is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with FFmpeg; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 
22 #include <wels/codec_api.h>
23 #include <wels/codec_ver.h>
24 
25 #include "libavutil/attributes.h"
26 #include "libavutil/common.h"
27 #include "libavutil/opt.h"
28 #include "libavutil/internal.h"
29 #include "libavutil/intreadwrite.h"
30 #include "libavutil/mathematics.h"
31 
32 #include "avcodec.h"
33 #include "codec_internal.h"
34 #include "encode.h"
35 #include "internal.h"
36 #include "libopenh264.h"
37 
38 #if !OPENH264_VER_AT_LEAST(1, 6)
39 #define SM_SIZELIMITED_SLICE SM_DYN_SLICE
40 #endif
41 
42 #define TARGET_BITRATE_DEFAULT 2*1000*1000
43 
44 typedef struct SVCContext {
45  const AVClass *av_class;
46  ISVCEncoder *encoder;
49  int profile;
52  int skipped;
53  int coder;
54 
55  // rate control mode
56  int rc_mode;
57 } SVCContext;
58 
59 #define OFFSET(x) offsetof(SVCContext, x)
60 #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
61 #define DEPRECATED AV_OPT_FLAG_DEPRECATED
62 static const AVOption options[] = {
63  { "loopfilter", "enable loop filter", OFFSET(loopfilter), AV_OPT_TYPE_INT, { .i64 = 1 }, 0, 1, VE },
64  { "profile", "set profile restrictions", OFFSET(profile), AV_OPT_TYPE_INT, { .i64 = AV_PROFILE_UNKNOWN }, AV_PROFILE_UNKNOWN, 0xffff, VE, "profile" },
65 #define PROFILE(name, value) name, NULL, 0, AV_OPT_TYPE_CONST, { .i64 = value }, 0, 0, VE, "profile"
66  { PROFILE("constrained_baseline", AV_PROFILE_H264_CONSTRAINED_BASELINE) },
67  { PROFILE("main", AV_PROFILE_H264_MAIN) },
68  { PROFILE("high", AV_PROFILE_H264_HIGH) },
69 #undef PROFILE
70  { "max_nal_size", "set maximum NAL size in bytes", OFFSET(max_nal_size), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, VE },
71  { "allow_skip_frames", "allow skipping frames to hit the target bitrate", OFFSET(skip_frames), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VE },
72  { "coder", "Coder type", OFFSET(coder), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 1, VE, "coder" },
73  { "default", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = -1 }, INT_MIN, INT_MAX, VE, "coder" },
74  { "cavlc", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = 0 }, INT_MIN, INT_MAX, VE, "coder" },
75  { "cabac", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = 1 }, INT_MIN, INT_MAX, VE, "coder" },
76  { "vlc", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = 0 }, INT_MIN, INT_MAX, VE, "coder" },
77  { "ac", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = 1 }, INT_MIN, INT_MAX, VE, "coder" },
78 
79  { "rc_mode", "Select rate control mode", OFFSET(rc_mode), AV_OPT_TYPE_INT, { .i64 = RC_QUALITY_MODE }, RC_OFF_MODE, RC_TIMESTAMP_MODE, VE, "rc_mode" },
80  { "off", "bit rate control off", 0, AV_OPT_TYPE_CONST, { .i64 = RC_OFF_MODE }, 0, 0, VE, "rc_mode" },
81  { "quality", "quality mode", 0, AV_OPT_TYPE_CONST, { .i64 = RC_QUALITY_MODE }, 0, 0, VE, "rc_mode" },
82  { "bitrate", "bitrate mode", 0, AV_OPT_TYPE_CONST, { .i64 = RC_BITRATE_MODE }, 0, 0, VE, "rc_mode" },
83  { "buffer", "using buffer status to adjust the video quality (no bitrate control)", 0, AV_OPT_TYPE_CONST, { .i64 = RC_BUFFERBASED_MODE }, 0, 0, VE, "rc_mode" },
84 #if OPENH264_VER_AT_LEAST(1, 4)
85  { "timestamp", "bit rate control based on timestamp", 0, AV_OPT_TYPE_CONST, { .i64 = RC_TIMESTAMP_MODE }, 0, 0, VE, "rc_mode" },
86 #endif
87 
88  { NULL }
89 };
90 
91 static const AVClass class = {
92  .class_name = "libopenh264enc",
93  .item_name = av_default_item_name,
94  .option = options,
96 };
97 
99 {
100  SVCContext *s = avctx->priv_data;
101 
102  if (s->encoder)
103  WelsDestroySVCEncoder(s->encoder);
104  if (s->skipped > 0)
105  av_log(avctx, AV_LOG_WARNING, "%d frames skipped\n", s->skipped);
106  return 0;
107 }
108 
110 {
111  SVCContext *s = avctx->priv_data;
112  SEncParamExt param = { 0 };
113  int err;
114  int log_level;
115  WelsTraceCallback callback_function;
116  AVCPBProperties *props;
117 
118  if ((err = ff_libopenh264_check_version(avctx)) < 0)
120 
121  if (WelsCreateSVCEncoder(&s->encoder)) {
122  av_log(avctx, AV_LOG_ERROR, "Unable to create encoder\n");
123  return AVERROR_UNKNOWN;
124  }
125 
126  // Pass all libopenh264 messages to our callback, to allow ourselves to filter them.
127  log_level = WELS_LOG_DETAIL;
128  (*s->encoder)->SetOption(s->encoder, ENCODER_OPTION_TRACE_LEVEL, &log_level);
129 
130  // Set the logging callback function to one that uses av_log() (see implementation above).
131  callback_function = (WelsTraceCallback) ff_libopenh264_trace_callback;
132  (*s->encoder)->SetOption(s->encoder, ENCODER_OPTION_TRACE_CALLBACK, &callback_function);
133 
134  // Set the AVCodecContext as the libopenh264 callback context so that it can be passed to av_log().
135  (*s->encoder)->SetOption(s->encoder, ENCODER_OPTION_TRACE_CALLBACK_CONTEXT, &avctx);
136 
137  (*s->encoder)->GetDefaultParams(s->encoder, &param);
138 
139  if (avctx->framerate.num > 0 && avctx->framerate.den > 0) {
140  param.fMaxFrameRate = av_q2d(avctx->framerate);
141  } else {
143  param.fMaxFrameRate = 1.0 / av_q2d(avctx->time_base)
144 #if FF_API_TICKS_PER_FRAME
145  / FFMAX(avctx->ticks_per_frame, 1)
146 #endif
147  ;
149  }
150  param.iPicWidth = avctx->width;
151  param.iPicHeight = avctx->height;
152  param.iTargetBitrate = avctx->bit_rate > 0 ? avctx->bit_rate : TARGET_BITRATE_DEFAULT;
153  param.iMaxBitrate = FFMAX(avctx->rc_max_rate, avctx->bit_rate);
154  param.iRCMode = s->rc_mode;
155  if (avctx->qmax >= 0)
156  param.iMaxQp = av_clip(avctx->qmax, 1, 51);
157  if (avctx->qmin >= 0)
158  param.iMinQp = av_clip(avctx->qmin, 1, param.iMaxQp);
159  param.iTemporalLayerNum = 1;
160  param.iSpatialLayerNum = 1;
161  param.bEnableDenoise = 0;
162  param.bEnableBackgroundDetection = 1;
163  param.bEnableAdaptiveQuant = 1;
164  param.bEnableFrameSkip = s->skip_frames;
165  param.bEnableLongTermReference = 0;
166  param.iLtrMarkPeriod = 30;
167  if (avctx->gop_size >= 0)
168  param.uiIntraPeriod = avctx->gop_size;
169 #if OPENH264_VER_AT_LEAST(1, 4)
170  param.eSpsPpsIdStrategy = CONSTANT_ID;
171 #else
172  param.bEnableSpsPpsIdAddition = 0;
173 #endif
174  param.bPrefixNalAddingCtrl = 0;
175  param.iLoopFilterDisableIdc = !s->loopfilter;
176  param.iEntropyCodingModeFlag = s->coder >= 0 ? s->coder : 1;
177  param.iMultipleThreadIdc = avctx->thread_count;
178 
179  /* Allow specifying the libopenh264 profile through AVCodecContext. */
180  if (AV_PROFILE_UNKNOWN == s->profile &&
181  AV_PROFILE_UNKNOWN != avctx->profile)
182  switch (avctx->profile) {
186  s->profile = avctx->profile;
187  break;
188  default:
189  av_log(avctx, AV_LOG_WARNING,
190  "Unsupported avctx->profile: %d.\n", avctx->profile);
191  break;
192  }
193 
194  if (s->profile == AV_PROFILE_UNKNOWN && s->coder >= 0)
195  s->profile = s->coder == 0 ? AV_PROFILE_H264_CONSTRAINED_BASELINE :
196 #if OPENH264_VER_AT_LEAST(1, 8)
198 #else
200 #endif
201 
202  switch (s->profile) {
204  av_log(avctx, AV_LOG_VERBOSE, "Using %s, "
205  "select EProfileIdc PRO_HIGH in libopenh264.\n",
206  param.iEntropyCodingModeFlag ? "CABAC" : "CAVLC");
207  break;
209  av_log(avctx, AV_LOG_VERBOSE, "Using %s, "
210  "select EProfileIdc PRO_MAIN in libopenh264.\n",
211  param.iEntropyCodingModeFlag ? "CABAC" : "CAVLC");
212  break;
214  case AV_PROFILE_UNKNOWN:
216  param.iEntropyCodingModeFlag = 0;
217  av_log(avctx, AV_LOG_VERBOSE, "Using CAVLC, "
218  "select EProfileIdc PRO_BASELINE in libopenh264.\n");
219  break;
220  default:
222  param.iEntropyCodingModeFlag = 0;
223  av_log(avctx, AV_LOG_WARNING, "Unsupported profile, "
224  "select EProfileIdc PRO_BASELINE in libopenh264.\n");
225  break;
226  }
227 
228  param.sSpatialLayers[0].iVideoWidth = param.iPicWidth;
229  param.sSpatialLayers[0].iVideoHeight = param.iPicHeight;
230  param.sSpatialLayers[0].fFrameRate = param.fMaxFrameRate;
231  param.sSpatialLayers[0].iSpatialBitrate = param.iTargetBitrate;
232  param.sSpatialLayers[0].iMaxSpatialBitrate = param.iMaxBitrate;
233  param.sSpatialLayers[0].uiProfileIdc = s->profile;
234 
235 #if OPENH264_VER_AT_LEAST(1, 7)
236  if (avctx->sample_aspect_ratio.num && avctx->sample_aspect_ratio.den) {
237  // Table E-1.
238  static const AVRational sar_idc[] = {
239  { 0, 0 }, // Unspecified (never written here).
240  { 1, 1 }, { 12, 11 }, { 10, 11 }, { 16, 11 },
241  { 40, 33 }, { 24, 11 }, { 20, 11 }, { 32, 11 },
242  { 80, 33 }, { 18, 11 }, { 15, 11 }, { 64, 33 },
243  { 160, 99 }, // Last 3 are unknown to openh264: { 4, 3 }, { 3, 2 }, { 2, 1 },
244  };
245  static const ESampleAspectRatio asp_idc[] = {
246  ASP_UNSPECIFIED,
247  ASP_1x1, ASP_12x11, ASP_10x11, ASP_16x11,
248  ASP_40x33, ASP_24x11, ASP_20x11, ASP_32x11,
249  ASP_80x33, ASP_18x11, ASP_15x11, ASP_64x33,
250  ASP_160x99,
251  };
252  int num, den, i;
253 
254  av_reduce(&num, &den, avctx->sample_aspect_ratio.num,
255  avctx->sample_aspect_ratio.den, 65535);
256 
257  for (i = 1; i < FF_ARRAY_ELEMS(sar_idc); i++) {
258  if (num == sar_idc[i].num &&
259  den == sar_idc[i].den)
260  break;
261  }
262  if (i == FF_ARRAY_ELEMS(sar_idc)) {
263  param.sSpatialLayers[0].eAspectRatio = ASP_EXT_SAR;
264  param.sSpatialLayers[0].sAspectRatioExtWidth = num;
265  param.sSpatialLayers[0].sAspectRatioExtHeight = den;
266  } else {
267  param.sSpatialLayers[0].eAspectRatio = asp_idc[i];
268  }
269  param.sSpatialLayers[0].bAspectRatioPresent = true;
270  } else {
271  param.sSpatialLayers[0].bAspectRatioPresent = false;
272  }
273 #endif
274 
275  if ((avctx->slices > 1) && (s->max_nal_size)) {
276  av_log(avctx, AV_LOG_ERROR,
277  "Invalid combination -slices %d and -max_nal_size %d.\n",
278  avctx->slices, s->max_nal_size);
279  return AVERROR(EINVAL);
280  }
281 
282  if (avctx->slices > 1)
283  s->slice_mode = SM_FIXEDSLCNUM_SLICE;
284 
285  if (s->max_nal_size)
286  s->slice_mode = SM_SIZELIMITED_SLICE;
287 
288 #if OPENH264_VER_AT_LEAST(1, 6)
289  param.sSpatialLayers[0].sSliceArgument.uiSliceMode = s->slice_mode;
290  param.sSpatialLayers[0].sSliceArgument.uiSliceNum = avctx->slices;
291 #else
292  param.sSpatialLayers[0].sSliceCfg.uiSliceMode = s->slice_mode;
293  param.sSpatialLayers[0].sSliceCfg.sSliceArgument.uiSliceNum = avctx->slices;
294 #endif
295  if (avctx->slices == 0 && s->slice_mode == SM_FIXEDSLCNUM_SLICE)
296  av_log(avctx, AV_LOG_WARNING, "Slice count will be set automatically\n");
297 
298  if (s->slice_mode == SM_SIZELIMITED_SLICE) {
299  if (s->max_nal_size) {
300  param.uiMaxNalSize = s->max_nal_size;
301 #if OPENH264_VER_AT_LEAST(1, 6)
302  param.sSpatialLayers[0].sSliceArgument.uiSliceSizeConstraint = s->max_nal_size;
303 #else
304  param.sSpatialLayers[0].sSliceCfg.sSliceArgument.uiSliceSizeConstraint = s->max_nal_size;
305 #endif
306  } else {
307  av_log(avctx, AV_LOG_ERROR, "Invalid -max_nal_size, "
308  "specify a valid max_nal_size to use -slice_mode dyn\n");
309  return AVERROR(EINVAL);
310  }
311  }
312 
313 #if OPENH264_VER_AT_LEAST(1, 6)
314  param.sSpatialLayers[0].uiVideoFormat = VF_UNDEF;
315 
316  if (avctx->color_range != AVCOL_RANGE_UNSPECIFIED) {
317  param.sSpatialLayers[0].bFullRange = (avctx->color_range == AVCOL_RANGE_JPEG);
318  } else if (avctx->pix_fmt == AV_PIX_FMT_YUVJ420P)
319  param.sSpatialLayers[0].bFullRange = 1;
320 
321  if (avctx->colorspace != AVCOL_SPC_UNSPECIFIED ||
323  avctx->color_trc != AVCOL_TRC_UNSPECIFIED) {
324  param.sSpatialLayers[0].bColorDescriptionPresent = true;
325  }
326 
327  if (avctx->colorspace != AVCOL_SPC_UNSPECIFIED)
328  param.sSpatialLayers[0].uiColorMatrix = avctx->colorspace;
330  param.sSpatialLayers[0].uiColorPrimaries = avctx->color_primaries;
331  if (avctx->color_trc != AVCOL_TRC_UNSPECIFIED)
332  param.sSpatialLayers[0].uiTransferCharacteristics = avctx->color_trc;
333 
334  param.sSpatialLayers[0].bVideoSignalTypePresent =
335  (param.sSpatialLayers[0].bFullRange || param.sSpatialLayers[0].bColorDescriptionPresent);
336 #endif
337 
338  if ((*s->encoder)->InitializeExt(s->encoder, &param) != cmResultSuccess) {
339  av_log(avctx, AV_LOG_ERROR, "Initialize failed\n");
340  return AVERROR_UNKNOWN;
341  }
342 
343  if (avctx->flags & AV_CODEC_FLAG_GLOBAL_HEADER) {
344  SFrameBSInfo fbi = { 0 };
345  int i, size = 0;
346  (*s->encoder)->EncodeParameterSets(s->encoder, &fbi);
347  for (i = 0; i < fbi.sLayerInfo[0].iNalCount; i++)
348  size += fbi.sLayerInfo[0].pNalLengthInByte[i];
350  if (!avctx->extradata)
351  return AVERROR(ENOMEM);
352  avctx->extradata_size = size;
353  memcpy(avctx->extradata, fbi.sLayerInfo[0].pBsBuf, size);
354  }
355 
356  props = ff_encode_add_cpb_side_data(avctx);
357  if (!props)
358  return AVERROR(ENOMEM);
359  props->max_bitrate = param.iMaxBitrate;
360  props->avg_bitrate = param.iTargetBitrate;
361 
362  return 0;
363 }
364 
365 static int svc_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
366  const AVFrame *frame, int *got_packet)
367 {
368  SVCContext *s = avctx->priv_data;
369  SFrameBSInfo fbi = { 0 };
370  int i, ret;
371  int encoded;
372  SSourcePicture sp = { 0 };
373  int size = 0, layer, first_layer = 0;
374  int layer_size[MAX_LAYER_NUM_OF_FRAME] = { 0 };
375 
376  sp.iColorFormat = videoFormatI420;
377  for (i = 0; i < 3; i++) {
378  sp.iStride[i] = frame->linesize[i];
379  sp.pData[i] = frame->data[i];
380  }
381  sp.iPicWidth = avctx->width;
382  sp.iPicHeight = avctx->height;
383 
385  (*s->encoder)->ForceIntraFrame(s->encoder, true);
386  }
387 
388  encoded = (*s->encoder)->EncodeFrame(s->encoder, &sp, &fbi);
389  if (encoded != cmResultSuccess) {
390  av_log(avctx, AV_LOG_ERROR, "EncodeFrame failed\n");
391  return AVERROR_UNKNOWN;
392  }
393  if (fbi.eFrameType == videoFrameTypeSkip) {
394  s->skipped++;
395  av_log(avctx, AV_LOG_DEBUG, "frame skipped\n");
396  return 0;
397  }
398  first_layer = 0;
399  // Normal frames are returned with one single layer, while IDR
400  // frames have two layers, where the first layer contains the SPS/PPS.
401  // If using global headers, don't include the SPS/PPS in the returned
402  // packet - thus, only return one layer.
403  if (avctx->flags & AV_CODEC_FLAG_GLOBAL_HEADER)
404  first_layer = fbi.iLayerNum - 1;
405 
406  for (layer = first_layer; layer < fbi.iLayerNum; layer++) {
407  for (i = 0; i < fbi.sLayerInfo[layer].iNalCount; i++)
408  layer_size[layer] += fbi.sLayerInfo[layer].pNalLengthInByte[i];
409  size += layer_size[layer];
410  }
411  av_log(avctx, AV_LOG_DEBUG, "%d slices\n", fbi.sLayerInfo[fbi.iLayerNum - 1].iNalCount);
412 
413  if ((ret = ff_get_encode_buffer(avctx, avpkt, size, 0)))
414  return ret;
415 
416  size = 0;
417  for (layer = first_layer; layer < fbi.iLayerNum; layer++) {
418  memcpy(avpkt->data + size, fbi.sLayerInfo[layer].pBsBuf, layer_size[layer]);
419  size += layer_size[layer];
420  }
421  avpkt->pts = frame->pts;
422  if (fbi.eFrameType == videoFrameTypeIDR)
423  avpkt->flags |= AV_PKT_FLAG_KEY;
424  *got_packet = 1;
425  return 0;
426 }
427 
429  { "b", "0" },
430  { "g", "-1" },
431  { "qmin", "-1" },
432  { "qmax", "-1" },
433  { NULL },
434 };
435 
437  .p.name = "libopenh264",
438  CODEC_LONG_NAME("OpenH264 H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10"),
439  .p.type = AVMEDIA_TYPE_VIDEO,
440  .p.id = AV_CODEC_ID_H264,
441  .p.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_OTHER_THREADS |
443  .priv_data_size = sizeof(SVCContext),
446  .close = svc_encode_close,
447  .caps_internal = FF_CODEC_CAP_INIT_CLEANUP |
449  .p.pix_fmts = (const enum AVPixelFormat[]){ AV_PIX_FMT_YUV420P,
451  AV_PIX_FMT_NONE },
452  .defaults = svc_enc_defaults,
453  .p.priv_class = &class,
454  .p.wrapper_name = "libopenh264",
455 };
ff_libopenh264_check_version
int ff_libopenh264_check_version(void *logctx)
Definition: libopenh264.c:50
SVCContext
Definition: libopenh264dec.c:37
FF_ENABLE_DEPRECATION_WARNINGS
#define FF_ENABLE_DEPRECATION_WARNINGS
Definition: internal.h:73
AV_LOG_WARNING
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:186
AVPixelFormat
AVPixelFormat
Pixel format.
Definition: pixfmt.h:64
av_clip
#define av_clip
Definition: common.h:96
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
AVERROR
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
opt.h
AVCodecContext::colorspace
enum AVColorSpace colorspace
YUV colorspace type.
Definition: avcodec.h:1029
AV_PROFILE_H264_MAIN
#define AV_PROFILE_H264_MAIN
Definition: defs.h:111
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:340
AVFrame::pts
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
Definition: frame.h:452
AVCodecContext::color_trc
enum AVColorTransferCharacteristic color_trc
Color Transfer Characteristic.
Definition: avcodec.h:1022
AVCOL_RANGE_JPEG
@ AVCOL_RANGE_JPEG
Full range content.
Definition: pixfmt.h:673
internal.h
AVPacket::data
uint8_t * data
Definition: packet.h:491
AVOption
AVOption.
Definition: opt.h:251
encode.h
AVCOL_TRC_UNSPECIFIED
@ AVCOL_TRC_UNSPECIFIED
Definition: pixfmt.h:573
SVCContext::skipped
int skipped
Definition: libopenh264enc.c:52
FFCodec
Definition: codec_internal.h:127
AV_LOG_VERBOSE
#define AV_LOG_VERBOSE
Detailed information.
Definition: log.h:196
mathematics.h
FFMAX
#define FFMAX(a, b)
Definition: macros.h:47
AVERROR_UNKNOWN
#define AVERROR_UNKNOWN
Unknown error, typically from an external library.
Definition: error.h:73
AVCodecContext::qmax
int qmax
maximum quantizer
Definition: avcodec.h:1255
AV_PKT_FLAG_KEY
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
Definition: packet.h:546
AVFrame::data
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:361
libopenh264.h
AV_CODEC_FLAG_GLOBAL_HEADER
#define AV_CODEC_FLAG_GLOBAL_HEADER
Place global headers in extradata instead of every keyframe.
Definition: avcodec.h:334
AVCodecContext::framerate
AVRational framerate
Definition: avcodec.h:1803
SVCContext::max_nal_size
int max_nal_size
Definition: libopenh264enc.c:50
FFCodecDefault
Definition: codec_internal.h:97
FFCodec::p
AVCodec p
The public AVCodec.
Definition: codec_internal.h:131
options
static const AVOption options[]
Definition: libopenh264enc.c:62
AVCodecContext::thread_count
int thread_count
thread count is used to decide how many independent tasks should be passed to execute()
Definition: avcodec.h:1532
AVCodecContext::flags
int flags
AV_CODEC_FLAG_*.
Definition: avcodec.h:521
SVCContext::coder
int coder
Definition: libopenh264enc.c:53
SVCContext::rc_mode
int rc_mode
Definition: libopenh264enc.c:56
FF_CODEC_ENCODE_CB
#define FF_CODEC_ENCODE_CB(func)
Definition: codec_internal.h:315
av_reduce
int av_reduce(int *dst_num, int *dst_den, int64_t num, int64_t den, int64_t max)
Reduce a fraction.
Definition: rational.c:35
AVRational::num
int num
Numerator.
Definition: rational.h:59
AVCodecContext::color_primaries
enum AVColorPrimaries color_primaries
Chromaticity coordinates of the source primaries.
Definition: avcodec.h:1015
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:180
FF_ARRAY_ELEMS
#define FF_ARRAY_ELEMS(a)
Definition: sinewin_tablegen.c:29
av_cold
#define av_cold
Definition: attributes.h:90
AV_PROFILE_UNKNOWN
#define AV_PROFILE_UNKNOWN
Definition: defs.h:65
AVCodecContext::extradata_size
int extradata_size
Definition: avcodec.h:543
intreadwrite.h
s
#define s(width, name)
Definition: cbs_vp9.c:198
av_q2d
static double av_q2d(AVRational a)
Convert an AVRational to a double.
Definition: rational.h:104
AV_CODEC_CAP_OTHER_THREADS
#define AV_CODEC_CAP_OTHER_THREADS
Codec supports multithreading through a method other than slice- or frame-level multithreading.
Definition: codec.h:124
init
int(* init)(AVBSFContext *ctx)
Definition: dts2pts_bsf.c:365
AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE
#define AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE
This encoder can reorder user opaque values from input AVFrames and return them with corresponding ou...
Definition: codec.h:159
svc_encode_frame
static int svc_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, const AVFrame *frame, int *got_packet)
Definition: libopenh264enc.c:365
AV_LOG_DEBUG
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:201
SVCContext::av_class
const AVClass * av_class
Definition: libopenh264enc.c:45
AV_PIX_FMT_YUV420P
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition: pixfmt.h:66
AVCodecContext::rc_max_rate
int64_t rc_max_rate
maximum bitrate
Definition: avcodec.h:1284
AVCOL_PRI_UNSPECIFIED
@ AVCOL_PRI_UNSPECIFIED
Definition: pixfmt.h:548
AVCPBProperties
This structure describes the bitrate properties of an encoded bitstream.
Definition: defs.h:269
AV_CODEC_ID_H264
@ AV_CODEC_ID_H264
Definition: codec_id.h:79
CODEC_LONG_NAME
#define CODEC_LONG_NAME(str)
Definition: codec_internal.h:272
frame
static AVFrame * frame
Definition: demux_decode.c:54
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
AVCodecContext::color_range
enum AVColorRange color_range
MPEG vs JPEG YUV range.
Definition: avcodec.h:1039
AVRational
Rational number (pair of numerator and denominator).
Definition: rational.h:58
AV_PIX_FMT_YUVJ420P
@ AV_PIX_FMT_YUVJ420P
planar YUV 4:2:0, 12bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV420P and setting col...
Definition: pixfmt.h:78
AVCodecContext::bit_rate
int64_t bit_rate
the average bitrate
Definition: avcodec.h:491
av_default_item_name
const char * av_default_item_name(void *ptr)
Return the context name.
Definition: log.c:237
AV_PICTURE_TYPE_I
@ AV_PICTURE_TYPE_I
Intra.
Definition: avutil.h:279
SVCContext::loopfilter
int loopfilter
Definition: libopenh264enc.c:48
SM_SIZELIMITED_SLICE
#define SM_SIZELIMITED_SLICE
Definition: libopenh264enc.c:39
AVCOL_RANGE_UNSPECIFIED
@ AVCOL_RANGE_UNSPECIFIED
Definition: pixfmt.h:639
AVCodecContext::time_base
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented.
Definition: avcodec.h:563
AVFrame::pict_type
enum AVPictureType pict_type
Picture type of the frame.
Definition: frame.h:442
AV_CODEC_CAP_DR1
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
Definition: codec.h:52
SVCContext::encoder
ISVCEncoder * encoder
Definition: libopenh264enc.c:46
AVCodecContext::gop_size
int gop_size
the number of pictures in a group of pictures, or 0 for intra_only
Definition: avcodec.h:643
codec_internal.h
TARGET_BITRATE_DEFAULT
#define TARGET_BITRATE_DEFAULT
Definition: libopenh264enc.c:42
ff_libopenh264_encoder
const FFCodec ff_libopenh264_encoder
Definition: libopenh264enc.c:436
sp
#define sp
Definition: regdef.h:63
size
int size
Definition: twinvq_data.h:10344
PROFILE
#define PROFILE(name, value)
attributes.h
AVPacket::flags
int flags
A combination of AV_PKT_FLAG values.
Definition: packet.h:497
AVCPBProperties::avg_bitrate
int64_t avg_bitrate
Average bitrate of the stream, in bits per second.
Definition: defs.h:284
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:255
AVPacket::pts
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
Definition: packet.h:484
AVCodecContext::extradata
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
Definition: avcodec.h:542
internal.h
SVCContext::skip_frames
int skip_frames
Definition: libopenh264enc.c:51
common.h
AVCPBProperties::max_bitrate
int64_t max_bitrate
Maximum bitrate of the stream, in bits per second.
Definition: defs.h:274
OFFSET
#define OFFSET(x)
Definition: libopenh264enc.c:59
av_mallocz
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
Definition: mem.c:254
AVCodec::name
const char * name
Name of the codec implementation.
Definition: codec.h:194
profile
int profile
Definition: mxfenc.c:2115
AVCOL_SPC_UNSPECIFIED
@ AVCOL_SPC_UNSPECIFIED
Definition: pixfmt.h:602
AVCodecContext::height
int height
Definition: avcodec.h:621
AVCodecContext::pix_fmt
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
Definition: avcodec.h:658
avcodec.h
svc_encode_init
static av_cold int svc_encode_init(AVCodecContext *avctx)
Definition: libopenh264enc.c:109
ret
ret
Definition: filter_design.txt:187
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
SVCContext::profile
int profile
Definition: libopenh264enc.c:49
AV_INPUT_BUFFER_PADDING_SIZE
#define AV_INPUT_BUFFER_PADDING_SIZE
Definition: defs.h:40
AVCodecContext
main external API structure.
Definition: avcodec.h:441
AV_PROFILE_H264_HIGH
#define AV_PROFILE_H264_HIGH
Definition: defs.h:113
SVCContext::slice_mode
int slice_mode
Definition: libopenh264enc.c:47
ff_get_encode_buffer
int ff_get_encode_buffer(AVCodecContext *avctx, AVPacket *avpkt, int64_t size, int flags)
Get a buffer for a packet.
Definition: encode.c:105
svc_encode_close
static av_cold int svc_encode_close(AVCodecContext *avctx)
Definition: libopenh264enc.c:98
AVCodecContext::qmin
int qmin
minimum quantizer
Definition: avcodec.h:1248
AVRational::den
int den
Denominator.
Definition: rational.h:60
AV_PIX_FMT_NONE
@ AV_PIX_FMT_NONE
Definition: pixfmt.h:65
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Definition: opt.h:225
AVCodecContext::profile
int profile
profile
Definition: avcodec.h:1596
VE
#define VE
Definition: libopenh264enc.c:60
AVCodecContext::ticks_per_frame
attribute_deprecated int ticks_per_frame
For some codecs, the time base is closer to the field rate than the frame rate.
Definition: avcodec.h:579
ff_libopenh264_trace_callback
void ff_libopenh264_trace_callback(void *ctx, int level, const char *msg)
Definition: libopenh264.c:42
AV_PROFILE_H264_CONSTRAINED_BASELINE
#define AV_PROFILE_H264_CONSTRAINED_BASELINE
Definition: defs.h:110
FF_DISABLE_DEPRECATION_WARNINGS
#define FF_DISABLE_DEPRECATION_WARNINGS
Definition: internal.h:72
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
AVERROR_ENCODER_NOT_FOUND
#define AVERROR_ENCODER_NOT_FOUND
Encoder not found.
Definition: error.h:56
FF_CODEC_CAP_AUTO_THREADS
#define FF_CODEC_CAP_AUTO_THREADS
Codec handles avctx->thread_count == 0 (auto) internally.
Definition: codec_internal.h:73
AVCodecContext::slices
int slices
Number of slices.
Definition: avcodec.h:1055
AVPacket
This structure stores compressed data.
Definition: packet.h:468
AVCodecContext::priv_data
void * priv_data
Definition: avcodec.h:468
AV_OPT_TYPE_BOOL
@ AV_OPT_TYPE_BOOL
Definition: opt.h:244
AVCodecContext::width
int width
picture width / height.
Definition: avcodec.h:621
AVFrame::linesize
int linesize[AV_NUM_DATA_POINTERS]
For video, a positive or negative value, which is typically indicating the size in bytes of each pict...
Definition: frame.h:385
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
ff_encode_add_cpb_side_data
AVCPBProperties * ff_encode_add_cpb_side_data(AVCodecContext *avctx)
Add a CPB properties side data to an encoding context.
Definition: encode.c:870
rc_mode
mfxU16 rc_mode
Definition: qsvenc.c:141
AV_OPT_TYPE_CONST
@ AV_OPT_TYPE_CONST
Definition: opt.h:234
AVCodecContext::sample_aspect_ratio
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:822
svc_enc_defaults
static const FFCodecDefault svc_enc_defaults[]
Definition: libopenh264enc.c:428