22#include "config_components.h"
133 av_assert0(
s->stream_groups[
s->nb_stream_groups - 1 ] == stg);
164 if (
s->iformat &&
s->iformat->priv_class &&
s->priv_data)
166 if (
s->oformat &&
s->oformat->priv_class &&
s->priv_data)
169 for (
unsigned i = 0;
i <
s->nb_streams;
i++)
171 for (
unsigned i = 0;
i <
s->nb_stream_groups;
i++)
173 s->nb_stream_groups = 0;
176 for (
unsigned i = 0;
i <
s->nb_programs;
i++) {
185 while (
s->nb_chapters--) {
192#if CONFIG_LIBCURL_PROTOCOL
220 dst->time_base =
src->time_base;
221 dst->start_time =
src->start_time;
222 dst->duration =
src->duration;
223 dst->nb_frames =
src->nb_frames;
224 dst->disposition =
src->disposition;
225 dst->discard =
src->discard;
226 dst->sample_aspect_ratio =
src->sample_aspect_ratio;
227 dst->avg_frame_rate =
src->avg_frame_rate;
228 dst->event_flags =
src->event_flags;
229 dst->r_frame_rate =
src->r_frame_rate;
230 dst->pts_wrap_bits =
src->pts_wrap_bits;
242 if (
src->attached_pic.data) {
353 int ret, idx = -1, match = -1;
363 for (
unsigned i = 0;
i <
src->nb_programs;
i++) {
364 if (
src->programs[
i]->id == progid) {
366 av_log(
dst,
AV_LOG_ERROR,
"multiple programs found in source with same id 0x%04x. Not copying.\n", progid);
369 src_prog =
src->programs[
i];
379 for (
unsigned i = 0;
i <
dst->nb_programs;
i++) {
380 if (
dst->programs[
i]->id == progid) {
382 av_log(
dst,
AV_LOG_ERROR,
"multiple programs found in target with same id 0x%04x. Not copying.\n", progid);
390 if (idx >= 0 && !overwrite)
396 dst_prog =
dst->programs[idx];
407 dst_prog->
id = src_prog->
id;
415 if (match == -1 &&
src->nb_streams) {
417 for (
unsigned i = 0;
i <
src->nb_streams && !match;
i++) {
418 int src_id =
src->streams[
i]->id;
423 for (
unsigned j=
i+1; j <
src->nb_streams; j++) {
424 int sib_id =
src->streams[j]->id;
425 if (src_id == sib_id) {
433 for (
unsigned i = 0;
i <
dst->nb_streams;
i++) {
434 int dst_val = match ?
i :
dst->streams[
i]->id;
439 if (dst_val == src_val) {
472 int best_score = INT_MIN;
474 if (
s->nb_streams <= 0)
476 for (
unsigned i = 0;
i <
s->nb_streams;
i++) {
497 if (score > best_score) {
506 int wanted_stream_nb,
int related_stream,
511 int best_count = -1, best_multiframe = -1, best_disposition = -1;
512 int count, multiframe, disposition;
515 unsigned *program =
NULL;
518 if (related_stream >= 0 && wanted_stream_nb < 0) {
521 program = p->stream_index;
526 int real_stream_index = program ? program[
i] :
i;
531 if (wanted_stream_nb >= 0 && real_stream_index != wanted_stream_nb)
547 multiframe =
FFMIN(5, count);
548 if ((best_disposition > disposition) ||
549 (best_disposition == disposition && best_multiframe > multiframe) ||
550 (best_disposition == disposition && best_multiframe == multiframe && best_bitrate >
bitrate) ||
551 (best_disposition == disposition && best_multiframe == multiframe && best_bitrate ==
bitrate && best_count >= count))
553 best_disposition = disposition;
556 best_multiframe = multiframe;
557 ret = real_stream_index;
567 *decoder_ret = best_decoder;
581 const char *spec,
const char **indexptr,
586 if (*spec <=
'9' && *spec >=
'0') {
590 }
else if (*spec ==
'v' || *spec ==
'a' || *spec ==
's' || *spec ==
'd' ||
591 *spec ==
't' || *spec ==
'V') {
604 if (*spec && *spec++ !=
':')
611 }
else if (*spec ==
'g' && *(spec + 1) ==
':') {
612 int64_t group_idx = -1, group_id = -1;
616 if (*spec ==
'#' || (*spec ==
'i' && *(spec + 1) ==
':')) {
617 spec += 1 + (*spec ==
'i');
618 group_id = strtol(spec, &endptr, 0);
619 if (spec == endptr || (*endptr && *endptr++ !=
':'))
623 group_idx = strtol(spec, &endptr, 0);
625 if (spec == endptr || (*endptr && *endptr++ !=
':'))
631 for (
unsigned i = 0;
i <
s->nb_stream_groups;
i++) {
632 if (group_id ==
s->stream_groups[
i]->id) {
638 if (group_idx < 0 || group_idx >=
s->nb_stream_groups)
640 for (
unsigned j = 0; j <
s->stream_groups[group_idx]->nb_streams; j++) {
641 if (st->
index ==
s->stream_groups[group_idx]->streams[j]->index) {
644 *
g =
s->stream_groups[group_idx];
651 }
else if (*spec ==
'p' && *(spec + 1) ==
':') {
656 prog_id = strtol(spec, &endptr, 0);
658 if (spec == endptr || (*endptr && *endptr++ !=
':'))
662 for (
unsigned i = 0;
i <
s->nb_programs;
i++) {
663 if (
s->programs[
i]->id != prog_id)
666 for (
unsigned j = 0; j <
s->programs[
i]->nb_stream_indexes; j++) {
667 if (st->
index ==
s->programs[
i]->stream_index[j]) {
679 }
else if (*spec ==
'#' ||
680 (*spec ==
'i' && *(spec + 1) ==
':')) {
683 spec += 1 + (*spec ==
'i');
684 stream_id = strtol(spec, &endptr, 0);
685 if (spec == endptr || *endptr)
687 return match && (stream_id == st->
id);
688 }
else if (*spec ==
'm' && *(spec + 1) ==
':') {
694 const char *
val = strchr(spec,
':');
702 if (!
val || !strcmp(
tag->value,
val + 1))
712 }
else if (*spec ==
'u' && *(spec + 1) ==
'\0') {
747 const char *indexptr =
NULL;
759 index = strtol(indexptr, &endptr, 0);
766 if (spec == indexptr)
770 nb_streams =
g ?
g->nb_streams : (p ? p->nb_stream_indexes :
s->nb_streams);
772 unsigned idx =
g ?
g->streams[
i]->index : (p ? p->stream_index[
i] :
i);
773 const AVStream *candidate =
s->streams[idx];
777 if (ret > 0 &&
index-- == 0 && st == candidate)
793 AVRational frame_sample_aspect_ratio =
frame ?
frame->sample_aspect_ratio : codec_sample_aspect_ratio;
795 av_reduce(&stream_sample_aspect_ratio.
num, &stream_sample_aspect_ratio.
den,
796 stream_sample_aspect_ratio.
num, stream_sample_aspect_ratio.
den, INT_MAX);
797 if (stream_sample_aspect_ratio.
num <= 0 || stream_sample_aspect_ratio.
den <= 0)
798 stream_sample_aspect_ratio = undef;
800 av_reduce(&frame_sample_aspect_ratio.
num, &frame_sample_aspect_ratio.
den,
801 frame_sample_aspect_ratio.
num, frame_sample_aspect_ratio.
den, INT_MAX);
802 if (frame_sample_aspect_ratio.
num <= 0 || frame_sample_aspect_ratio.
den <= 0)
803 frame_sample_aspect_ratio = undef;
805 if (stream_sample_aspect_ratio.
num)
806 return stream_sample_aspect_ratio;
808 return frame_sample_aspect_ratio;
817 if (avg_fr.
num > 0 && avg_fr.
den > 0 && fr.
num > 0 && fr.
den > 0 &&
826 if ( codec_fr.
num > 0 && codec_fr.
den > 0 &&
835 unsigned int pts_num,
unsigned int pts_den)
840 if (new_tb.
num != pts_num)
842 "st:%d removing common factor %d from timebase\n",
846 "st:%d has too large timebase, reducing\n", st->
index);
848 if (new_tb.
num <= 0 || new_tb.
den <= 0) {
850 "Ignoring attempt to set invalid timebase %d/%d for st:%d\n",
866 if (
s->video_codec)
return s->video_codec;
869 if (
s->audio_codec)
return s->audio_codec;
872 if (
s->subtitle_codec)
return s->subtitle_codec;
881#define OFF(field) offsetof(AVFormatContext, field)
882 static const unsigned offsets[] = {
883 OFF(codec_whitelist),
OFF(format_whitelist),
884 OFF(protocol_whitelist),
OFF(protocol_blacklist),
888 !
dst->format_whitelist &&
889 !
dst->protocol_whitelist &&
890 !
dst->protocol_blacklist);
892 const char *src_str = *(
char *
const*)((
const char*)
src +
offsets[
i]);
904 if (
src->recursion_limit <= 0) {
908 dst->recursion_limit =
src->recursion_limit - 1;
941 if (
s->protocol_whitelist &&
av_match_list(proto,
s->protocol_whitelist,
',') <= 0) {
942 av_log(
s,
AV_LOG_ERROR,
"Protocol '%s' not on whitelist '%s'!\n", proto,
s->protocol_whitelist);
946 if (
s->protocol_blacklist &&
av_match_list(proto,
s->protocol_blacklist,
',') > 0) {
965 ret =
s->io_close2(
s, *pb);
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
static double val(void *priv, double ch)
static const char *const format[]
simple assert() macros that are a bit more flexible than ISO C assert().
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Libavcodec external API header.
#define flags(name, subs,...)
#define i(width, name, range_min, range_max)
Public libavutil channel layout APIs header.
int avcodec_parameters_copy(AVCodecParameters *dst, const AVCodecParameters *src)
void avcodec_parameters_free(AVCodecParameters **ppar)
static __device__ float fabs(float a)
static unsigned int nb_streams
reference-counted frame API
void av_bsf_free(AVBSFContext **pctx)
Free a bitstream filter context and everything associated with it; write NULL into the supplied point...
const AVCodecDescriptor * avcodec_descriptor_get(enum AVCodecID id)
#define AV_CODEC_PROP_FIELDS
Video codec supports separate coding of fields in interlaced frames.
#define AV_CODEC_PROP_INTRA_ONLY
Codec uses only intra compression.
const AVCodec * avcodec_find_decoder(enum AVCodecID id)
Find a registered decoder with a matching codec ID.
AVCodecID
Identify the syntax and semantics of the bitstream.
void avcodec_free_context(AVCodecContext **avctx)
Free the codec context and everything associated with it and write NULL to the provided pointer.
@ AVDISCARD_ALL
discard all
@ AVDISCARD_NONE
discard nothing
void av_packet_side_data_free(AVPacketSideData **psd, int *pnb_sd)
Convenience function to free all the side data stored in an array, and the array itself.
void av_packet_free(AVPacket **pkt)
Free the packet, if the packet is reference counted, it will be unreferenced first.
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
int av_packet_ref(AVPacket *dst, const AVPacket *src)
Setup a new reference to the data described by a given packet.
void av_parser_close(AVCodecParserContext *s)
#define AVFMT_PROGCOPY_MATCH_BY_INDEX
match streams using stream index
const char * avformat_stream_group_name(enum AVStreamGroupParamsType type)
AVProgram * av_new_program(AVFormatContext *ac, int id)
AVStream * avformat_new_stream(AVFormatContext *s, const struct AVCodec *c)
Add a new stream to a media file.
int av_program_copy(AVFormatContext *dst, const AVFormatContext *src, int progid, int flags)
Copy an AVProgram from one AVFormatContext to another.
#define AVFMT_PROGCOPY_MATCH_BY_ID
match streams using stream id
#define AVFMT_PROGCOPY_OVERWRITE
overwrite pre-existing program having same ID
void avformat_free_context(AVFormatContext *s)
Free an AVFormatContext and all its streams.
AVProgram * av_find_program_from_stream(AVFormatContext *ic, AVProgram *last, int s)
Find the programs which belong to a given stream.
AVRational av_guess_frame_rate(AVFormatContext *format, AVStream *st, AVFrame *frame)
Guess the frame rate, based on both the container and codec information.
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.
int av_find_default_stream_index(AVFormatContext *s)
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.
void av_dict_free(AVDictionary **pm)
Free all the memory allocated for an AVDictionary struct and all keys and values.
AVDictionaryEntry * av_dict_get(const AVDictionary *m, const char *key, const AVDictionaryEntry *prev, int flags)
Get a dictionary entry with matching key.
int av_dict_copy(AVDictionary **dst, const AVDictionary *src, int flags)
Copy entries from one AVDictionary struct into another.
#define AVERROR_DECODER_NOT_FOUND
Decoder not found.
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
#define AVERROR_STREAM_NOT_FOUND
Stream not found.
void av_iamf_audio_element_free(AVIAMFAudioElement **paudio_element)
Free an AVIAMFAudioElement and all its contents.
void av_iamf_mix_presentation_free(AVIAMFMixPresentation **pmix_presentation)
Free an AVIAMFMixPresentation and all its contents.
#define AV_LOG_TRACE
Extremely verbose debugging, useful for libav* development.
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
#define AV_LOG_WARNING
Something somehow does not look correct.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
int av_reduce(int *dst_num, int *dst_den, int64_t num, int64_t den, int64_t max)
Reduce a fraction.
static double av_q2d(AVRational a)
Convert an AVRational to a double.
AVRational av_div_q(AVRational b, AVRational c)
Divide one rational by another.
int av_dynarray_add_nofree(void *tab_ptr, int *nb_ptr, void *elem)
Add an element to a dynamic array.
char * av_strndup(const char *s, size_t len)
Duplicate a substring of a string.
void * av_realloc_array(void *ptr, size_t nmemb, size_t size)
@ AVMEDIA_TYPE_ATTACHMENT
Opaque data information usually sparse.
@ AVMEDIA_TYPE_DATA
Opaque data information usually continuous.
@ AVMEDIA_TYPE_UNKNOWN
Usually treated as AVMEDIA_TYPE_DATA.
size_t av_strlcpy(char *dst, const char *src, size_t size)
Copy the string src to dst, but no more than size - 1 bytes, and null-terminate dst.
int av_match_list(const char *name, const char *list, char separator)
Check if a name is in a list.
#define AV_NOPTS_VALUE
Undefined timestamp value.
void av_opt_free(void *obj)
Free all allocated objects in obj.
static const int offsets[]
static const chunk_decoder decoder[8]
Immersive Audio Model and Formats API header.
Memory handling functions.
static const FFOutputFormat * ffofmt(const AVOutputFormat *fmt)
#define FF_ARRAY_ELEMS(a)
int nb_channels
Number of channels in this layout.
main external API structure.
AVRational pkt_timebase
Timebase in which pkt_dts/pts and AVPacket.dts/pts are expressed.
This struct describes the properties of a single codec described by an AVCodecID.
int props
Codec properties, a combination of AV_CODEC_PROP_* flags.
This struct describes the properties of an encoded stream.
int height
The height of the video frame in pixels.
AVChannelLayout ch_layout
The channel layout and number of channels.
int width
The width of the video frame in pixels.
int64_t bit_rate
The average bitrate of the encoded data (in bits per second).
enum AVMediaType codec_type
General type of the encoded data.
AVRational sample_aspect_ratio
The aspect ratio (width/height) which a single pixel should have when displayed.
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
int sample_rate
The number of audio samples per second.
unsigned int nb_streams
Number of elements in AVFormatContext.streams.
AVStream ** streams
A list of all streams in the file.
This structure describes decoded (raw) audio or video data.
unsigned char * buf
Buffer must have AVPROBE_PADDING_SIZE of extra allocated bytes filled with zero.
New fields can be added to the end with minor version bumps.
unsigned int nb_stream_indexes
unsigned int * stream_index
int64_t pts_wrap_reference
reference dts for wrap detection
enum AVDiscard discard
selects which program to discard and which to feed to the caller
int pts_wrap_behavior
behavior on wrap detection
Rational number (pair of numerator and denominator).
int nb_coded_side_data
Amount of entries in coded_side_data.
struct AVStreamGroupTileGrid::@036353327352337314037001273105074056331305251354 * offsets
An nb_tiles sized array of offsets in pixels from the topleft edge of the canvas, indicating where ea...
AVPacketSideData * coded_side_data
Additional data associated with the grid.
union AVStreamGroup::@166361102046003066253145020066347265153020354020 params
Group type-specific parameters.
enum AVStreamGroupParamsType type
Group type.
struct AVIAMFMixPresentation * iamf_mix_presentation
struct AVStreamGroupTileGrid * tile_grid
struct AVStreamGroupTREF * tref
AVDictionary * metadata
Metadata that applies to the whole group.
struct AVIAMFAudioElement * iamf_audio_element
AVStream ** streams
A list of streams in the group.
struct AVStreamGroupLayeredVideo * layered_video
AVCodecParameters * codecpar
Codec parameters associated with this stream.
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown)
enum AVDiscard discard
Selects which packets can be discarded at will and do not need to be demuxed.
int id
Format-specific stream ID.
int index
stream index in AVFormatContext
int pts_wrap_bits
Number of bits in timestamps.
AVPacket attached_pic
For streams with AV_DISPOSITION_ATTACHED_PIC disposition, this packet will contain the attached pictu...
AVRational avg_frame_rate
Average framerate.
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented.
AVRational r_frame_rate
Real base framerate of the stream.
int disposition
Stream disposition - a combination of AV_DISPOSITION_* flags.
PacketList packet_buffer
This buffer is only needed when packets were already buffered but not decoded, for example to get the...
AVDictionary * id3v2_meta
ID3v2 tag useful for MP3 demuxing.
struct CurlLoop * curl_loop
Shared libcurl event loop, created on demand on the first use.
AVPacket * parse_pkt
The generic code uses this as a temporary packet to parse packets or for muxing, especially flushing.
AVPacket * pkt
Used to hold temporary packets for the generic demuxing code.
double(* duration_error)[2][MAX_STD_TIMEBASES]
struct AVCodecContext * avctx
The codec context used by avformat_find_stream_info, the parser, etc.
struct AVBSFContext * bsfc
bitstream filter to run on stream
struct AVBSFContext * bsf
const struct AVCodecDescriptor * codec_desc
struct AVCodecParserContext * parser
struct FFStreamInfo * info
Stream information used internally by avformat_find_stream_info()
AVPacket * parse_pkt
The generic code uses this as a temporary packet to parse packets or for muxing, especially flushing.
struct FFStream::@143263315346311247247365102337045232073206113210 extract_extradata
AVIndexEntry * index_entries
Only used if the format does not support seeking natively.
int codec_info_nb_frames
Number of frames that have been demuxed during avformat_find_stream_info()
PacketList parse_queue
Packets split by the parser get queued here.
PacketList raw_packet_buffer
Raw packets from the demuxer, prior to parsing and decoding.
int raw_packet_buffer_size
Sum of the size of packets in raw_packet_buffer, in bytes.
int initialized
Whether or not avformat_init_output has already been called.
const char * scheme
possibly including lavf-specific options
static void error(const char *err)
int ff_url_decompose(URLComponents *uc, const char *url, const char *end)
Parse an URL to find the components.
unbuffered private I/O API