Go to the documentation of this file.
52 #if FF_API_AVSTREAM_SIDE_DATA
54 for (
int i = 0;
i < st->nb_side_data;
i++)
125 av_assert0(
s->stream_groups[
s->nb_stream_groups - 1 ] == stg);
153 if (
s->iformat &&
s->iformat->priv_class &&
s->priv_data)
155 if (
s->oformat &&
s->oformat->priv_class &&
s->priv_data)
158 for (
unsigned i = 0;
i <
s->nb_streams;
i++)
160 for (
unsigned i = 0;
i <
s->nb_stream_groups;
i++)
162 s->nb_stream_groups = 0;
165 for (
unsigned i = 0;
i <
s->nb_programs;
i++) {
174 while (
s->nb_chapters--) {
190 #if FF_API_AVSTREAM_SIDE_DATA
192 uint8_t *av_stream_get_side_data(
const AVStream *st,
195 for (
int i = 0;
i < st->nb_side_data;
i++) {
196 if (st->side_data[
i].type ==
type) {
198 *
size = st->side_data[
i].size;
199 return st->side_data[
i].data;
212 for (
int i = 0;
i < st->nb_side_data;
i++) {
213 sd = &st->side_data[
i];
223 if (st->nb_side_data + 1
U >
FFMIN(INT_MAX, SIZE_MAX /
sizeof(*
tmp)))
234 sd = &st->side_data[st->nb_side_data - 1];
297 if (
src->attached_pic.data) {
379 for (
unsigned j = 0; j <
program->nb_stream_indexes; j++)
380 if (
program->stream_index[j] == idx)
410 int best_score = INT_MIN;
412 if (
s->nb_streams <= 0)
414 for (
unsigned i = 0;
i <
s->nb_streams;
i++) {
435 if (score > best_score) {
444 int wanted_stream_nb,
int related_stream,
449 int best_count = -1, best_multiframe = -1, best_disposition = -1;
450 int count, multiframe, disposition;
456 if (related_stream >= 0 && wanted_stream_nb < 0) {
469 if (wanted_stream_nb >= 0 && real_stream_index != wanted_stream_nb)
485 multiframe =
FFMIN(5, count);
486 if ((best_disposition > disposition) ||
487 (best_disposition == disposition && best_multiframe > multiframe) ||
488 (best_disposition == disposition && best_multiframe == multiframe && best_bitrate >
bitrate) ||
489 (best_disposition == disposition && best_multiframe == multiframe && best_bitrate ==
bitrate && best_count >= count))
491 best_disposition = disposition;
494 best_multiframe = multiframe;
495 ret = real_stream_index;
505 *decoder_ret = best_decoder;
519 const char *spec,
const char **indexptr,
524 if (*spec <= '9' && *spec >=
'0') {
528 }
else if (*spec ==
'v' || *spec ==
'a' || *spec ==
's' || *spec ==
'd' ||
529 *spec ==
't' || *spec ==
'V') {
542 if (*spec && *spec++ !=
':')
549 }
else if (*spec ==
'g' && *(spec + 1) ==
':') {
550 int64_t group_idx = -1, group_id = -1;
554 if (*spec ==
'#' || (*spec ==
'i' && *(spec + 1) ==
':')) {
555 spec += 1 + (*spec ==
'i');
556 group_id = strtol(spec, &endptr, 0);
557 if (spec == endptr || (*endptr && *endptr++ !=
':'))
561 group_idx = strtol(spec, &endptr, 0);
563 if (spec == endptr || (*endptr && *endptr++ !=
':'))
569 for (
unsigned i = 0;
i <
s->nb_stream_groups;
i++) {
570 if (group_id ==
s->stream_groups[
i]->id) {
576 if (group_idx < 0 || group_idx >=
s->nb_stream_groups)
578 for (
unsigned j = 0; j <
s->stream_groups[group_idx]->nb_streams; j++) {
579 if (st->
index ==
s->stream_groups[group_idx]->streams[j]->index) {
582 *
g =
s->stream_groups[group_idx];
589 }
else if (*spec ==
'p' && *(spec + 1) ==
':') {
594 prog_id = strtol(spec, &endptr, 0);
596 if (spec == endptr || (*endptr && *endptr++ !=
':'))
600 for (
unsigned i = 0;
i <
s->nb_programs;
i++) {
601 if (
s->programs[
i]->id != prog_id)
604 for (
unsigned j = 0; j <
s->programs[
i]->nb_stream_indexes; j++) {
605 if (st->
index ==
s->programs[
i]->stream_index[j]) {
617 }
else if (*spec ==
'#' ||
618 (*spec ==
'i' && *(spec + 1) ==
':')) {
621 spec += 1 + (*spec ==
'i');
622 stream_id = strtol(spec, &endptr, 0);
623 if (spec == endptr || *endptr)
625 return match && (stream_id == st->
id);
626 }
else if (*spec ==
'm' && *(spec + 1) ==
':') {
633 val = strchr(spec,
':');
641 if (!
val || !strcmp(
tag->value,
val + 1))
651 }
else if (*spec ==
'u' && *(spec + 1) ==
'\0') {
686 const char *indexptr =
NULL;
698 index = strtol(indexptr, &endptr, 0);
705 if (spec == indexptr)
710 for (
int i = 0; i < nb_streams && index >= 0;
i++) {
712 const AVStream *candidate =
s->streams[idx];
716 if (
ret > 0 &&
index-- == 0 && st == candidate)
734 av_reduce(&stream_sample_aspect_ratio.
num, &stream_sample_aspect_ratio.
den,
735 stream_sample_aspect_ratio.
num, stream_sample_aspect_ratio.
den, INT_MAX);
736 if (stream_sample_aspect_ratio.
num <= 0 || stream_sample_aspect_ratio.
den <= 0)
737 stream_sample_aspect_ratio = undef;
739 av_reduce(&frame_sample_aspect_ratio.
num, &frame_sample_aspect_ratio.
den,
740 frame_sample_aspect_ratio.
num, frame_sample_aspect_ratio.
den, INT_MAX);
741 if (frame_sample_aspect_ratio.
num <= 0 || frame_sample_aspect_ratio.
den <= 0)
742 frame_sample_aspect_ratio = undef;
744 if (stream_sample_aspect_ratio.
num)
745 return stream_sample_aspect_ratio;
747 return frame_sample_aspect_ratio;
756 if (avg_fr.
num > 0 && avg_fr.
den > 0 && fr.
num > 0 && fr.
den > 0 &&
765 if ( codec_fr.
num > 0 && codec_fr.
den > 0 &&
786 #if FF_API_TICKS_PER_FRAME
797 if (!strcmp(ofmt->
name,
"avi")) {
798 #if FF_API_R_FRAME_RATE
804 ||
copy_tb == AVFMT_TBCF_R_FRAMERATE) {
816 #if FF_API_TICKS_PER_FRAME
817 enc_tb.
num *= ticks_per_frame;
828 #if FF_API_TICKS_PER_FRAME
829 enc_tb.
num *= ticks_per_frame;
835 && dec_ctx_tb.
num < dec_ctx_tb.
den
836 && dec_ctx_tb.
num > 0
837 && 121LL*dec_ctx_tb.
num > dec_ctx_tb.
den) {
843 enc_tb.
num, enc_tb.
den, INT_MAX);
854 unsigned int pts_num,
unsigned int pts_den)
859 if (new_tb.
num != pts_num)
861 "st:%d removing common factor %d from timebase\n",
865 "st:%d has too large timebase, reducing\n", st->
index);
867 if (new_tb.
num <= 0 || new_tb.
den <= 0) {
869 "Ignoring attempt to set invalid timebase %d/%d for st:%d\n",
885 if (
s->video_codec)
return s->video_codec;
888 if (
s->audio_codec)
return s->audio_codec;
891 if (
s->subtitle_codec)
return s->subtitle_codec;
900 #define OFF(field) offsetof(AVFormatContext, field)
901 static const unsigned offsets[] = {
902 OFF(codec_whitelist),
OFF(format_whitelist),
903 OFF(protocol_whitelist),
OFF(protocol_blacklist),
911 const char *src_str = *(
char *
const*)((
const char*)
src +
offsets[
i]);
920 *(
char **)((
char*)dst +
offsets[
i]) = dst_str;
948 ret =
s->io_close2(
s, *pb);
static void error(const char *err)
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
#define FF_ENABLE_DEPRECATION_WARNINGS
#define AV_LOG_WARNING
Something somehow does not look correct.
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C program
static AVCodecContext * dec_ctx
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
enum AVMediaType codec_type
General type of the encoded data.
struct AVStreamGroupTileGrid * tile_grid
unsigned int nb_stream_indexes
struct AVBSFContext * bsfc
bitstream filter to run on stream
This struct describes the properties of an encoded stream.
struct AVBSFContext * bsf
AVStream * avformat_new_stream(AVFormatContext *s, const struct AVCodec *c)
Add a new stream to a media file.
enum AVDiscard discard
Selects which packets can be discarded at will and do not need to be demuxed.
AVProgram * av_find_program_from_stream(AVFormatContext *ic, AVProgram *last, int s)
Find the programs which belong to a given stream.
AVRational av_div_q(AVRational b, AVRational c)
Divide one rational by another.
char * protocol_blacklist
',' separated list of disallowed protocols.
struct FFStream::@318 extract_extradata
This structure describes decoded (raw) audio or video data.
AVStream ** streams
A list of all streams in the file.
This structure stores auxiliary information for decoding, presenting, or otherwise processing the cod...
AVRational avg_frame_rate
Average framerate.
int initialized
Whether or not avformat_init_output has already been called.
void av_iamf_mix_presentation_free(AVIAMFMixPresentation **pmix_presentation)
Free an AVIAMFMixPresentation and all its contents.
uint32_t codec_tag
Additional information about the codec (corresponds to the AVI FOURCC).
int nb_channels
Number of channels in this layout.
void av_bsf_free(AVBSFContext **pctx)
Free a bitstream filter context and everything associated with it; write NULL into the supplied point...
void av_packet_free(AVPacket **pkt)
Free the packet, if the packet is reference counted, it will be unreferenced first.
AVRational transferred_mux_tb
const struct AVCodecDescriptor * codec_desc
static const chunk_decoder decoder[8]
const char * avformat_stream_group_name(enum AVStreamGroupParamsType type)
void av_iamf_audio_element_free(AVIAMFAudioElement **paudio_element)
Free an AVIAMFAudioElement and all its contents.
void av_opt_free(void *obj)
Free all allocated objects in obj.
struct AVCodecContext * avctx
The codec context used by avformat_find_stream_info, the parser, etc.
@ AVDISCARD_NONE
discard nothing
static double val(void *priv, double ch)
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf type
AVProgram * av_new_program(AVFormatContext *ac, int id)
int64_t duration
Decoding: duration of the stream, in stream time base.
int av_reduce(int *dst_num, int *dst_den, int64_t num, int64_t den, int64_t max)
Reduce a fraction.
AVPacket attached_pic
For streams with AV_DISPOSITION_ATTACHED_PIC disposition, this packet will contain the attached pictu...
char * format_whitelist
',' separated list of allowed demuxers.
#define AV_LOG_TRACE
Extremely verbose debugging, useful for libav* development.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
#define FF_ARRAY_ELEMS(a)
AVDictionaryEntry * av_dict_get(const AVDictionary *m, const char *key, const AVDictionaryEntry *prev, int flags)
Get a dictionary entry with matching key.
PacketList parse_queue
Packets split by the parser get queued here.
This struct describes the properties of a single codec described by an AVCodecID.
PacketList packet_buffer
This buffer is only needed when packets were already buffered but not decoded, for example to get the...
static const int offsets[]
void * av_realloc_array(void *ptr, size_t nmemb, size_t size)
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample format(the sample packing is implied by the sample format) and sample rate. The lists are not just lists
AVRational sample_aspect_ratio
Video only.
unsigned char * buf
Buffer must have AVPROBE_PADDING_SIZE of extra allocated bytes filled with zero.
static double av_q2d(AVRational a)
Convert an AVRational to a double.
#define av_assert0(cond)
assert() equivalent, that is always enabled.
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
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.
int codec_info_nb_frames
Number of frames that have been demuxed during avformat_find_stream_info()
static const FFOutputFormat * ffofmt(const AVOutputFormat *fmt)
@ AVMEDIA_TYPE_DATA
Opaque data information usually continuous.
@ AVDISCARD_ALL
discard all
#define AV_CODEC_PROP_INTRA_ONLY
Codec uses only intra compression.
AVCodecParameters * codecpar
Codec parameters associated with this stream.
static __device__ float fabs(float a)
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented.
void avcodec_parameters_free(AVCodecParameters **ppar)
Free an AVCodecParameters instance and everything associated with it and write NULL to the supplied p...
void avcodec_free_context(AVCodecContext **avctx)
Free the codec context and everything associated with it and write NULL to the provided pointer.
Rational number (pair of numerator and denominator).
char * protocol_whitelist
',' separated list of allowed protocols.
enum AVPacketSideDataType type
unsigned int * stream_index
int av_packet_ref(AVPacket *dst, const AVPacket *src)
Setup a new reference to the data described by a given packet.
AVChannelLayout ch_layout
Audio only.
int sample_rate
Audio only.
int64_t nb_frames
number of frames in this stream if known or 0
AVCodecID
Identify the syntax and semantics of the bitstream.
const AVCodec * avcodec_find_decoder(enum AVCodecID id)
Find a registered decoder with a matching codec ID.
unsigned int nb_streams
Number of elements in AVFormatContext.streams.
AVDictionary * id3v2_meta
ID3v2 tag useful for MP3 demuxing.
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented.
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.
AVPacket * parse_pkt
The generic code uses this as a temporary packet to parse packets or for muxing, especially flushing.
void avpriv_packet_list_free(PacketList *pkt_buf)
Wipe the list and unref all the packets in it.
AVRational pkt_timebase
Timebase in which pkt_dts/pts and AVPacket.dts/pts are expressed.
#define AV_NOPTS_VALUE
Undefined timestamp value.
#define AV_CODEC_PROP_FIELDS
Video codec supports separate coding of fields in interlaced frames.
struct AVIAMFAudioElement * iamf_audio_element
int event_flags
Flags indicating events happening on the stream, a combination of AVSTREAM_EVENT_FLAG_*.
AVRational av_stream_get_codec_timebase(const AVStream *st)
Get the internal codec timebase from a stream.
@ AVMEDIA_TYPE_UNKNOWN
Usually treated as AVMEDIA_TYPE_DATA.
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown)
int raw_packet_buffer_size
Sum of the size of packets in raw_packet_buffer, in bytes.
void av_dict_free(AVDictionary **pm)
Free all the memory allocated for an AVDictionary struct and all keys and values.
AVStream ** streams
A list of streams in the group.
struct AVIAMFMixPresentation * iamf_mix_presentation
double(* duration_error)[2][MAX_STD_TIMEBASES]
PacketList raw_packet_buffer
Raw packets from the demuxer, prior to parsing and decoding.
#define i(width, name, range_min, range_max)
char * codec_whitelist
',' separated list of allowed decoders.
@ AVMEDIA_TYPE_ATTACHMENT
Opaque data information usually sparse.
int av_find_default_stream_index(AVFormatContext *s)
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
New fields can be added to the end with minor version bumps.
static av_always_inline AVRational av_inv_q(AVRational q)
Invert a rational.
union AVStreamGroup::@298 params
Group type-specific parameters.
int disposition
Stream disposition - a combination of AV_DISPOSITION_* flags.
int id
Format-specific stream ID.
AVRational av_guess_frame_rate(AVFormatContext *format, AVStream *st, AVFrame *frame)
Guess the frame rate, based on both the container and codec information.
AVDictionary * metadata
Metadata that applies to the whole group.
AVRational sample_aspect_ratio
Sample aspect ratio for the video frame, 0/1 if unknown/unspecified.
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_RL32
int av_dynarray_add_nofree(void *tab_ptr, int *nb_ptr, void *elem)
Add an element to a dynamic array.
main external API structure.
int index
stream index in AVFormatContext
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.
#define AVERROR_STREAM_NOT_FOUND
Stream not found.
int av_match_name(const char *name, const char *names)
Match instances of a name in a comma-separated list of names.
void avformat_free_context(AVFormatContext *s)
Free an AVFormatContext and all its streams.
AVRational r_frame_rate
Real base framerate of the stream.
attribute_deprecated int ticks_per_frame
For some codecs, the time base is closer to the field rate than the frame rate.
struct FFStreamInfo * info
Stream information used internally by avformat_find_stream_info()
AVRational av_mul_q(AVRational b, AVRational c)
Multiply two rationals.
AVIndexEntry * index_entries
Only used if the format does not support seeking natively.
#define FF_DISABLE_DEPRECATION_WARNINGS
#define AVERROR_DECODER_NOT_FOUND
Decoder not found.
char * av_strdup(const char *s)
Duplicate a string.
enum AVStreamGroupParamsType type
Group type.
AVPacket * pkt
Used to hold temporary packets for the generic demuxing code.
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
int av_dict_copy(AVDictionary **dst, const AVDictionary *src, int flags)
Copy entries from one AVDictionary struct into another.
struct AVStreamGroupTileGrid::@297 * offsets
An nb_tiles sized array of offsets in pixels from the topleft edge of the canvas, indicating where ea...
#define flags(name, subs,...)
int64_t bit_rate
The average bitrate of the encoded data (in bits per second).
struct AVCodecParserContext * parser
const AVCodecDescriptor * avcodec_descriptor_get(enum AVCodecID id)
int64_t start_time
Decoding: pts of the first frame of the stream in presentation order, in stream time base.
char * av_strndup(const char *s, size_t len)
Duplicate a substring of a string.
int pts_wrap_bits
Number of bits in timestamps.
int avcodec_parameters_copy(AVCodecParameters *dst, const AVCodecParameters *src)
Copy the contents of src to dst.
void av_parser_close(AVCodecParserContext *s)