/* x264_param_default: * fill x264_param_t with default values and do CPU detection */ voidx264_param_default( x264_param_t * );
/* x264_param_parse: * set one parameter by name. * returns 0 on success, or returns one of the following errors. * note: BAD_VALUE occurs only if it can't even parse the value, * numerical range is not checked until x264_encoder_open() or * x264_encoder_reconfig(). * value=NULL means "true" for boolean options, but is a BAD_VALUE for non-booleans. */ #define X264_PARAM_BAD_NAME (-1) #define X264_PARAM_BAD_VALUE (-2) intx264_param_parse( x264_param_t *, constchar *name, constchar *value );
/* These functions expose the full power of x264's preset-tune-profile system for * easy adjustment of large numbers of internal parameters. * * In order to replicate x264CLI's option handling, these functions MUST be called * in the following order: * 1) x264_param_default_preset * 2) Custom user options (via param_parse or directly assigned variables) * 3) x264_param_apply_fastfirstpass * 4) x264_param_apply_profile * * Additionally, x264CLI does not apply step 3 if the preset chosen is "placebo" * or --slow-firstpass is set. */
/* x264_param_default_preset: * The same as x264_param_default, but also use the passed preset and tune * to modify the default settings. * (either can be NULL, which implies no preset or no tune, respectively) * * Currently available presets are, ordered from fastest to slowest: */ staticconstchar * const x264_preset_names[] = { "ultrafast", "superfast", "veryfast", "faster", "fast", "medium", "slow", "slower", "veryslow", "placebo", 0 };
/* The presets can also be indexed numerically, as in: * x264_param_default_preset( ¶m, "3", ... ) * with ultrafast mapping to "0" and placebo mapping to "9". This mapping may * of course change if new presets are added in between, but will always be * ordered from fastest to slowest. * * Warning: the speed of these presets scales dramatically. Ultrafast is a full * 100 times faster than placebo! * * Currently available tunings are: */ staticconstchar * const x264_tune_names[] = { "film", "animation", "grain", "stillimage", "psnr", "ssim", "fastdecode", "zerolatency", 0 };
/* Multiple tunings can be used if separated by a delimiter in ",./-+", * however multiple psy tunings cannot be used. * film, animation, grain, stillimage, psnr, and ssim are psy tunings. * * returns 0 on success, negative on failure (e.g. invalid preset/tune name). */ intx264_param_default_preset( x264_param_t *, constchar *preset, constchar *tune );
/* x264_param_apply_fastfirstpass: * If first-pass mode is set (rc.b_stat_read == 0, rc.b_stat_write == 1), * modify the encoder settings to disable options generally not useful on * the first pass. */ voidx264_param_apply_fastfirstpass( x264_param_t * );
/* x264_param_apply_profile: * Applies the restrictions of the given profile. * Currently available profiles are, from most to least restrictive: */ staticconstchar * const x264_profile_names[] = { "baseline", "main", "high", "high10", "high422", "high444", 0 };
/* (can be NULL, in which case the function will do nothing) * * Does NOT guarantee that the given profile will be used: if the restrictions * of "High" are applied to settings that are already Baseline-compatible, the * stream will remain baseline. In short, it does not increase settings, only * decrease them. * * returns 0 on success, negative on failure (e.g. invalid profile name). */ intx264_param_apply_profile( x264_param_t *, constchar *profile );
typedefstructx264_param_t { /* CPU flags */ unsignedint cpu; int i_threads; /* encode multiple frames in parallel */ int i_lookahead_threads; /* multiple threads for lookahead analysis */ int b_sliced_threads; /* Whether to use slice-based threading. */ int b_deterministic; /* whether to allow non-deterministic optimizations when threaded */ int b_cpu_independent; /* force canonical behavior rather than cpu-dependent optimal algorithms */ int i_sync_lookahead; /* threaded lookahead buffer */
/* Video Properties */ int i_width; int i_height; int i_csp; /* CSP of encoded bitstream */ int i_bitdepth; int i_level_idc; int i_frame_total; /* number of frames to encode if known, else 0 */
/* NAL HRD * Uses Buffering and Picture Timing SEIs to signal HRD * The HRD in H.264 was not designed with VFR in mind. * It is therefore not recommendeded to use NAL HRD with VFR. * Furthermore, reconfiguring the VBV (via x264_encoder_reconfig) * will currently generate invalid HRD. */ int i_nal_hrd;
struct { /* they will be reduced to be 0 < x <= 65535 and prime */ int i_sar_height; int i_sar_width;
int i_overscan; /* 0=undef, 1=no overscan, 2=overscan */
/* see h264 annex E for the values of the following */ int i_vidformat; int b_fullrange; int i_colorprim; int i_transfer; int i_colmatrix; int i_chroma_loc; /* both top & bottom */ } vui;
/* Bitstream parameters */ int i_frame_reference; /* Maximum number of reference frames */ int i_dpb_size; /* Force a DPB size larger than that implied by B-frames and reference frames. * Useful in combination with interactive error resilience. */ int i_keyint_max; /* Force an IDR keyframe at this interval */ int i_keyint_min; /* Scenecuts closer together than this are coded as I, not IDR. */ int i_scenecut_threshold; /* how aggressively to insert extra I frames */ int b_intra_refresh; /* Whether or not to use periodic intra refresh instead of IDR frames. */
int i_bframe; /* how many b-frame between 2 references pictures */ int i_bframe_adaptive; int i_bframe_bias; int i_bframe_pyramid; /* Keep some B-frames as references: 0=off, 1=strict hierarchical, 2=normal */ int b_open_gop; int b_bluray_compat; int i_avcintra_class; int i_avcintra_flavor;
int b_deblocking_filter; int i_deblocking_filter_alphac0; /* [-6, 6] -6 light filter, 6 strong */ int i_deblocking_filter_beta; /* [-6, 6] idem */
int b_cabac; int i_cabac_init_idc;
int b_interlaced; int b_constrained_intra;
int i_cqm_preset; char *psz_cqm_file; /* filename (in UTF-8) of CQM file, JM format */ uint8_t cqm_4iy[16]; /* used only if i_cqm_preset == X264_CQM_CUSTOM */ uint8_t cqm_4py[16]; uint8_t cqm_4ic[16]; uint8_t cqm_4pc[16]; uint8_t cqm_8iy[64]; uint8_t cqm_8py[64]; uint8_t cqm_8ic[64]; uint8_t cqm_8pc[64];
/* Log */ void (*pf_log)( void *, int i_level, constchar *psz, va_list ); void *p_log_private; int i_log_level; int b_full_recon; /* fully reconstruct frames, even when not necessary for encoding. Implied by psz_dump_yuv */ char *psz_dump_yuv; /* filename (in UTF-8) for reconstructed frames */
/* Encoder analyser parameters */ struct { unsignedint intra; /* intra partitions */ unsignedint inter; /* inter partitions */
int b_transform_8x8; int i_weighted_pred; /* weighting for P-frames */ int b_weighted_bipred; /* implicit weighting for B-frames */ int i_direct_mv_pred; /* spatial vs temporal mv prediction */ int i_chroma_qp_offset;
int i_me_method; /* motion estimation algorithm to use (X264_ME_*) */ int i_me_range; /* integer pixel motion estimation search range (from predicted mv) */ int i_mv_range; /* maximum length of a mv (in pixels). -1 = auto, based on level */ int i_mv_range_thread; /* minimum space between threads. -1 = auto, based on number of threads. */ int i_subpel_refine; /* subpixel motion estimation quality */ int b_chroma_me; /* chroma ME for subpel and mode decision in P-frames */ int b_mixed_references; /* allow each mb partition to have its own reference number */ int i_trellis; /* trellis RD quantization */ int b_fast_pskip; /* early SKIP detection on P-frames */ int b_dct_decimate; /* transform coefficient thresholding on P-frames */ int i_noise_reduction; /* adaptive pseudo-deadzone */ float f_psy_rd; /* Psy RD strength */ float f_psy_trellis; /* Psy trellis strength */ int b_psy; /* Toggle all psy optimizations */
int b_mb_info; /* Use input mb_info data in x264_picture_t */ int b_mb_info_update; /* Update the values in mb_info according to the results of encoding. */
/* the deadzone size that will be used in luma quantization */ int i_luma_deadzone[2]; /* {inter, intra} */
int b_psnr; /* compute and print PSNR stats */ int b_ssim; /* compute and print SSIM stats */ } analyse;
/* Rate control parameters */ struct { int i_rc_method; /* X264_RC_* */
int i_qp_constant; /* 0=lossless */ int i_qp_min; /* min allowed QP value */ int i_qp_max; /* max allowed QP value */ int i_qp_step; /* max QP step between frames */
int i_bitrate; float f_rf_constant; /* 1pass VBR, nominal QP */ float f_rf_constant_max; /* In CRF mode, maximum CRF as caused by VBV */ float f_rate_tolerance; int i_vbv_max_bitrate; int i_vbv_buffer_size; float f_vbv_buffer_init; /* <=1: fraction of buffer_size. >1: kbit */ float f_ip_factor; float f_pb_factor;
/* VBV filler: force CBR VBV and use filler bytes to ensure hard-CBR. * Implied by NAL-HRD CBR. */ int b_filler;
int i_aq_mode; /* psy adaptive QP. (X264_AQ_*) */ float f_aq_strength; int b_mb_tree; /* Macroblock-tree ratecontrol. */ int i_lookahead;
/* 2pass */ int b_stat_write; /* Enable stat writing in psz_stat_out */ char *psz_stat_out; /* output filename (in UTF-8) of the 2pass stats file */ int b_stat_read; /* Read stat from psz_stat_in and use it */ char *psz_stat_in; /* input filename (in UTF-8) of the 2pass stats file */
/* 2pass params (same as ffmpeg ones) */ float f_qcompress; /* 0.0 => cbr, 1.0 => constant qp */ float f_qblur; /* temporally blur quants */ float f_complexity_blur; /* temporally blur complexity */ x264_zone_t *zones; /* ratecontrol overrides */ int i_zones; /* number of zone_t's */ char *psz_zones; /* alternate method of specifying zones */ } rc;
/* Cropping Rectangle parameters: added to those implicitly defined by non-mod16 video resolutions. */ struct { unsignedint i_left; unsignedint i_top; unsignedint i_right; unsignedint i_bottom; } crop_rect;
/* frame packing arrangement flag */ int i_frame_packing;
/* alternative transfer SEI */ int i_alternative_transfer;
/* Muxing parameters */ int b_aud; /* generate access unit delimiters */ int b_repeat_headers; /* put SPS/PPS before each keyframe */ int b_annexb; /* if set, place start codes (4 bytes) before NAL units, * otherwise place size (4 bytes) before NAL units. */ int i_sps_id; /* SPS and PPS id number */ int b_vfr_input; /* VFR input. If 1, use timebase and timestamps for ratecontrol purposes. * If 0, use fps only. */ int b_pulldown; /* use explicity set timebase for CFR */ uint32_t i_fps_num; uint32_t i_fps_den; uint32_t i_timebase_num; /* Timebase numerator */ uint32_t i_timebase_den; /* Timebase denominator */
int b_tff;
/* Pulldown: * The correct pic_struct must be passed with each input frame. * The input timebase should be the timebase corresponding to the output framerate. This should be constant. * e.g. for 3:2 pulldown timebase should be 1001/30000 * The PTS passed with each frame must be the PTS of the frame after pulldown is applied. * Frame doubling and tripling require b_vfr_input set to zero (see H.264 Table D-1) * * Pulldown changes are not clearly defined in H.264. Therefore, it is the calling app's responsibility to manage this. */
int b_pic_struct;
/* Fake Interlaced. * * Used only when b_interlaced=0. Setting this flag makes it possible to flag the stream as PAFF interlaced yet * encode all frames progessively. It is useful for encoding 25p and 30p Blu-Ray streams. */
int b_fake_interlaced;
/* Don't optimize header parameters based on video content, e.g. ensure that splitting an input video, compressing * each part, and stitching them back together will result in identical SPS/PPS. This is necessary for stitching * with container formats that don't allow multiple SPS/PPS. */ int b_stitchable;
int b_opencl; /* use OpenCL when available */ int i_opencl_device; /* specify count of GPU devices to skip, for CLI users */ void *opencl_device_id; /* pass explicit cl_device_id as void*, for API users */ char *psz_clbin_file; /* filename (in UTF-8) of the compiled OpenCL kernel cache file */
/* Slicing parameters */ int i_slice_max_size; /* Max size per slice in bytes; includes estimated NAL overhead. */ int i_slice_max_mbs; /* Max number of MBs per slice; overrides i_slice_count. */ int i_slice_min_mbs; /* Min number of MBs per slice */ int i_slice_count; /* Number of slices per frame: forces rectangular slices. */ int i_slice_count_max; /* Absolute cap on slices per frame; stops applying slice-max-size * and slice-max-mbs if this is reached. */
/* Optional callback for freeing this x264_param_t when it is done being used. * Only used when the x264_param_t sits in memory for an indefinite period of time, * i.e. when an x264_param_t is passed to x264_t in an x264_picture_t or in zones. * Not used when x264_encoder_reconfig is called directly. */ void (*param_free)( void* );
/* Optional low-level callback for low-latency encoding. Called for each output NAL unit * immediately after the NAL unit is finished encoding. This allows the calling application * to begin processing video data (e.g. by sending packets over a network) before the frame * is done encoding. * * This callback MUST do the following in order to work correctly: * 1) Have available an output buffer of at least size nal->i_payload*3/2 + 5 + 64. * 2) Call x264_nal_encode( h, dst, nal ), where dst is the output buffer. * After these steps, the content of nal is valid and can be used in the same way as if * the NAL unit were output by x264_encoder_encode. * * This does not need to be synchronous with the encoding process: the data pointed to * by nal (both before and after x264_nal_encode) will remain valid until the next * x264_encoder_encode call. The callback must be re-entrant. * * This callback does not work with frame-based threads; threads must be disabled * or sliced-threads enabled. This callback also does not work as one would expect * with HRD -- since the buffering period SEI cannot be calculated until the frame * is finished encoding, it will not be sent via this callback. * * Note also that the NALs are not necessarily returned in order when sliced threads is * enabled. Accordingly, the variable i_first_mb and i_last_mb are available in * x264_nal_t to help the calling application reorder the slices if necessary. * * When this callback is enabled, x264_encoder_encode does not return valid NALs; * the calling application is expected to acquire all output NALs through the callback. * * It is generally sensible to combine this callback with a use of slice-max-mbs or * slice-max-size. * * The opaque pointer is the opaque pointer from the input frame associated with this * NAL unit. This helps distinguish between nalu_process calls from different sources, * e.g. if doing multiple encodes in one process. */ void (*nalu_process)( x264_t *h, x264_nal_t *nal, void *opaque ); } x264_param_t;
Reprint policy:
All articles in this blog are used except for special statements
CC BY 4.0
reprint polocy. If reproduced, please indicate source
Yin Wenjie
!