24 #define X265_API_IMPORTS 1 55 case NAL_UNIT_CODED_SLICE_BLA_W_LP:
56 case NAL_UNIT_CODED_SLICE_BLA_W_RADL:
57 case NAL_UNIT_CODED_SLICE_BLA_N_LP:
58 case NAL_UNIT_CODED_SLICE_IDR_W_RADL:
59 case NAL_UNIT_CODED_SLICE_IDR_N_LP:
60 case NAL_UNIT_CODED_SLICE_CRA:
86 ctx->
api = x265_api_get(0);
99 for (i = 0; x265_preset_names[
i]; i++)
104 for (i = 0; x265_tune_names[
i]; i++)
126 if (ctx->
params->sourceWidth < 64 || ctx->
params->sourceHeight < 64)
127 ctx->
params->maxCUSize = 32;
128 if (ctx->
params->sourceWidth < 32 || ctx->
params->sourceHeight < 32)
129 ctx->
params->maxCUSize = 16;
130 if (ctx->
params->sourceWidth < 16 || ctx->
params->sourceHeight < 16) {
137 ctx->
params->vui.bEnableVideoSignalTypePresentFlag = 1;
151 ctx->
params->vui.bEnableColorDescriptionPresentFlag = 1;
161 int sar_num, sar_den;
166 snprintf(sar,
sizeof(sar),
"%d:%d", sar_num, sar_den);
167 if (ctx->
api->param_parse(ctx->
params,
"sar", sar) == X265_PARAM_BAD_VALUE) {
177 ctx->
params->internalCsp = X265_CSP_I420;
182 ctx->
params->internalCsp = X265_CSP_I422;
188 ctx->
params->vui.bEnableVideoSignalTypePresentFlag = 1;
189 ctx->
params->vui.bEnableColorDescriptionPresentFlag = 1;
193 ctx->
params->internalCsp = X265_CSP_I444;
198 if (ctx->
api->api_build_number < 85) {
200 "libx265 version is %d, must be at least 85 for gray encoding.\n",
201 ctx->
api->api_build_number);
204 ctx->
params->internalCsp = X265_CSP_I400;
212 if (ctx->
api->param_parse(ctx->
params,
"crf", crf) == X265_PARAM_BAD_VALUE) {
218 ctx->
params->rc.rateControlMode = X265_RC_ABR;
232 ctx->
params->bRepeatHeaders = 1;
243 case X265_PARAM_BAD_NAME:
245 "Unknown option: %s.\n", en->
key);
247 case X265_PARAM_BAD_VALUE:
249 "Invalid value for %s: %s.\n", en->
key, en->
value);
260 ctx->
params->rc.vbvBufferInit == 0.9) {
269 for (i = 0; x265_profile_names[
i]; i++)
297 "Cannot allocate HEVC header of size %d.\n", avctx->
extradata_size);
312 if (ctx->
params->rc.aqMode == X265_AQ_NONE) {
313 av_log(ctx,
AV_LOG_WARNING,
"Adaptive quantization must be enabled to use ROI encoding, skipping ROI.\n");
316 int mb_size = (ctx->
params->rc.qgSize == 8) ? 8 : 16;
317 int mbx = (frame->
width + mb_size - 1) / mb_size;
318 int mby = (frame->
height + mb_size - 1) / mb_size;
319 int qp_range = 51 + 6 * (pic->bitDepth - 8);
327 if (!roi_size || sd->
size % roi_size != 0) {
331 nb_rois = sd->
size / roi_size;
339 for (
int i = nb_rois - 1;
i >= 0;
i--) {
340 int startx, endx, starty, endy;
345 starty =
FFMIN(mby, roi->
top / mb_size);
346 endy =
FFMIN(mby, (roi->
bottom + mb_size - 1)/ mb_size);
347 startx =
FFMIN(mbx, roi->
left / mb_size);
348 endx =
FFMIN(mbx, (roi->
right + mb_size - 1)/ mb_size);
356 qoffset = av_clipf(qoffset * qp_range, -qp_range, +qp_range);
358 for (
int y = starty; y < endy; y++)
359 for (
int x = startx; x < endx; x++)
360 qoffsets[x + y*mbx] = qoffset;
363 pic->quantOffsets = qoffsets;
370 const AVFrame *pic,
int *got_packet)
373 x265_picture x265pic;
374 x265_picture x265pic_out = { 0 };
382 ctx->
api->picture_init(ctx->
params, &x265pic);
385 for (i = 0; i < 3; i++) {
386 x265pic.planes[
i] = pic->
data[
i];
390 x265pic.pts = pic->
pts;
394 (ctx->
forced_idr ? X265_TYPE_IDR : X265_TYPE_I) :
404 ret = ctx->
api->encoder_encode(ctx->
encoder, &nal, &nnal,
405 pic ? &x265pic :
NULL, &x265pic_out);
415 for (i = 0; i < nnal; i++)
416 payload += nal[i].sizeBytes;
425 for (i = 0; i < nnal; i++) {
426 memcpy(dst, nal[i].payload, nal[i].sizeBytes);
427 dst += nal[
i].sizeBytes;
433 pkt->
pts = x265pic_out.pts;
434 pkt->
dts = x265pic_out.dts;
436 #if FF_API_CODED_FRAME 438 switch (x265pic_out.sliceType) {
453 #if X265_BUILD >= 130 454 if (x265pic_out.sliceType == X265_TYPE_B)
456 if (x265pic_out.frameData.sliceType ==
'b')
517 if (x265_api_get(12))
519 else if (x265_api_get(10))
521 else if (x265_api_get(8))
525 #define OFFSET(x) offsetof(libx265Context, x) 526 #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM 559 .priv_class = &
class,
562 .wrapper_name =
"libx265",
static const AVOption options[]
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
int top
Distance in pixels from the top edge of the frame to the top and bottom edges and from the left edge ...
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
This structure describes decoded (raw) audio or video data.
static int is_keyframe(NalUnitType naltype)
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
#define AV_LOG_WARNING
Something somehow does not look correct.
int64_t bit_rate
the average bitrate
#define LIBAVUTIL_VERSION_INT
int max_bitrate
Maximum bitrate of the stream, in bits per second.
int rc_initial_buffer_occupancy
Number of bits which should be loaded into the rc buffer before decoding starts.
SMPTE ST 432-1 (2010) / P3 D65 / Display P3.
enum AVColorRange color_range
MPEG vs JPEG YUV range.
#define AV_PIX_FMT_GBRP10
const char * av_default_item_name(void *ptr)
Return the context name.
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown) That is the width of a pixel divided by the height of the pixel...
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
#define AV_PIX_FMT_YUV420P12
#define AV_CODEC_CAP_AUTO_THREADS
Codec supports avctx->thread_count == 0 (auto).
order of coefficients is actually GBR, also IEC 61966-2-1 (sRGB)
#define AV_PKT_FLAG_DISPOSABLE
Flag is used to indicate packets that contain frames that can be discarded by the decoder...
AVRational qoffset
Quantisation offset.
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented...
#define AV_PIX_FMT_GRAY10
AVFrameSideData * av_frame_get_side_data(const AVFrame *frame, enum AVFrameSideDataType type)
#define AV_PIX_FMT_GRAY12
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
#define AV_CODEC_CAP_DELAY
Encoder or decoder requires flushing with NULL input at the end in order to give the complete and cor...
int ff_alloc_packet2(AVCodecContext *avctx, AVPacket *avpkt, int64_t size, int64_t min_size)
Check AVPacket size and/or allocate data.
AVComponentDescriptor comp[4]
Parameters that describe how pixels are packed.
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
Structure to hold side data for an AVFrame.
AVDictionaryEntry * av_dict_get(const AVDictionary *m, const char *key, const AVDictionaryEntry *prev, int flags)
Get a dictionary entry with matching key.
planar YUV 4:2:2, 16bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV422P and setting col...
int buffer_size
The size of the buffer to which the ratecontrol is applied, in bits.
int av_reduce(int *dst_num, int *dst_den, int64_t num, int64_t den, int64_t max)
Reduce a fraction.
uint32_t self_size
Must be set to the size of this data structure (that is, sizeof(AVRegionOfInterest)).
#define AV_PIX_FMT_YUV422P12
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
#define i(width, name, range_min, range_max)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
static int libx265_encode_frame(AVCodecContext *avctx, AVPacket *pkt, const AVFrame *pic, int *got_packet)
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
void av_dict_free(AVDictionary **pm)
Free all the memory allocated for an AVDictionary struct and all keys and values. ...
int flags
AV_CODEC_FLAG_*.
const char * name
Name of the codec implementation.
#define AV_PIX_FMT_YUV444P10
static const AVCodecDefault defaults[]
int flags
A combination of AV_PKT_FLAG values.
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
int rc_buffer_size
decoder bitstream buffer size
common internal API header
static av_cold void libx265_encode_init_csp(AVCodec *codec)
enum AVPixelFormat * pix_fmts
array of supported pixel formats, or NULL if unknown, array is terminated by -1
enum AVPictureType pict_type
Picture type of the frame.
AVCodec ff_libx265_encoder
planar YUV 4:2:0, 12bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV420P and setting col...
static av_cold int libx265_encode_init(AVCodecContext *avctx)
int width
picture width / height.
#define AV_CODEC_FLAG_PSNR
error[?] variables will be set during encoding.
enum AVColorPrimaries color_primaries
Chromaticity coordinates of the source primaries.
Structure describing a single Region Of Interest.
int ticks_per_frame
For some codecs, the time base is closer to the field rate than the frame rate.
static av_cold int libx265_encode_set_roi(libx265Context *ctx, const AVFrame *frame, x265_picture *pic)
int thread_count
thread count is used to decide how many independent tasks should be passed to execute() ...
the normal 2^n-1 "JPEG" YUV ranges
int av_dict_parse_string(AVDictionary **pm, const char *str, const char *key_val_sep, const char *pairs_sep, int flags)
Parse the key/value pairs list and add the parsed entries to a dictionary.
This structure describes the bitrate properties of an encoded bitstream.
#define AV_LOG_INFO
Standard information.
Libavcodec external API header.
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
main external API structure.
#define AV_PIX_FMT_YUV420P10
Describe the class of an AVClass context structure.
enum AVColorSpace colorspace
YUV colorspace type.
enum AVColorTransferCharacteristic color_trc
Color Transfer Characteristic.
static enum AVPixelFormat x265_csp_ten[]
Regions Of Interest, the data is an array of AVRegionOfInterest type, the number of array element is ...
#define AV_PIX_FMT_GBRP12
#define AV_PIX_FMT_YUV422P10
#define AV_PIX_FMT_YUV444P12
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
#define AV_CODEC_FLAG_GLOBAL_HEADER
Place global headers in extradata instead of every keyframe.
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
#define FF_DISABLE_DEPRECATION_WARNINGS
common internal api header.
common internal and external API header
static enum AVPixelFormat x265_csp_twelve[]
planar YUV 4:4:4, 24bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV444P and setting col...
attribute_deprecated AVFrame * coded_frame
the picture in the bitstream
AVCPBProperties * ff_add_cpb_side_data(AVCodecContext *avctx)
Add a CPB properties side data to an encoding context.
#define AV_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding...
ARIB STD-B67, known as "Hybrid log-gamma".
static const AVCodecDefault x265_defaults[]
#define FF_ENABLE_DEPRECATION_WARNINGS
int avg_bitrate
Average bitrate of the stream, in bits per second.
static av_cold int libx265_encode_close(AVCodecContext *avctx)
static enum AVPixelFormat x265_csp_eight[]
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed...
#define AV_DICT_IGNORE_SUFFIX
Return first entry in a dictionary whose first part corresponds to the search key, ignoring the suffix of the found key string.
#define AV_CODEC_FLAG_CLOSED_GOP
int depth
Number of bits in the component.
#define AVERROR_EXTERNAL
Generic error in an external library.
AVPixelFormat
Pixel format.
This structure stores compressed data.
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
int64_t rc_max_rate
maximum bitrate
void * av_mallocz_array(size_t nmemb, size_t size)
Allocate a memory block for an array with av_mallocz().