24 #define X265_API_IMPORTS 1
53 case NAL_UNIT_CODED_SLICE_BLA_W_LP:
54 case NAL_UNIT_CODED_SLICE_BLA_W_RADL:
55 case NAL_UNIT_CODED_SLICE_BLA_N_LP:
56 case NAL_UNIT_CODED_SLICE_IDR_W_RADL:
57 case NAL_UNIT_CODED_SLICE_IDR_N_LP:
58 case NAL_UNIT_CODED_SLICE_CRA:
85 ctx->
api = x265_api_get(0);
90 "4:2:2 and 4:4:4 support is not fully defined for HEVC yet. "
91 "Set -strict experimental to encode anyway.\n");
112 for (i = 0; x265_preset_names[i]; i++)
117 for (i = 0; x265_tune_names[i]; i++)
139 ctx->
params->vui.bEnableVideoSignalTypePresentFlag = 1;
140 ctx->
params->vui.bEnableColorDescriptionPresentFlag = 1;
150 int sar_num, sar_den;
155 snprintf(sar,
sizeof(sar),
"%d:%d", sar_num, sar_den);
156 if (ctx->
api->param_parse(ctx->
params,
"sar", sar) == X265_PARAM_BAD_VALUE) {
165 ctx->
params->internalCsp = X265_CSP_I420;
169 ctx->
params->internalCsp = X265_CSP_I422;
173 ctx->
params->internalCsp = X265_CSP_I444;
181 if (ctx->
api->param_parse(ctx->
params,
"crf", crf) == X265_PARAM_BAD_VALUE) {
187 ctx->
params->rc.rateControlMode = X265_RC_ABR;
191 ctx->
params->bRepeatHeaders = 1;
202 case X265_PARAM_BAD_NAME:
204 "Unknown option: %s.\n", en->
key);
206 case X265_PARAM_BAD_VALUE:
208 "Invalid value for %s: %s.\n", en->
key, en->
value);
239 "Cannot allocate HEVC header of size %d.\n", avctx->
extradata_size);
251 const AVFrame *pic,
int *got_packet)
254 x265_picture x265pic;
255 x265_picture x265pic_out = { 0 };
263 ctx->
api->picture_init(ctx->
params, &x265pic);
266 for (i = 0; i < 3; i++) {
267 x265pic.planes[i] = pic->
data[i];
268 x265pic.stride[i] = pic->
linesize[i];
271 x265pic.pts = pic->
pts;
280 ret = ctx->
api->encoder_encode(ctx->
encoder, &nal, &nnal,
281 pic ? &x265pic :
NULL, &x265pic_out);
288 for (i = 0; i < nnal; i++)
289 payload += nal[i].sizeBytes;
298 for (i = 0; i < nnal; i++) {
299 memcpy(dst, nal[i].payload, nal[i].sizeBytes);
300 dst += nal[i].sizeBytes;
306 pkt->
pts = x265pic_out.pts;
307 pkt->
dts = x265pic_out.dts;
309 switch (x265pic_out.sliceType) {
345 if (x265_api_get(10))
347 else if (x265_api_get(8))
351 #define OFFSET(x) offsetof(libx265Context, x)
352 #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
357 {
"x265-params",
"set the x265 configuration using a :-separated list of key=value parameters",
OFFSET(x265_opts),
AV_OPT_TYPE_STRING, { 0 }, 0, 0,
VE },
383 .priv_class = &
class,
ITU-R BT2020 for 12 bit system.
static const AVOption options[]
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
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.
#define LIBAVUTIL_VERSION_INT
AVFrame * coded_frame
the picture in the bitstream
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.
uint8_t log2_chroma_w
Amount to shift the luma width right to find the chroma width.
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented...
#define CODEC_FLAG_PSNR
error[?] variables will be set during encoding.
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
AVComponentDescriptor comp[4]
Parameters that describe how pixels are packed.
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
#define CODEC_FLAG_GLOBAL_HEADER
Place global headers in extradata instead of every keyframe.
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.
AVDictionaryEntry * av_dict_get(const AVDictionary *m, const char *key, const AVDictionaryEntry *prev, int flags)
Get a dictionary entry with matching key.
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
uint16_t depth_minus1
Number of bits in the component minus 1.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
#define CODEC_CAP_DELAY
Encoder or decoder requires flushing with NULL input at the end in order to give the complete and cor...
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
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. ...
const char * name
Name of the codec implementation.
#define AV_PIX_FMT_YUV444P10
Libavcodec external API header.
int flags
A combination of AV_PKT_FLAG values.
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
int av_reduce(int *dst_num, int *dst_den, int64_t num, int64_t den, int64_t max)
Reduce a fraction.
common internal API header
#define FF_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding...
#define FF_COMPLIANCE_EXPERIMENTAL
Allow nonstandardized experimental things.
static av_cold void libx265_encode_init_csp(AVCodec *codec)
int bit_rate
the average bitrate
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
static av_cold int libx265_encode_init(AVCodecContext *avctx)
int width
picture width / height.
#define CODEC_CAP_AUTO_THREADS
Codec supports avctx->thread_count == 0 (auto).
enum AVColorPrimaries color_primaries
Chromaticity coordinates of the source primaries.
int ff_alloc_packet(AVPacket *avpkt, int size)
int ticks_per_frame
For some codecs, the time base is closer to the field rate than the frame rate.
int thread_count
thread count is used to decide how many independent tasks should be passed to execute() ...
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.
#define AV_LOG_INFO
Standard information.
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.
#define AV_PIX_FMT_YUV422P10
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
ITU-R BT2020 constant luminance system.
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
common internal api header.
common internal and external API header
static enum AVPixelFormat x265_csp_twelve[]
static const AVCodecDefault x265_defaults[]
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.
static const AVCodecDefault defaults[]
#define AVERROR_EXTERNAL
Generic error in an external library.
AVPixelFormat
Pixel format.
This structure stores compressed data.
int strict_std_compliance
strictly follow the standard (MPEG4, ...).
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...