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

Miscellaneous utility functions related to both muxing and demuxing (or neither). More...

Modules

 RIFF FourCCs
 Get the tables mapping RIFF FourCCs to libavcodec AVCodecIDs.
 

Macros

#define AV_FRAME_FILENAME_FLAGS_MULTIPLE   1
 Allow multiple d. More...
 

Enumerations

enum  AVTimebaseSource { AVFMT_TBCF_AUTO = -1, AVFMT_TBCF_DECODER, AVFMT_TBCF_DEMUXER }
 

Functions

void av_hex_dump (FILE *f, const uint8_t *buf, int size)
 Send a nice hexadecimal dump of a buffer to the specified file stream. More...
 
void av_hex_dump_log (void *avcl, int level, const uint8_t *buf, int size)
 Send a nice hexadecimal dump of a buffer to the log. More...
 
void av_pkt_dump2 (FILE *f, const AVPacket *pkt, int dump_payload, const AVStream *st)
 Send a nice dump of a packet to the specified file stream. More...
 
void av_pkt_dump_log2 (void *avcl, int level, const AVPacket *pkt, int dump_payload, const AVStream *st)
 Send a nice dump of a packet to the log. More...
 
enum AVCodecID av_codec_get_id (const struct AVCodecTag *const *tags, unsigned int tag)
 Get the AVCodecID for the given codec tag tag. More...
 
unsigned int av_codec_get_tag (const struct AVCodecTag *const *tags, enum AVCodecID id)
 Get the codec tag for the given codec id id. More...
 
int av_codec_get_tag2 (const struct AVCodecTag *const *tags, enum AVCodecID id, unsigned int *tag)
 Get the codec tag for the given codec id. More...
 
int av_find_default_stream_index (AVFormatContext *s)
 
int av_index_search_timestamp (AVStream *st, int64_t timestamp, int flags)
 Get the index for a specific timestamp. More...
 
int av_add_index_entry (AVStream *st, int64_t pos, int64_t timestamp, int size, int distance, int flags)
 Add an index entry into a sorted list. More...
 
void av_url_split (char *proto, int proto_size, char *authorization, int authorization_size, char *hostname, int hostname_size, int *port_ptr, char *path, int path_size, const char *url)
 Split a URL string into components. More...
 
void av_dump_format (AVFormatContext *ic, int index, const char *url, int is_output)
 Print detailed information about the input or output format, such as duration, bitrate, streams, container, programs, metadata, side data, codec and time base. More...
 
int av_get_frame_filename2 (char *buf, int buf_size, const char *path, int number, int flags)
 Return in 'buf' the path with 'd' replaced by a number. More...
 
int av_get_frame_filename (char *buf, int buf_size, const char *path, int number)
 
int av_filename_number_test (const char *filename)
 Check whether filename actually is a numbered sequence generator. More...
 
int av_sdp_create (AVFormatContext *ac[], int n_files, char *buf, int size)
 Generate an SDP for an RTP session. More...
 
int av_match_ext (const char *filename, const char *extensions)
 Return a positive value if the given filename has one of the given extensions, 0 otherwise. More...
 
int avformat_query_codec (const AVOutputFormat *ofmt, enum AVCodecID codec_id, int std_compliance)
 Test if the given container can store a codec. More...
 
AVRational av_guess_sample_aspect_ratio (AVFormatContext *format, AVStream *stream, AVFrame *frame)
 Guess the sample aspect ratio of a frame, based on both the stream and the frame aspect ratio. More...
 
AVRational av_guess_frame_rate (AVFormatContext *ctx, AVStream *stream, AVFrame *frame)
 Guess the frame rate, based on both the container and codec information. More...
 
int avformat_match_stream_specifier (AVFormatContext *s, AVStream *st, const char *spec)
 Check if the stream st contained in s is matched by the stream specifier spec. More...
 
int avformat_queue_attached_pictures (AVFormatContext *s)
 
int avformat_transfer_internal_stream_timing_info (const AVOutputFormat *ofmt, AVStream *ost, const AVStream *ist, enum AVTimebaseSource copy_tb)
 Transfer internal timing information from one stream to another. More...
 
AVRational av_stream_get_codec_timebase (const AVStream *st)
 Get the internal codec timebase from a stream. More...
 

Detailed Description

Miscellaneous utility functions related to both muxing and demuxing (or neither).

Macro Definition Documentation

#define AV_FRAME_FILENAME_FLAGS_MULTIPLE   1

Allow multiple d.

Definition at line 2817 of file avformat.h.

Referenced by av_get_frame_filename2(), and write_packet().

Enumeration Type Documentation

Enumerator
AVFMT_TBCF_AUTO 
AVFMT_TBCF_DECODER 
AVFMT_TBCF_DEMUXER 

Definition at line 2984 of file avformat.h.

Function Documentation

void av_hex_dump ( FILE *  f,
const uint8_t buf,
int  size 
)

Send a nice hexadecimal dump of a buffer to the specified file stream.

Parameters
fThe file stream pointer where the dump should be sent to.
bufbuffer
sizebuffer size
See Also
av_hex_dump_log, av_pkt_dump2, av_pkt_dump_log2

Definition at line 74 of file dump.c.

void av_hex_dump_log ( void avcl,
int  level,
const uint8_t buf,
int  size 
)

Send a nice hexadecimal dump of a buffer to the log.

Parameters
avclA pointer to an arbitrary struct of which the first field is a pointer to an AVClass struct.
levelThe importance level of the message, lower values signifying higher importance.
bufbuffer
sizebuffer size
See Also
av_hex_dump, av_pkt_dump2, av_pkt_dump_log2

Definition at line 79 of file dump.c.

Referenced by asf_read_header().

void av_pkt_dump2 ( FILE *  f,
const AVPacket pkt,
int  dump_payload,
const AVStream st 
)

Send a nice dump of a packet to the specified file stream.

Parameters
fThe file stream pointer where the dump should be sent to.
pktpacket to dump
dump_payloadTrue if the payload must be displayed, too.
stAVStream that the packet belongs to

Definition at line 108 of file dump.c.

void av_pkt_dump_log2 ( void avcl,
int  level,
const AVPacket pkt,
int  dump_payload,
const AVStream st 
)

Send a nice dump of a packet to the log.

Parameters
avclA pointer to an arbitrary struct of which the first field is a pointer to an AVClass struct.
levelThe importance level of the message, lower values signifying higher importance.
pktpacket to dump
dump_payloadTrue if the payload must be displayed, too.
stAVStream that the packet belongs to

Definition at line 113 of file dump.c.

Referenced by process_input().

enum AVCodecID av_codec_get_id ( const struct AVCodecTag *const *  tags,
unsigned int  tag 
)

Get the AVCodecID for the given codec tag tag.

If no codec id is found returns AV_CODEC_ID_NONE.

Parameters
tagslist of supported codec_id-codec_tag pairs, as stored in AVInputFormat.codec_tag and AVOutputFormat.codec_tag
tagcodec tag to match to a codec ID

Referenced by decode_stream_header(), dshow_add_device(), dshow_cycle_formats(), hls_mux_init(), init_output_stream_streamcopy(), seg_write_header(), and segment_mux_init().

unsigned int av_codec_get_tag ( const struct AVCodecTag *const *  tags,
enum AVCodecID  id 
)

Get the codec tag for the given codec id id.

If no codec tag is found returns 0.

Parameters
tagslist of supported codec_id-codec_tag pairs, as stored in AVInputFormat.codec_tag and AVOutputFormat.codec_tag
idcodec ID to match to a codec tag

Referenced by hls_mux_init(), init_muxer(), seg_write_header(), segment_mux_init(), and set_codec_str().

int av_codec_get_tag2 ( const struct AVCodecTag *const *  tags,
enum AVCodecID  id,
unsigned int tag 
)

Get the codec tag for the given codec id.

Parameters
tagslist of supported codec_id - codec_tag pairs, as stored in AVInputFormat.codec_tag and AVOutputFormat.codec_tag
idcodec id that should be searched for in the list
tagA pointer to the found tag
Returns
0 if id was not found in tags, > 0 if it was found

Referenced by init_output_stream_streamcopy().

int av_find_default_stream_index ( AVFormatContext s)

Definition at line 1824 of file utils.c.

Referenced by seek_frame_internal(), and update_wrap_reference().

int av_index_search_timestamp ( AVStream st,
int64_t  timestamp,
int  flags 
)

Get the index for a specific timestamp.

Parameters
ststream that the timestamp belongs to
timestamptimestamp to retrieve the index for
flagsif AVSEEK_FLAG_BACKWARD then the returned index will correspond to the timestamp which is <= the requested one, if backward is 0, then it will be >= if AVSEEK_FLAG_ANY seek to any frame, only keyframes otherwise
Returns
< 0 if no such timestamp could be found

Definition at line 2092 of file utils.c.

Referenced by ape_read_seek(), asf_read_seek(), avi_read_packet(), avi_read_seek(), ff_seek_frame_binary(), film_read_seek(), find_prev_closest_index(), flac_seek(), gxf_seek(), img_read_seek(), matroska_read_seek(), mov_seek_stream(), mp3_seek(), mpc8_read_seek(), mpc_read_seek(), mv_read_seek(), nsv_read_seek(), nut_write_packet(), read_packet(), read_seek(), rl2_read_seek(), seek_frame_generic(), tta_read_seek(), voc_read_seek(), and webm_clusters_start_with_keyframe().

int av_add_index_entry ( AVStream st,
int64_t  pos,
int64_t  timestamp,
int  size,
int  distance,
int  flags 
)
void av_url_split ( char *  proto,
int  proto_size,
char *  authorization,
int  authorization_size,
char *  hostname,
int  hostname_size,
int port_ptr,
char *  path,
int  path_size,
const char *  url 
)

Split a URL string into components.

The pointers to buffers for storing individual components may be null, in order to ignore that component. Buffers for components not found are set to empty strings. If the port is not found, it is set to a negative value.

Parameters
protothe buffer for the protocol
proto_sizethe size of the proto buffer
authorizationthe buffer for the authorization
authorization_sizethe size of the authorization buffer
hostnamethe buffer for the host name
hostname_sizethe size of the hostname buffer
port_ptra pointer to store the port number in
paththe buffer for the path
path_sizethe size of the path buffer
urlthe URL to split

Definition at line 4617 of file utils.c.

Referenced by ff_rtp_set_remote_url(), ff_tls_open_underlying(), ff_udp_set_remote_url(), find_rtp_session_with_url(), ftp_connect(), ftp_move(), gopher_open(), http_listen(), http_open_cnx_internal(), icecast_open(), libssh_connect(), libssh_move(), mms_open(), mmsh_open_internal(), parse_command_line(), prompeg_open(), resetup_tcp(), rtmp_http_open(), rtmp_open(), rtmpe_open(), rtp_open(), rtsp_cmd_describe(), rtsp_cmd_setup(), rtsp_listen(), sap_read_header(), sap_write_header(), sctp_open(), srtp_open(), tcp_open(), test_same_origin(), and udp_open().

void av_dump_format ( AVFormatContext ic,
int  index,
const char *  url,
int  is_output 
)

Print detailed information about the input or output format, such as duration, bitrate, streams, container, programs, metadata, side data, codec and time base.

Parameters
icthe context to analyze
indexindex of the stream to dump information about
urlthe URL to print, such as source or destination file
is_outputSelect whether the specified context is an input(0) or output(1)
Examples:
avio_reading.c, demuxing_decoding.c, muxing.c, remuxing.c, and transcoding.c.

Definition at line 555 of file dump.c.

Referenced by check_init_output_file(), main(), open_input_file(), open_output_file(), and read_thread().

int av_get_frame_filename2 ( char *  buf,
int  buf_size,
const char *  path,
int  number,
int  flags 
)

Return in 'buf' the path with 'd' replaced by a number.

Also handles the '%0nd' format where 'n' is the total number of digits and '%'.

Parameters
bufdestination buffer
buf_sizedestination buffer size
pathnumbered sequence string
numberframe number
flagsAV_FRAME_FILENAME_FLAGS_*
Returns
0 if OK, -1 on format error

Definition at line 4557 of file utils.c.

Referenced by av_get_frame_filename(), and write_packet().

int av_get_frame_filename ( char *  buf,
int  buf_size,
const char *  path,
int  number 
)
int av_filename_number_test ( const char *  filename)

Check whether filename actually is a numbered sequence generator.

Parameters
filenamepossible numbered sequence string
Returns
1 if a valid numbered sequence string, 0 otherwise

Definition at line 306 of file utils.c.

Referenced by av_guess_format(), avformat_open_input(), img_read_probe(), and open_output_file().

int av_sdp_create ( AVFormatContext ac[],
int  n_files,
char *  buf,
int  size 
)

Generate an SDP for an RTP session.

Note, this overwrites the id values of AVStreams in the muxer contexts for getting unique dynamic payload types.

Parameters
acarray of AVFormatContexts describing the RTP streams. If the array is composed by only one context, such context can contain multiple AVStreams (one AVStream per RTP stream). Otherwise, all the contexts in the array (an AVCodecContext per RTP stream) must contain only one AVStream.
n_filesnumber of AVCodecContexts contained in ac
bufbuffer where the SDP will be stored (must be allocated by the caller)
sizethe size of the buffer
Returns
0 if OK, AVERROR_xxx on error

Definition at line 835 of file sdp.c.

Referenced by ff_rtsp_setup_output_streams(), prepare_sdp_description(), print_sdp(), and sap_write_header().

int av_match_ext ( const char *  filename,
const char *  extensions 
)

Return a positive value if the given filename has one of the given extensions, 0 otherwise.

Parameters
filenamefile name to check against the given extensions
extensionsa comma-separated list of filename extensions

Definition at line 85 of file format.c.

Referenced by av_guess_format(), av_probe_input_format3(), http_parse_request(), img_read_probe(), modplug_probe(), mov_find_codec_tag(), mpegts_init(), nsv_probe(), open_url(), pgm_probe(), pgmyuv_probe(), and seg_init().

int avformat_query_codec ( const AVOutputFormat ofmt,
enum AVCodecID  codec_id,
int  std_compliance 
)

Test if the given container can store a codec.

Parameters
ofmtcontainer to check for compatibility
codec_idcodec to potentially store in container
std_compliancestandards compliance level, one of FF_COMPLIANCE_*
Returns
1 if codec with ID codec_id can be stored in ofmt, 0 if it cannot. A negative number if this information is not available.

Definition at line 4830 of file utils.c.

Referenced by open_output_file().

AVRational av_guess_sample_aspect_ratio ( AVFormatContext format,
AVStream stream,
AVFrame frame 
)

Guess the sample aspect ratio of a frame, based on both the stream and the frame aspect ratio.

Since the frame aspect ratio is set by the codec but the stream aspect ratio is set by the demuxer, these two may not be equal. This function tries to return the value that you should use if you would like to display the frame.

Basic logic is to use the stream aspect ratio if it is set to something sane otherwise use the frame aspect ratio. This way a container setting, which is usually easy to modify can override the coded value in the frames.

Parameters
formatthe format context which the stream is part of
streamthe stream which the frame is part of
framethe frame with the aspect ratio to be determined
Returns
the guessed (valid) sample_aspect_ratio, 0/1 if no idea

Definition at line 4913 of file utils.c.

Referenced by get_video_frame(), read_thread(), show_frame(), and show_stream().

AVRational av_guess_frame_rate ( AVFormatContext ctx,
AVStream stream,
AVFrame frame 
)

Guess the frame rate, based on both the container and codec information.

Parameters
ctxthe format context which the stream is part of
streamthe stream which the frame is part of
framethe frame for which the frame rate should be determined, may be NULL
Returns
the guessed (valid) frame rate, 0/1 if no idea
Examples:
transcoding.c.

Definition at line 4936 of file utils.c.

Referenced by configure_input_video_filter(), open_input_file(), and video_thread().

int avformat_match_stream_specifier ( AVFormatContext s,
AVStream st,
const char *  spec 
)

Check if the stream st contained in s is matched by the stream specifier spec.

See the "stream specifiers" chapter in the documentation for the syntax of spec.

Returns
>0 if st is matched by spec; 0 if st is not matched by spec; AVERROR code if spec is invalid
Note
A stream specifier can match several streams in the format.

Definition at line 4957 of file utils.c.

Referenced by check_stream_specifier(), find_stream(), open_slave(), probe_file(), read_thread(), and select_reference_stream().

int avformat_queue_attached_pictures ( AVFormatContext s)

Definition at line 453 of file utils.c.

Referenced by av_seek_frame(), avformat_open_input(), avformat_seek_file(), and hls_read_header().

int avformat_transfer_internal_stream_timing_info ( const AVOutputFormat ofmt,
AVStream ost,
const AVStream ist,
enum AVTimebaseSource  copy_tb 
)

Transfer internal timing information from one stream to another.

This function is useful when doing stream copy.

Parameters
ofmttarget output format for ost
ostoutput stream which needs timings copy and adjustments
istreference input stream to copy timings from
copy_tbdefine from where the stream codec timebase needs to be imported

Definition at line 5530 of file utils.c.

Referenced by init_output_stream_streamcopy().

AVRational av_stream_get_codec_timebase ( const AVStream st)

Get the internal codec timebase from a stream.

Parameters
stinput stream to extract the timebase from

Definition at line 5592 of file utils.c.

Referenced by init_output_stream_streamcopy().