22 #include <va/va_enc_h264.h>
46 0x59, 0x94, 0x8b, 0x28, 0x11, 0xec, 0x45, 0xaf,
47 0x96, 0x75, 0x19, 0xd4, 0x1f, 0xea, 0xa9, 0x4d,
106 char *
data,
size_t *data_len,
120 "%zu < %zu.\n", *data_len,
151 char *
data,
size_t *data_len)
181 char *
data,
size_t *data_len)
207 char *
data,
size_t *data_len)
266 *type = VAEncPackedHeaderRawData;
276 *type = VAEncPackedHeaderH264_SEI;
303 memset(sps, 0,
sizeof(*sps));
304 memset(pps, 0,
sizeof(*pps));
327 dpb_frames = 1 + (ctx->
b_per_p > 0);
346 "to any level: using level 6.2.\n");
387 { 1, 1 }, { 12, 11 }, { 10, 11 }, { 16, 11 },
388 { 40, 33 }, { 24, 11 }, { 20, 11 }, { 32, 11 },
389 { 80, 33 }, { 18, 11 }, { 15, 11 }, { 64, 33 },
390 { 160, 99 }, { 4, 3 }, { 3, 2 }, { 2, 1 },
527 *vseq = (VAEncSequenceParameterBufferH264) {
577 *vpic = (VAEncPictureParameterBufferH264) {
579 .picture_id = VA_INVALID_ID,
580 .flags = VA_PICTURE_H264_INVALID,
583 .coded_buf = VA_INVALID_ID,
601 .deblocking_filter_control_present_flag =
604 .pic_order_present_flag =
692 .exact_match_flag = 1,
693 .broken_link_flag = ctx->
b_per_p > 0,
699 vpic->CurrPic = (VAPictureH264) {
707 for (i = 0; i < pic->
nb_refs; i++) {
714 vpic->ReferenceFrames[i] = (VAPictureH264) {
716 .frame_idx = frame_num,
717 .flags = VA_PICTURE_H264_SHORT_TERM_REFERENCE,
718 .TopFieldOrderCnt = pic_order_cnt,
719 .BottomFieldOrderCnt = pic_order_cnt,
723 vpic->ReferenceFrames[i] = (VAPictureH264) {
724 .picture_id = VA_INVALID_ID,
725 .flags = VA_PICTURE_H264_INVALID,
783 vslice->macroblock_info = VA_INVALID_ID;
794 vslice->RefPicList0[i].picture_id = VA_INVALID_ID;
795 vslice->RefPicList0[i].flags = VA_PICTURE_H264_INVALID;
796 vslice->RefPicList1[i].picture_id = VA_INVALID_ID;
797 vslice->RefPicList1[i].flags = VA_PICTURE_H264_INVALID;
805 vslice->RefPicList0[0] = vpic->ReferenceFrames[0];
810 vslice->RefPicList1[0] = vpic->ReferenceFrames[1];
847 "%d / %d / %d for IDR- / P- / B-frames.\n",
863 const char *vaapi = VA_VERSION_S;
873 driver =
"unknown driver";
875 len =
snprintf(
NULL, 0,
"%s / VAAPI %s / %s", lavc, vaapi, driver);
882 "%s / VAAPI %s / %s", lavc, vaapi, driver);
896 8, 3, 1, 1, VAProfileH264ConstrainedBaseline },
907 .sequence_params_size =
sizeof(VAEncSequenceParameterBufferH264),
910 .picture_params_size =
sizeof(VAEncPictureParameterBufferH264),
913 .slice_params_size =
sizeof(VAEncSliceParameterBufferH264),
916 .sequence_header_type = VAEncPackedHeaderSequence,
919 .slice_header_type = VAEncPackedHeaderH264_Slice,
943 "supported, using constrained baseline profile instead.\n");
948 "is not supported.\n");
953 "are not supported.\n");
962 "are not supported.\n");
968 "in 8-bit unsigned integer.\n", avctx->
level);
973 VA_ENC_PACKED_HEADER_SEQUENCE |
974 VA_ENC_PACKED_HEADER_SLICE |
975 VA_ENC_PACKED_HEADER_MISC;
995 #define OFFSET(x) offsetof(VAAPIEncodeH264Context, x)
996 #define FLAGS (AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM)
1000 {
"qp",
"Constant QP (for P-frames; scaled by qfactor/qoffset for I/B)",
1002 {
"quality",
"Set encode quality (trades off against speed, higher is faster)",
1004 {
"coder",
"Entropy coder type",
1011 {
"aud",
"Include AUD",
1014 {
"sei",
"Set SEI to include",
1017 0, INT_MAX,
FLAGS,
"sei" },
1018 {
"identifier",
"Include encoder version identifier",
1020 INT_MIN, INT_MAX,
FLAGS,
"sei" },
1021 {
"timing",
"Include timing parameters (buffering_period and pic_timing)",
1023 INT_MIN, INT_MAX,
FLAGS,
"sei" },
1024 {
"recovery_point",
"Include recovery points where appropriate",
1026 INT_MIN, INT_MAX,
FLAGS,
"sei" },
1028 {
"profile",
"Set profile (profile_idc and constraint_set*_flag)",
1032 #define PROFILE(name, value) name, NULL, 0, AV_OPT_TYPE_CONST, \
1033 { .i64 = value }, 0, 0, FLAGS, "profile"
1039 {
"level",
"Set level (level_idc)",
1043 #define LEVEL(name, value) name, NULL, 0, AV_OPT_TYPE_CONST, \
1044 { .i64 = value }, 0, 0, FLAGS, "level"
1046 {
LEVEL(
"1.1", 11) },
1047 {
LEVEL(
"1.2", 12) },
1048 {
LEVEL(
"1.3", 13) },
1050 {
LEVEL(
"2.1", 21) },
1051 {
LEVEL(
"2.2", 22) },
1053 {
LEVEL(
"3.1", 31) },
1054 {
LEVEL(
"3.2", 32) },
1056 {
LEVEL(
"4.1", 41) },
1057 {
LEVEL(
"4.2", 42) },
1059 {
LEVEL(
"5.1", 51) },
1060 {
LEVEL(
"5.2", 52) },
1062 {
LEVEL(
"6.1", 61) },
1063 {
LEVEL(
"6.2", 62) },
1073 {
"i_qfactor",
"1" },
1074 {
"i_qoffset",
"0" },
1075 {
"b_qfactor",
"6/5" },
1076 {
"b_qoffset",
"0" },
1090 .
name =
"h264_vaapi",
1098 .priv_class = &vaapi_encode_h264_class,
1100 .
defaults = vaapi_encode_h264_defaults,
1105 .wrapper_name =
"vaapi",
#define FF_PROFILE_H264_MAIN
H264RawNALUnitHeader nal_unit_header
uint8_t frame_cropping_flag
uint8_t deblocking_filter_control_present_flag
static const VAAPIEncodeType vaapi_encode_type_h264
#define FF_PROFILE_H264_CAVLC_444
uint8_t bit_depth_chroma_minus8
#define FF_COMPRESSION_DEFAULT
static av_cold int vaapi_encode_h264_configure(AVCodecContext *avctx)
char * sei_identifier_string
ptrdiff_t const GLvoid * data
union H264RawSEIPayload::@50 payload
uint16_t recovery_frame_cnt
uint8_t dpb_output_delay_length_minus1
struct H264RawSEIBufferingPeriod::@49 nal
uint8_t initial_cpb_removal_delay_length_minus1
#define AV_LOG_WARNING
Something somehow does not look correct.
int64_t bit_rate
the average bitrate
#define LIBAVUTIL_VERSION_INT
uint8_t chroma_sample_loc_type_bottom_field
static av_cold int init(AVCodecContext *avctx)
uint8_t constraint_set3_flag
#define AV_CODEC_CAP_HARDWARE
Codec is backed by a hardware implementation.
int ff_cbs_init(CodedBitstreamContext **ctx_ptr, enum AVCodecID codec_id, void *log_ctx)
Create and initialise a new context for the given codec.
H264RawNALUnitHeader nal_unit_header
enum AVColorRange color_range
MPEG vs JPEG YUV range.
H264RawSEIRecoveryPoint recovery_point
uint8_t log2_max_frame_num_minus4
const char * av_default_item_name(void *ptr)
Return the context name.
int ff_cbs_insert_unit_content(CodedBitstreamContext *ctx, CodedBitstreamFragment *frag, int position, CodedBitstreamUnitType type, void *content, AVBufferRef *content_buf)
Insert a new unit into a fragment with the given content.
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown) That is the width of a pixel divided by the height of the pixel...
uint8_t time_offset_length
uint8_t low_delay_hrd_flag
uint8_t seq_parameter_set_id
void * codec_sequence_params
VAEncMiscParameterHRD hrd
uint8_t max_dec_frame_buffering
uint8_t fixed_frame_rate_flag
float i_quant_offset
qscale offset between P and I-frames
static const AVClass vaapi_encode_h264_class
#define FF_PROFILE_H264_HIGH_444_PREDICTIVE
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented...
uint8_t weighted_pred_flag
uint8_t constraint_set4_flag
H264RawHRD nal_hrd_parameters
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...
static int vaapi_encode_h264_write_extra_header(AVCodecContext *avctx, VAAPIEncodePicture *pic, int index, int *type, char *data, size_t *data_len)
#define av_assert0(cond)
assert() equivalent, that is always enabled.
static const AVOption vaapi_encode_h264_options[]
H264RawSEIRecoveryPoint sei_recovery_point
#define FF_PROFILE_H264_BASELINE
uint16_t frame_crop_top_offset
uint16_t pic_width_in_mbs_minus1
static const AVCodecDefault vaapi_encode_h264_defaults[]
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...
static const uint8_t vaapi_encode_h264_sei_identifier_uuid[16]
uint32_t num_units_in_tick
uint8_t mb_adaptive_frame_field_flag
uint8_t transform_8x8_mode_flag
uint8_t constrained_intra_pred_flag
uint32_t cpb_size_value_minus1[H264_MAX_CPB_CNT]
uint16_t frame_crop_left_offset
static int vaapi_encode_h264_init_picture_params(AVCodecContext *avctx, VAAPIEncodePicture *pic)
static av_cold int vaapi_encode_h264_init(AVCodecContext *avctx)
#define AVERROR_EOF
End of file.
#define FF_PROFILE_H264_EXTENDED
#define AV_LOG_VERBOSE
Detailed information.
VASurfaceID recon_surface
static const uint8_t header[24]
H264RawNALUnitHeader nal_unit_header
enum AVChromaLocation chroma_sample_location
This defines the location of chroma samples.
int8_t second_chroma_qp_index_offset
uint8_t nal_hrd_parameters_present_flag
uint8_t bit_depth_luma_minus8
size_t data_size
The number of bytes in the bitstream.
H.264 common definitions.
uint8_t pic_scaling_matrix_present_flag
uint8_t chroma_sample_loc_type_top_field
buffering period (H.264, D.1.1)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
uint8_t aspect_ratio_info_present_flag
void ff_cbs_fragment_uninit(CodedBitstreamContext *ctx, CodedBitstreamFragment *frag)
Free all allocated memory in a fragment.
uint8_t max_num_ref_frames
uint8_t weighted_bipred_idc
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
const H264LevelDescriptor * ff_h264_guess_level(int profile_idc, int64_t bitrate, int width, int height, int max_dec_frame_buffering)
Guess the level of a stream from some parameters.
uint8_t transfer_characteristics
static int vaapi_encode_h264_write_access_unit(AVCodecContext *avctx, char *data, size_t *data_len, CodedBitstreamFragment *au)
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
CodedBitstreamContext * cbc
#define FF_PROFILE_H264_HIGH_422
#define FF_PROFILE_H264_HIGH
uint32_t initial_cpb_removal_delay_offset[H264_MAX_CPB_CNT]
uint8_t num_ref_idx_l1_default_active_minus1
simple assert() macros that are a bit more flexible than ISO C assert().
const char * name
Name of the codec implementation.
uint8_t frame_mbs_only_flag
float i_quant_factor
qscale factor between P- and I-frames If > 0 then the last P-frame quantizer will be used (q = lastp_...
static const AVCodecDefault defaults[]
uint8_t seq_parameter_set_id
uint8_t seq_scaling_matrix_present_flag
static int vaapi_encode_h264_init_sequence_params(AVCodecContext *avctx)
void * codec_picture_params
size_t data_bit_padding
The number of bits which should be ignored in the final byte.
H264RawSEIPicTiming pic_timing
uint8_t timing_info_present_flag
H264RawSEIPicTiming sei_pic_timing
uint8_t video_full_range_flag
uint8_t seq_parameter_set_id
#define LEVEL(name, value)
H264RawSEIUserDataUnregistered user_data_unregistered
common internal API header
AVCodec ff_h264_vaapi_encoder
static int vaapi_encode_h264_write_sequence_header(AVCodecContext *avctx, char *data, size_t *data_len)
uint16_t frame_crop_bottom_offset
int width
picture width / height.
uint8_t vui_parameters_present_flag
#define FF_PROFILE_UNKNOWN
const VAAPIEncodeProfile * profiles
av_cold int ff_vaapi_encode_init(AVCodecContext *avctx)
uint32_t cpb_removal_delay
uint8_t colour_description_present_flag
enum AVColorPrimaries color_primaries
Chromaticity coordinates of the source primaries.
static const VAAPIEncodeProfile vaapi_encode_h264_profiles[]
uint8_t video_signal_type_present_flag
void * codec_picture_params
static int vaapi_encode_h264_write_slice_header(AVCodecContext *avctx, VAAPIEncodePicture *pic, VAAPIEncodeSlice *slice, char *data, size_t *data_len)
static int vaapi_encode_h264_add_nal(AVCodecContext *avctx, CodedBitstreamFragment *au, void *nal_unit)
int8_t chroma_qp_index_offset
uint8_t constraint_set5_flag
uint8_t chroma_format_idc
uint8_t * data
Pointer to the bitstream form of this fragment.
#define FF_ARRAY_ELEMS(a)
the normal 2^n-1 "JPEG" YUV ranges
int ff_cbs_write_fragment_data(CodedBitstreamContext *ctx, CodedBitstreamFragment *frag)
Write the content of the fragment to its own internal buffer.
VADisplay display
The VADisplay handle, to be filled by the user.
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
struct VAAPIEncodePicture * refs[MAX_PICTURE_REFERENCES]
uint32_t bit_rate_value_minus1[H264_MAX_CPB_CNT]
H264RawNALUnitHeader nal_unit_header
uint8_t chroma_loc_info_present_flag
uint8_t cbr_flag[H264_MAX_CPB_CNT]
const struct VAAPIEncodeType * codec
Libavcodec external API header.
#define FF_PROFILE_H264_HIGH_422_INTRA
uint8_t bottom_field_pic_order_in_frame_present_flag
uint8_t entropy_coding_mode_flag
Coded bitstream fragment structure, combining one or more units.
VAAPIEncodeContext common
main external API structure.
uint8_t uuid_iso_iec_11578[16]
#define FF_PROFILE_H264_HIGH_10_INTRA
static int FUNC() aud(CodedBitstreamContext *ctx, RWContext *rw, H264RawAUD *current)
uint8_t pic_order_cnt_type
Describe the class of an AVClass context structure.
static int FUNC() pps(CodedBitstreamContext *ctx, RWContext *rw, H264RawPPS *current)
Context structure for coded bitstream operations.
uint8_t matrix_coefficients
uint8_t num_ref_idx_l0_default_active_minus1
enum AVColorSpace colorspace
YUV colorspace type.
Rational number (pair of numerator and denominator).
enum AVColorTransferCharacteristic color_trc
Color Transfer Characteristic.
static int FUNC() sps(CodedBitstreamContext *ctx, RWContext *rw, H264RawSPS *current)
recovery point (frame # to decoder sync)
#define FF_PROFILE_H264_HIGH_444
uint8_t log2_max_mv_length_horizontal
void ff_cbs_close(CodedBitstreamContext **ctx_ptr)
Close a context and free all internal state.
float b_quant_offset
qscale offset between IP and B-frames
H264RawSEIBufferingPeriod buffering_period
H264RawSEIPayload payload[H264_MAX_SEI_PAYLOADS]
static enum AVPixelFormat pix_fmts[]
CodedBitstreamFragment current_access_unit
#define VAAPI_ENCODE_COMMON_OPTIONS
uint8_t direct_8x8_inference_flag
int sei_cbr_workaround_needed
static int vaapi_encode_h264_init_slice_params(AVCodecContext *avctx, VAAPIEncodePicture *pic, VAAPIEncodeSlice *slice)
uint32_t initial_cpb_removal_delay[H264_MAX_CPB_CNT]
common internal api header.
common internal and external API header
static int ref[MAX_W *MAX_W]
uint8_t redundant_pic_cnt_present_flag
struct VAAPIEncodeContext::@162 hrd_params
uint8_t cpb_removal_delay_length_minus1
uint8_t motion_vectors_over_pic_boundaries_flag
int ff_vaapi_encode2(AVCodecContext *avctx, AVPacket *pkt, const AVFrame *input_image, int *got_packet)
static int FUNC() sei(CodedBitstreamContext *ctx, RWContext *rw, H264RawSEI *current)
uint8_t bitstream_restriction_flag
uint16_t frame_crop_right_offset
uint8_t pic_parameter_set_id
uint8_t max_num_reorder_frames
H264RawSEIUserDataUnregistered sei_identifier
#define PROFILE(name, value)
uint8_t log2_max_mv_length_vertical
H264RawSliceHeader header
uint8_t log2_max_pic_order_cnt_lsb_minus4
static av_cold int vaapi_encode_h264_close(AVCodecContext *avctx)
void * codec_slice_params
uint8_t delta_pic_order_always_zero_flag
H264RawSEIBufferingPeriod sei_buffering_period
#define FF_PROFILE_H264_HIGH_444_INTRA
int8_t pic_init_qp_minus26
unsigned int desired_packed_headers
uint8_t constraint_set1_flag
uint16_t pic_height_in_map_units_minus1
#define FF_PROFILE_H264_CONSTRAINED_BASELINE
#define FF_PROFILE_H264_HIGH_10
AVPixelFormat
Pixel format.
av_cold int ff_vaapi_encode_close(AVCodecContext *avctx)
AVVAAPIDeviceContext * hwctx
uint8_t constraint_set3_flag