FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Data Structures | Macros | Enumerations | Functions

Data Structures

struct  AVRational
 rational number numerator/denominator More...
 

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
}
 

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 a and b. 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) 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) 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 2 timestamps each in its own timebases. More...
 
int64_t av_compare_mod (uint64_t a, uint64_t b, uint64_t mod)
 Compare 2 integers modulo mod. 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...
 
static AVRational av_make_q (int num, int den)
 Create a rational. More...
 
static int av_cmp_q (AVRational a, AVRational b)
 Compare two rationals. More...
 
static double av_q2d (AVRational a)
 Convert rational to double. More...
 
int av_reduce (int *dst_num, int *dst_den, int64_t num, int64_t den, int64_t max)
 Reduce a fraction. More...
 
AVRational av_mul_q (AVRational b, AVRational c) av_const
 Multiply two rationals. More...
 
AVRational av_div_q (AVRational b, AVRational c) av_const
 Divide one rational by another. More...
 
AVRational av_add_q (AVRational b, AVRational c) av_const
 Add two rationals. More...
 
AVRational av_sub_q (AVRational b, AVRational c) av_const
 Subtract one rational from another. More...
 
static av_always_inline AVRational av_inv_q (AVRational q)
 Invert a rational. More...
 
AVRational av_d2q (double d, int max) av_const
 Convert a double precision floating point number to a rational. More...
 
int av_nearer_q (AVRational q, AVRational q1, AVRational q2)
 
int av_find_nearest_q_idx (AVRational q, const AVRational *q_list)
 Find the nearest value in q_list to q. More...
 
uint32_t av_q2intfloat (AVRational q)
 Converts a AVRational to a IEEE 32bit float. More...
 

Detailed Description

Macro Definition Documentation

#define ff_ctz   ff_ctz_c

Definition at line 106 of file intmath.h.

Referenced by get_bit_length(), refill2(), and remove_wasted_bits().

#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 config_input().

#define av_parity   __builtin_parity

Definition at line 158 of file intmath.h.

Referenced by decode_frame(), and validate_cc_data_pair().

Enumeration Type Documentation

enum AVRounding
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 to pass INT64_MIN/MAX through instead of rescaling, this avoids special cases for AV_NOPTS_VALUE.

Definition at line 70 of file mathematics.h.

Function Documentation

static av_always_inline av_const int ff_ctz_c ( int  v)
static

Trailing zero bit count.

Parameters
vinput value. If v is 0, the result is undefined.
Returns
the number of trailing 0-bits

Definition at line 115 of file intmath.h.

static av_always_inline av_const int ff_ctzll_c ( long long  v)
static

Definition at line 129 of file intmath.h.

static av_always_inline av_const unsigned ff_clz_c ( unsigned  x)
static

Definition at line 143 of file intmath.h.

int64_t av_const av_gcd ( int64_t  a,
int64_t  b 
)

Compute the greatest common divisor of a and b.

Returns
gcd of a and b up to sign; if a >= 0 and b >= 0, return value is >= 0; if a == 0 and b == 0, returns 0.

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.

A simple a*b/c isn't possible as it can overflow.

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_overlay_rect(), compute_pkt_fields(), config_input(), config_output(), config_props(), dc1394_read_common(), dca_parse(), estimate_timings_from_bit_rate(), ff_gen_search(), ff_interleave_add_packet(), ff_pcm_read_seek(), ff_rtp_check_and_send_back_rr(), ff_update_cur_dts(), filter(), filter_frame(), finalize_packet(), flv_write_packet(), generate_intervals(), get_delay(), get_input_packet(), get_lin_h(), get_lin_h2(), get_pcr(), get_vcd_padding_size(), matroska_parse_tracks(), mov_build_index(), mov_find_next_sample(), mov_flush_fragment(), mov_read_mvhd(), 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(), nppscale_config_props(), nsv_parse_NSVs_header(), oma_read_packet(), opengl_compute_display_area(), opus_header(), output_packet(), postProcess_TMPL(), push_frame(), r3d_read_reda(), read_header(), 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 
) const
int64_t av_rescale_q ( int64_t  a,
AVRational  bq,
AVRational  cq 
) const

Rescale a 64-bit integer by 2 rational numbers.

Definition at line 142 of file mathematics.c.

Referenced by alloc_out_frame(), asf_write_markers(), av_add_stable(), av_buffersink_get_samples(), av_packet_rescale_ts(), av_rescale_delta(), avcodec_decode_audio4(), avcodec_decode_subtitle2(), avf_read_packet(), avformat_find_stream_info(), avformat_seek_file(), avi_read_packet(), avi_read_seek(), 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(), dash_write_packet(), dash_write_trailer(), decode(), decode_audio(), decode_fctl_chunk(), decode_frame(), decode_syncpoint(), decode_video(), decoder_decode_frame(), display_frame(), do_streamcopy(), do_subtitle_out(), do_video_out(), dv_extract_video_info(), dv_read_header(), ff_af_queue_add(), ff_configure_buffers_for_index(), ff_dv_offset_reset(), ff_filter_frame_needs_framing(), ff_interleave_packet_per_dts(), ff_interleaved_peek(), ff_qsv_encode(), ff_read_packet(), ff_samples_to_time_base(), ff_update_link_current_pts(), ff_write_chained(), fill_all_stream_timings(), fill_timing_for_id3_timestamped_stream(), filter_frame(), find_and_decode_index(), framesync_inject_frame(), get_subtitle_pkt(), hls_read_packet(), http_prepare_data(), init(), init_convert_timestamp(), interleave_compare_dts(), interleave_new_audio_packet(), main(), matroska_parse_frame(), matroska_parse_tracks(), mkv_write_block(), mkv_write_chapters(), mkv_write_packet(), mkv_write_track(), mov_create_chapter_track(), 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(), 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(), pulse_write_packet(), push_frame(), push_samples(), qtkit_read_packet(), r3d_read_rdvo(), r3d_seek(), rawvideo_read_header(), read_from_fifo(), 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(), set_srce_frame_dest_pts(), source_request_frame(), sub2video_heartbeat(), sub2video_update(), submit_frame(), tee_write_packet(), teletext_decode_frame(), transcode_init(), ts_str(), update_initial_timestamps(), update_stream_timings(), v210_read_header(), wait_frame(), webm_chunk_write_packet(), write_audio_frame(), write_chapter(), write_frame(), write_manifest(), and write_packet().

int64_t av_rescale_q_rnd ( int64_t  a,
AVRational  bq,
AVRational  cq,
enum  AVRounding 
) const

Rescale a 64-bit integer by 2 rational numbers with specified rounding.

Returns
rescaled value a, or if AV_ROUND_PASS_MINMAX is set and a is INT64_MIN or INT64_MAX then a is passed through unchanged.

Definition at line 134 of file mathematics.c.

Referenced by av_rescale_delta(), av_rescale_q(), ff_interleave_add_packet(), filter_frame(), lavfi_read_packet(), main(), movie_push_frame(), parse_packet(), process_input(), rescale_interval(), rv10_write_header(), 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 2 timestamps each in its own timebases.

The result of the function is undefined if one of the timestamps is outside the int64_t range when represented in the others timebase.

Returns
-1 if ts_a is before ts_b, 1 if ts_a is after ts_b or 0 if they represent the same position

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(), 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 2 integers modulo mod.

That is we compare integers a and b for which only the least significant log2(mod) bits are known.

Parameters
modmust be a power of 2
Returns
a negative value if a is smaller than b a positive value if a is greater than b 0 if a equals b

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.

Parameters
in_tsInput timestamp
in_tbInput timebase
fs_tbDuration and *last timebase
durationduration till the next call
out_tbOutput timebase

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.

Parameters
tsInput timestamp
ts_tbInput timestamp timebase
incvalue to add to ts
inc_tbinc timebase

Definition at line 191 of file mathematics.c.

Referenced by compute_pkt_fields(), and main().

static AVRational av_make_q ( int  num,
int  den 
)
inlinestatic

Create a rational.

Useful for compilers that do not support compound literals.

Note
The return value is not reduced.

Definition at line 53 of file rational.h.

Referenced by alloc_out_frame(), avf_read_packet(), config_out_props(), config_output(), config_props(), convert_sub_to_old_ass_form(), encode_frame(), filter_frame(), mkv_parse_video_color(), mov_read_sidx(), plot_cqt(), and push_frame().

static int av_cmp_q ( AVRational  a,
AVRational  b 
)
inlinestatic
static double av_q2d ( AVRational  a)
inlinestatic

Convert rational to double.

Parameters
arational to convert
Returns
(double) a

Definition at line 80 of file rational.h.

Referenced by audio_thread(), av_dump_format(), av_guess_frame_rate(), av_ts_make_time_string(), avformat_find_stream_info(), avi_read_seek(), calculate_display_rect(), config_input(), config_output(), config_output_props(), config_props(), configure_video_device(), decode_frame(), decode_syncpoint(), DEFINE_BLEND8(), do_blend(), do_video_out(), do_video_stats(), draw_text(), dump_mastering_display_metadata(), dump_stream_format(), dv_write_pack(), estimate_timings(), fbdev_read_header(), fbdev_read_packet(), ff_decklink_read_header(), ff_filter_frame_framed(), ff_mpv_encode_init(), ff_mpv_encode_picture(), ff_rfps_add_frame(), ff_rfps_calculate(), filter_frame(), find_compressor(), flv_write_header(), gdigrab_read_header(), gdigrab_read_packet(), geq_filter_frame(), get_best_frame(), get_fps(), get_video_frame(), grab_read_header(), init(), init_muxer(), init_stream(), init_video(), main(), mkv_write_trailer(), mkv_write_video_color(), mov_get_h264_codec_tag(), mov_get_mpeg2_xdcam_codec_tag(), mov_write_trak_tag(), mpegvideo_parse(), mxf_compute_sample_count(), output_single_frame(), pkt_dump_internal(), process_input_packet(), push_frame(), read_header(), read_seek(), read_thread(), request_frame(), seg_write_packet(), segment_end(), select_frame(), set_side_data(), set_work_frame_pts(), stream_has_enough_packets(), svc_encode_init(), thp_read_header(), transcode_init(), update(), v4l2_read_header(), video_thread(), write_manifest(), writer_print_time(), x11grab_read_header(), and x11grab_read_packet().

int av_reduce ( int *  dst_num,
int *  dst_den,
int64_t  num,
int64_t  den,
int64_t  max 
)
AVRational av_mul_q ( AVRational  b,
AVRational  c 
) const
AVRational av_div_q ( AVRational  b,
AVRational  c 
) const

Divide one rational by another.

Parameters
bfirst rational
csecond rational
Returns
b/c

Definition at line 88 of file rational.c.

Referenced by av_dv_codec_profile2(), av_guess_frame_rate(), avi_read_header(), build_frame_code(), config_output(), config_output_props(), config_props(), config_props_output(), cuvid_handle_video_sequence(), and mpeg_decode_postinit().

AVRational av_add_q ( AVRational  b,
AVRational  c 
) const

Add two rationals.

Parameters
bfirst rational
csecond rational
Returns
b+c

Definition at line 93 of file rational.c.

Referenced by av_sub_q(), init_output_stream(), and main().

AVRational av_sub_q ( AVRational  b,
AVRational  c 
) const

Subtract one rational from another.

Parameters
bfirst rational
csecond rational
Returns
b-c

Definition at line 101 of file rational.c.

Referenced by ff_mxf_get_samples_per_frame(), and main().

static av_always_inline AVRational av_inv_q ( AVRational  q)
static
AVRational av_d2q ( double  d,
int  max 
) const

Convert a double precision floating point number to a rational.

inf is expressed as {1,0} or {-1,0} depending on the sign.

Parameters
ddouble to convert
maxthe maximum allowed numerator and denominator
Returns
(AVRational) d

Definition at line 106 of file rational.c.

Referenced by av_opt_get_q(), av_opt_get_video_rate(), av_opt_is_set_to_default(), av_opt_set_defaults2(), av_parse_ratio(), config_output_props(), decode_frame(), decode_header(), fourxm_read_header(), get_aspect_ratio(), init(), microdvd_read_header(), mov_read_tkhd(), mov_read_trak(), mpeg_decode_postinit(), nuv_header(), opt_list(), read_header(), thp_read_header(), var_read_float(), and write_number().

int av_nearer_q ( AVRational  q,
AVRational  q1,
AVRational  q2 
)
Returns
1 if q1 is nearer to q than q2, -1 if q2 is nearer than q1, 0 if they have the same distance.

Definition at line 127 of file rational.c.

Referenced by av_find_nearest_q_idx(), and find_frame_rate_index().

int av_find_nearest_q_idx ( AVRational  q,
const AVRational q_list 
)

Find the nearest value in q_list to q.

Parameters
q_listan array of rationals terminated by {0, 0}
Returns
the index of the nearest value found in the array

Definition at line 142 of file rational.c.

Referenced by ff_mxf_get_samples_per_frame(), and transcode_init().

uint32_t av_q2intfloat ( AVRational  q)

Converts a AVRational to a IEEE 32bit float.

The float is returned in a uint32_t and its value is platform indepenant.

Definition at line 152 of file rational.c.

Referenced by ircam_write_header(), and main().