FFmpeg
|
Mathematical utilities for working with timestamp and time base. More...
Modules | |
AVRational | |
Rational number calculation. | |
Macros | |
#define | ff_ctz ff_ctz_c |
#define | ff_ctzll ff_ctzll_c |
#define | ff_clz ff_clz_c |
#define | av_parity __builtin_parity |
Enumerations | |
enum | AVRounding { AV_ROUND_ZERO = 0, AV_ROUND_INF = 1, AV_ROUND_DOWN = 2, AV_ROUND_UP = 3, AV_ROUND_NEAR_INF = 5, AV_ROUND_PASS_MINMAX = 8192 } |
Rounding methods. More... | |
Functions | |
static av_always_inline av_const int | ff_ctz_c (int v) |
Trailing zero bit count. More... | |
static av_always_inline av_const int | ff_ctzll_c (long long v) |
static av_always_inline av_const unsigned | ff_clz_c (unsigned x) |
int64_t av_const | av_gcd (int64_t a, int64_t b) |
Compute the greatest common divisor of two integer operands. More... | |
int64_t | av_rescale (int64_t a, int64_t b, int64_t c) av_const |
Rescale a 64-bit integer with rounding to nearest. More... | |
int64_t | av_rescale_rnd (int64_t a, int64_t b, int64_t c, enum AVRounding rnd) av_const |
Rescale a 64-bit integer with specified rounding. More... | |
int64_t | av_rescale_q (int64_t a, AVRational bq, AVRational cq) av_const |
Rescale a 64-bit integer by 2 rational numbers. More... | |
int64_t | av_rescale_q_rnd (int64_t a, AVRational bq, AVRational cq, enum AVRounding rnd) av_const |
Rescale a 64-bit integer by 2 rational numbers with specified rounding. More... | |
int | av_compare_ts (int64_t ts_a, AVRational tb_a, int64_t ts_b, AVRational tb_b) |
Compare two timestamps each in its own time base. More... | |
int64_t | av_compare_mod (uint64_t a, uint64_t b, uint64_t mod) |
Compare the remainders of two integer operands divided by a common divisor. More... | |
int64_t | av_rescale_delta (AVRational in_tb, int64_t in_ts, AVRational fs_tb, int duration, int64_t *last, AVRational out_tb) |
Rescale a timestamp while preserving known durations. More... | |
int64_t | av_add_stable (AVRational ts_tb, int64_t ts, AVRational inc_tb, int64_t inc) |
Add a value to a timestamp. More... | |
Mathematical utilities for working with timestamp and time base.
#define ff_ctz ff_ctz_c |
Definition at line 106 of file intmath.h.
Referenced by av_frame_apply_cropping(), cbs_h264_write_nal_unit(), cbs_h265_write_nal_unit(), get_bit_length(), refill2(), remove_wasted_bits(), and vp9_raw_reorder_make_output().
#define ff_ctzll ff_ctzll_c |
Definition at line 126 of file intmath.h.
Referenced by av_gcd(), and ffat_get_channel_id().
#define ff_clz ff_clz_c |
Definition at line 142 of file intmath.h.
Referenced by convert_coeffs(), fill_optable(), load_data(), read_high_coeffs(), read_low_coeffs(), sbc_calc_scalefactors(), and sbc_calc_scalefactors_j().
#define av_parity __builtin_parity |
Definition at line 158 of file intmath.h.
Referenced by check_vanc_parity_checksum(), decode_frame(), and validate_cc_data_pair().
enum AVRounding |
Rounding methods.
Enumerator | |
---|---|
AV_ROUND_ZERO |
Round toward zero. |
AV_ROUND_INF |
Round away from zero. |
AV_ROUND_DOWN |
Round toward -infinity. |
AV_ROUND_UP |
Round toward +infinity. |
AV_ROUND_NEAR_INF |
Round to nearest and halfway cases away from zero. |
AV_ROUND_PASS_MINMAX |
Flag telling rescaling functions to pass Unlike other values of the enumeration AVRounding, this value is a bitmask that must be used in conjunction with another value of the enumeration through a bitwise OR, in order to set behavior for normal cases. // Rescaling 3:
// Calculating 3 * 1 / 2
// 3 / 2 is rounded up to 2
// => 2
// Rescaling AV_NOPTS_VALUE:
// AV_NOPTS_VALUE == INT64_MIN
// AV_NOPTS_VALUE is passed through
// => AV_NOPTS_VALUE
|
Definition at line 79 of file mathematics.h.
|
static |
|
static |
|
static |
int64_t av_const av_gcd | ( | int64_t | a, |
int64_t | b | ||
) |
Compute the greatest common divisor of two integer operands.
a,b | Operands |
Definition at line 37 of file mathematics.c.
Referenced by av_reduce(), avcodec_string(), config_output(), decode_main_header(), eval_expr(), ff_framesync_configure(), ff_h263_decode_picture_header(), ff_mpv_encode_init(), ff_parse_specific_params(), ff_put_wav_header(), ff_rfps_add_frame(), find_frame_rate_index(), main(), rtp_send_samples(), and xvid_correct_framerate().
int64_t av_rescale | ( | int64_t | a, |
int64_t | b, | ||
int64_t | c | ||
) | const |
Rescale a 64-bit integer with rounding to nearest.
The operation is mathematically equivalent to a * b / c
, but writing that directly can overflow.
This function is equivalent to av_rescale_rnd() with AV_ROUND_NEAR_INF.
Definition at line 129 of file mathematics.c.
Referenced by asf_build_simple_index(), asf_read_simple_index(), audio_read_packet(), av_dict_set_fxp(), av_dump_format(), av_q2intfloat(), avi_read_header(), calculate_bitrate(), check_stream_max_drift(), compute_display_area(), compute_pkt_fields(), compute_texture_rect(), config_input(), config_output(), config_props(), dash_read_packet(), dc1394_read_common(), dca_parse(), estimate_timings_from_bit_rate(), ff_decklink_read_header(), ff_gen_search(), ff_interleave_add_packet(), ff_pcm_read_seek(), ff_rtp_check_and_send_back_rr(), ff_scale_eval_dimensions(), ff_update_cur_dts(), filter(), filter_frame(), finalize_packet(), flv_write_packet(), generate_intervals(), get_delay(), get_edit_list_entry(), get_input_packet(), get_lin_h(), get_lin_h2(), get_pcr(), get_vcd_padding_size(), interpolate(), matroska_parse_tracks(), mkv_write_header(), mov_build_index(), mov_find_next_sample(), mov_flush_fragment(), mov_read_mvhd(), mov_read_sidx(), mov_write_moov_tag(), mov_write_tapt_tag(), mov_write_tkhd_tag(), mov_write_tmcd_tag(), mp3_seek(), mp3_update_xing(), mpeg_mux_write_packet(), mpegts_init(), mpegts_write_packet_internal(), mpegts_write_pes(), mxf_read_seek(), nsv_parse_NSVs_header(), opengl_compute_display_area(), opus_header(), output_packet(), postProcess_TMPL(), process_work_frame(), push_frame(), qsvscale_config_props(), r3d_read_reda(), read_header(), read_packet(), read_xing_toc(), request_frame(), rm_read_header(), sbg_read_header(), seek_frame_internal(), transcode_subtitles(), ts_to_samples(), update_wrap_reference(), vc2_encode_frame(), vivo_read_header(), vqf_read_seek(), and xv_write_header().
int64_t av_rescale_rnd | ( | int64_t | a, |
int64_t | b, | ||
int64_t | c, | ||
enum AVRounding | rnd | ||
) | const |
Rescale a 64-bit integer with specified rounding.
The operation is mathematically equivalent to a * b / c
, but writing that directly can overflow, and does not support different rounding methods.
Definition at line 58 of file mathematics.c.
Referenced by aom_init(), av_compare_ts(), av_image_check_sar(), av_nearer_q(), av_rescale(), av_rescale_q_rnd(), av_rescale_rnd(), avformat_seek_file(), avresample_get_out_samples(), compute_pkt_fields(), dash_read_seek(), dv_write_pack(), estimate_timings_from_pts(), ff_nut_reset_ts(), ff_pcm_read_seek(), get_out_samples(), gxf_compare_field_nb(), gxf_write_media_preamble(), handle_file(), hls_read_packet(), hls_read_seek(), main(), mov_write_edts_tag(), mov_write_mvhd_tag(), mov_write_tkhd_tag(), nut_write_packet(), rtmp_read_seek(), vpx_init(), vqf_read_seek(), write_audio_frame(), and write_time().
int64_t av_rescale_q | ( | int64_t | a, |
AVRational | bq, | ||
AVRational | cq | ||
) | const |
Rescale a 64-bit integer by 2 rational numbers.
The operation is mathematically equivalent to a * bq / cq
.
This function is equivalent to av_rescale_q_rnd() with AV_ROUND_NEAR_INF.
Definition at line 142 of file mathematics.c.
Referenced by activate(), alloc_out_frame(), asf_write_markers(), av_add_stable(), av_packet_rescale_ts(), av_rescale_delta(), avcodec_decode_subtitle2(), avf_read_packet(), avformat_find_stream_info(), avformat_seek_file(), avi_read_packet(), avi_read_seek(), avi_write_header(), avisynth_read_packet_audio(), avisynth_read_seek(), buffer_offset(), caca_write_header(), check_stream_max_drift(), choose_output(), close_output_stream(), compand_delay(), compand_drain(), compare_ts_with_wrapdetect(), compute_chapters_end(), concat_read_packet(), config_input(), convert_sub_to_old_ass_form(), copy_chapters(), cuvid_output_frame(), dash_flush(), dash_write_packet(), dash_write_trailer(), decode(), decode_fctl_chunk(), decode_frame(), decode_simple_internal(), decode_syncpoint(), decode_video(), decoder_decode_frame(), display_frame(), do_streamcopy(), do_subtitle_out(), dv_extract_video_info(), dv_read_header(), ff_af_queue_add(), ff_configure_buffers_for_index(), ff_dv_offset_reset(), ff_framequeue_skip_samples(), ff_framesync_dualinput_get(), ff_interleave_packet_per_dts(), ff_interleaved_peek(), ff_mediacodec_dec_send(), ff_qsv_encode(), ff_qsvvpp_filter_frame(), ff_read_packet(), ff_samples_to_time_base(), ff_update_link_current_pts(), ff_write_chained(), fifo_thread_attempt_recovery(), fill_all_stream_timings(), fill_timing_for_id3_timestamped_stream(), filter_callback(), filter_frame(), find_and_decode_index(), fir_frame(), flush(), framesync_inject_frame(), get_pkt_pts(), get_subtitle_pkt(), guess_status_pts(), headphone_frame(), hls_read_packet(), init(), init_convert_timestamp(), init_output_stream(), init_output_stream_encode(), interleave_compare_dts(), interleave_new_audio_packet(), kmsgrab_read_header(), main(), matroska_parse_frame(), matroska_parse_tracks(), mediacodec_wrap_hw_buffer(), mediacodec_wrap_sw_buffer(), mkv_write_block(), mkv_write_chapters(), mkv_write_packet(), mkv_write_track(), mov_create_chapter_track(), mov_preroll_write_stbl_atoms(), mov_read_dops(), mov_read_seek(), mov_read_sidx(), mov_write_chpl_tag(), mov_write_single_packet(), movie_common_init(), mp3_parse_info_tag(), mp3_parse_vbr_tags(), mpeg4_decode_header(), mpegts_write_packet_internal(), mxf_parse_physical_source_package(), mxf_parse_structural_metadata(), mxf_read_seek(), ndi_set_audio_packet(), ndi_set_video_packet(), ndi_write_audio_packet(), ndi_write_video_packet(), ni_prepare_read(), nut_write_packet(), ogg_buffer_data(), ogg_compare_granule(), ogg_write_packet_internal(), omx_encode_frame(), parse_forced_key_frames(), print_report(), process_frame(), process_input(), process_input_packet(), process_work_frame(), pulse_write_packet(), push_frame(), push_samples(), r3d_read_rdvo(), r3d_seek(), rawvideo_read_header(), read_header(), read_interval_packets(), reap_filters(), request_frame(), rescale_interval(), rl2_read_seek(), rtcp_send_sr(), rtp_mpegts_write_packet(), rtp_parse_one_packet(), rtsp_read_play(), rtsp_read_seek(), save_subtitle_set(), sbg_read_seek2(), seek_chapter(), seek_subtitle(), seek_to_start(), seg_write_packet(), select_frame(), send_silence(), source_request_frame(), sub2video_heartbeat(), sub2video_update(), submit_frame(), teletext_decode_frame(), ts_str(), update(), update_initial_timestamps(), update_stream_timings(), v210_read_header(), v4l2_get_pts(), v4l2_set_pts(), wait_frame(), webm_chunk_write_packet(), write_audio_frame(), write_chapter(), write_manifest(), and write_packet().
int64_t av_rescale_q_rnd | ( | int64_t | a, |
AVRational | bq, | ||
AVRational | cq, | ||
enum AVRounding | rnd | ||
) | const |
Rescale a 64-bit integer by 2 rational numbers with specified rounding.
The operation is mathematically equivalent to a * bq / cq
.
Definition at line 134 of file mathematics.c.
Referenced by av_rescale_delta(), av_rescale_q(), config_props(), ff_interleave_add_packet(), lavfi_read_packet(), main(), movie_push_frame(), parse_packet(), process_input(), read_frame(), rescale_interval(), rv10_write_header(), send_filter_eof(), update_eof_pts(), update_stream_timings(), write_packet(), and write_packet_header().
int av_compare_ts | ( | int64_t | ts_a, |
AVRational | tb_a, | ||
int64_t | ts_b, | ||
AVRational | tb_b | ||
) |
Compare two timestamps each in its own time base.
ts_a
is before ts_b
ts_a
is after ts_b
int64_t
range when represented in the other's timebase. Definition at line 147 of file mathematics.c.
Referenced by check_recording_time(), dash_write_packet(), duration_max(), ff_rtp_send_aac(), ff_rtp_send_amr(), ff_rtp_send_xiph(), filter_frame(), get_audio_frame(), get_video_frame(), hds_write_packet(), hls_write_packet(), interleave_compare_dts(), ism_write_packet(), main(), mpegts_write_packet_internal(), mux_frames(), nut_write_packet(), packet_after_outpoint(), rtp_send_ilbc(), seek_chapter(), and seg_write_packet().
int64_t av_compare_mod | ( | uint64_t | a, |
uint64_t | b, | ||
uint64_t | mod | ||
) |
Compare the remainders of two integer operands divided by a common divisor.
In other words, compare the least significant log2(mod)
bits of integers a
and b
.
a,b | Operands |
mod | Divisor; must be a power of 2 |
a % mod < b % mod
a % mod > b % mod
a % mod == b % mod
Definition at line 160 of file mathematics.c.
Referenced by av_read_frame(), and compare_ts_with_wrapdetect().
int64_t av_rescale_delta | ( | AVRational | in_tb, |
int64_t | in_ts, | ||
AVRational | fs_tb, | ||
int | duration, | ||
int64_t * | last, | ||
AVRational | out_tb | ||
) |
Rescale a timestamp while preserving known durations.
This function is designed to be called per audio packet to scale the input timestamp to a different time base. Compared to a simple av_rescale_q() call, this function is robust against possible inconsistent frame durations.
The last
parameter is a state variable that must be preserved for all subsequent calls for the same stream. For the first call, *last
should be initialized to AV_NOPTS_VALUE.
[in] | in_tb | Input time base |
[in] | in_ts | Input timestamp |
[in] | fs_tb | Duration time base; typically this is finer-grained (greater) than in_tb and out_tb |
[in] | duration | Duration till the next call to this function (i.e. duration of the current packet/frame) |
[in,out] | last | Pointer to a timestamp expressed in terms of fs_tb , acting as a state variable |
[in] | out_tb | Output timebase |
out_tb
Definition at line 168 of file mathematics.c.
Referenced by decode_audio(), and do_streamcopy().
int64_t av_add_stable | ( | AVRational | ts_tb, |
int64_t | ts, | ||
AVRational | inc_tb, | ||
int64_t | inc | ||
) |
Add a value to a timestamp.
This function guarantees that when the same value is repeatly added that no accumulation of rounding errors occurs.
[in] | ts | Input timestamp |
[in] | ts_tb | Input timestamp time base |
[in] | inc | Value to be added |
[in] | inc_tb | Time base of inc |
Definition at line 191 of file mathematics.c.
Referenced by compute_pkt_fields(), and main().