88 }
else if (
num >= den) {
96 const char *
format,
const char *filename)
118 "Unable to choose an output format for '%s'; "
119 "use a standard extension for the filename or specify "
120 "the format manually.\n", filename);
126 s->oformat = oformat;
131 if (
s->oformat->priv_class) {
132 *(
const AVClass**)
s->priv_data=
s->oformat->priv_class;
166 for (
int n = 0;
s->oformat->codec_tag[n]; n++) {
167 avctag =
s->oformat->codec_tag[n];
193 static const unsigned default_codec_offsets[] = {
206 if (
s->priv_data &&
s->oformat->priv_class && *(
const AVClass**)
s->priv_data==
s->oformat->priv_class &&
222 for (
unsigned i = 0;
i <
s->nb_streams;
i++) {
263 "(%d/%d) and encoder layer (%d/%d)\n",
279 default_codec_id = *(
const enum AVCodecID*)((
const char*)of + default_codec_offsets[par->
codec_type]);
318 "Tag %s incompatible with output codec id '%d' (%s)\n",
331 for (
unsigned i = 0;
i <
s->nb_stream_groups;
i++) {
336#if FF_API_STREAM_GROUP_ENTRIES
345 if (tile_grid->nb_coded_side_data) {
346 for (
int j = 0; j < tile_grid->nb_coded_side_data; j++) {
406 if ((ret = of->
init(
s)) < 0) {
426 for (
unsigned i = 0;
i <
s->nb_streams;
i++) {
451 if (
s->avoid_negative_ts < 0) {
466 if (
s->pb &&
s->pb->error >= 0) {
512 if (!already_initialized)
520 if (ret >= 0 &&
s->pb &&
s->pb->error < 0)
534 return streams_already_initialized;
541#define AV_PKT_FLAG_UNCODED_FRAME 0x2000
544#if FF_API_COMPUTE_PKT_FIELDS2
554 if (!fci->missing_ts_warning &&
559 "Timestamps are unset in a packet for stream %d. "
560 "This is deprecated and will stop working in the future. "
561 "Fix your code to set the timestamps properly\n", st->
index);
562 fci->missing_ts_warning = 1;
566 av_log(
s,
AV_LOG_DEBUG,
"compute_muxer_pkt_fields: pts:%s dts:%s cur_dts:%s b:%d size:%d st:%d\n",
601 "Application provided invalid, non monotonically increasing dts to muxer in stream %d: %s >= %s\n",
607 "pts (%s) < dts (%s) in stream %d\n",
647 pkt->duration,
pkt->stream_index);
696 pktl; pktl = pktl->
next) {
697 AVRational cmp_tb =
s->streams[pktl->pkt.stream_index]->time_base;
698 int64_t cmp_ts = use_pts ? pktl->pkt.pts : pktl->pkt.dts;
702 if (
s->output_ts_offset)
712 for (
unsigned i = 0;
i <
s->nb_streams;
i++) {
733 "pts %s in stream %d.\n"
734 "Try -avoid_negative_ts 1 as a possible workaround.\n",
742 "Packets poorly interleaved, failed to avoid negative "
743 "timestamp %s in stream %d.\n"
744 "Try -max_interleave_delta 0 as a possible workaround.\n",
769 if (
s->output_ts_offset) {
787 if (
s->pb && ret >= 0) {
789 if (
s->pb->error < 0)
801 if (
pkt->stream_index < 0 ||
pkt->stream_index >=
s->nb_streams) {
818#if !FF_API_COMPUTE_PKT_FIELDS2
834 "Timestamps are unset in a packet for stream %d\n", st->
index);
844 "Application provided invalid, non monotonically increasing "
845 "dts to muxer in stream %d: %" PRId64
" >= %" PRId64
"\n",
850 if (
pkt->pts <
pkt->dts) {
861 if (!
pkt->data && !
pkt->side_data_elems) {
871#define CHUNK_START 0x1000
881 int chunked =
s->max_chunk_size ||
s->max_chunk_duration;
883 this_pktl =
av_malloc(
sizeof(*this_pktl));
926 && ((chunked && !((*next_point)->pkt.flags&
CHUNK_START))
928 next_point = &(*next_point)->
next;
940 this_pktl->
next = *next_point;
954 if (
s->audio_preload) {
957 if (preload != preload2) {
959 preload *=
s->audio_preload;
960 preload2 *=
s->audio_preload;
968 comp = (ts2 > ts) - (ts2 < ts);
978 int flush,
int has_packet)
982 int stream_count = 0;
983 int noninterleaved_count = 0;
991 for (
unsigned i = 0;
i <
s->nb_streams;
i++) {
1001 ++noninterleaved_count;
1008 if (
s->max_interleave_delta > 0 &&
1015 int64_t delta_dts = INT64_MIN;
1020 for (
unsigned i = 0;
i <
s->nb_streams;
i++) {
1032 delta_dts =
FFMAX(delta_dts, last_dts - top_dts);
1035 if (delta_dts >
s->max_interleave_delta) {
1037 "Delay between the first packet and last packet in the "
1038 "muxing queue is %"PRId64
" > %"PRId64
": forcing output\n",
1039 delta_dts,
s->max_interleave_delta);
1044 if (stream_count &&
flush) {
1060 int flush,
int has_packet)
1069 if (stream_index < 0 || stream_index >=
s->nb_streams)
1072 st =
s->streams[stream_index];
1075 if (
s->output_ts_offset)
1114 int flush,
int has_packet)
1142#if FF_API_COMPUTE_PKT_FIELDS2
1164 "Failed to send packet to filter %s for stream %d\n",
1182 if (ret >= 0 && !interleaved)
1196 st =
s->streams[
pkt->stream_index];
1224 if (ret >= 0 &&
s->pb &&
s->pb->error < 0)
1282 for (
unsigned i = 0;
i <
s->nb_streams;
i++) {
1309 if (ret >= 0 &&
s->pb &&
s->pb->error < 0)
1311 for (
unsigned i = 0;
i <
s->nb_streams;
i++) {
1315 if (
s->oformat->priv_class)
1370 "Automatically inserted bitstream filter '%s'; args='%s'\n",
1371 name, args ? args :
"");
1379 int stream_index =
pkt->stream_index;
1383 pkt->stream_index = dst_stream;
1386 src->streams[stream_index]->time_base,
1387 dst->streams[dst_stream]->time_base);
1397 pkt->stream_index = stream_index;
1398 pkt->time_base = time_base;
1441 pkt->data = (
void *)framep;
1446 pkt->stream_index = stream_index;
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_assert2(cond)
assert() equivalent, that does lie in speed critical code.
#define av_assert1(cond)
assert() equivalent, that does not lie in speed critical code.
#define av_assert0(cond)
assert() equivalent, that is always enabled.
void avio_write_marker(AVIOContext *s, int64_t time, enum AVIODataMarkerType type)
Mark the written bytestream as a specific type.
@ AVIO_DATA_MARKER_TRAILER
Trailer data, which doesn't contain actual content, but only for finalizing the output file.
@ AVIO_DATA_MARKER_HEADER
Header data; this needs to be present for the stream to be decodeable.
@ AVIO_DATA_MARKER_UNKNOWN
This is any, unlabelled data.
@ AVIO_DATA_MARKER_FLUSH_POINT
A point in the output bytestream where the underlying AVIOContext might flush the buffer depending on...
void avio_flush(AVIOContext *s)
Force flushing of buffered data.
#define i(width, name, range_min, range_max)
int avcodec_parameters_copy(AVCodecParameters *dst, const AVCodecParameters *src)
static __device__ float fabs(float a)
#define AV_EF_EXPLODE
abort decoding on minor error detection
#define FF_COMPLIANCE_NORMAL
void(* flush)(AVBSFContext *ctx)
static void comp(unsigned char *dst, ptrdiff_t dst_stride, unsigned char *src, ptrdiff_t src_stride, int add)
reference-counted frame API
static const uint8_t frame_size[4]
void av_bsf_free(AVBSFContext **pctx)
Free a bitstream filter context and everything associated with it; write NULL into the supplied point...
int av_bsf_init(AVBSFContext *ctx)
Prepare the filter for use, after all the parameters and options have been set.
int av_bsf_alloc(const AVBitStreamFilter *filter, AVBSFContext **pctx)
Allocate a context for a given bitstream filter.
int av_bsf_receive_packet(AVBSFContext *ctx, AVPacket *pkt)
Retrieve a filtered packet.
int av_bsf_send_packet(AVBSFContext *ctx, AVPacket *pkt)
Submit a packet for filtering.
const AVBitStreamFilter * av_bsf_get_by_name(const char *name)
int av_get_bits_per_sample(enum AVCodecID codec_id)
Return codec bits per sample.
const AVCodecDescriptor * avcodec_descriptor_get(enum AVCodecID id)
const char * avcodec_get_name(enum AVCodecID id)
Get the name of a codec.
AVCodecID
Identify the syntax and semantics of the bitstream.
#define AV_CODEC_PROP_REORDER
Codec supports frame reordering.
#define AV_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding.
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.
AVPacketSideData * av_packet_side_data_new(AVPacketSideData **psd, int *pnb_sd, enum AVPacketSideDataType type, size_t size, int flags)
Allocate a new packet side data.
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
int av_packet_make_refcounted(AVPacket *pkt)
Ensure the data described by a given packet is reference counted.
void av_packet_move_ref(AVPacket *dst, AVPacket *src)
Move every field in src to dst and reset src.
int av_packet_copy_props(AVPacket *dst, const AVPacket *src)
Copy only "properties" fields from src to dst.
void av_packet_rescale_ts(AVPacket *pkt, AVRational src_tb, AVRational dst_tb)
Convert valid timing fields (timestamps / durations) in a packet from one timebase to another.
AVFormatContext * avformat_alloc_context(void)
Allocate an AVFormatContext.
void avformat_free_context(AVFormatContext *s)
Free an AVFormatContext and all its streams.
int avformat_init_output(AVFormatContext *s, AVDictionary **options)
Allocate the stream private data and initialize the codec, but do not write the header.
av_warn_unused_result int avformat_write_header(AVFormatContext *s, AVDictionary **options)
Allocate the stream private data and write the stream header to an output media file.
int av_interleaved_write_frame(AVFormatContext *s, AVPacket *pkt)
Write a packet to an output media file ensuring correct interleaving.
int av_interleaved_write_uncoded_frame(AVFormatContext *s, int stream_index, AVFrame *frame)
Write an uncoded frame to an output media file.
#define AVSTREAM_INIT_IN_INIT_OUTPUT
stream parameters initialized in avformat_init_output
#define AVSTREAM_INIT_IN_WRITE_HEADER
stream parameters initialized in avformat_write_header
int av_write_uncoded_frame(AVFormatContext *s, int stream_index, AVFrame *frame)
Write an uncoded frame to an output media file.
int av_write_uncoded_frame_query(AVFormatContext *s, int stream_index)
Test whether a muxer supports uncoded frame.
int av_get_output_timestamp(struct AVFormatContext *s, int stream, int64_t *dts, int64_t *wall)
Get timing information for the data currently output.
int av_write_trailer(AVFormatContext *s)
Write the stream trailer to an output media file and free the file private data.
const AVOutputFormat * av_guess_format(const char *short_name, const char *filename, const char *mime_type)
Return the output format in the list of registered output formats which best matches the provided par...
int av_write_frame(AVFormatContext *s, AVPacket *in)
Write a packet to an output media file.
unsigned int av_codec_get_tag(const struct AVCodecTag *const *tags, enum AVCodecID id)
Get the codec tag for the given codec id id.
void av_buffer_unref(AVBufferRef **buf)
Free a given reference and automatically free the buffer if there are no more references to it.
AVBufferRef * av_buffer_ref(const AVBufferRef *buf)
Create a new reference to an AVBuffer.
AVBufferRef * av_buffer_create(uint8_t *data, size_t size, void(*free)(void *opaque, uint8_t *data), void *opaque, int flags)
Create an AVBuffer from an existing array.
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.
#define AV_DICT_IGNORE_SUFFIX
Return first entry in a dictionary whose first part corresponds to the search key,...
int av_dict_copy(AVDictionary **dst, const AVDictionary *src, int flags)
Copy entries from one AVDictionary struct into another.
int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags)
Set the given entry in *pm, overwriting an existing entry.
#define AVERROR_BSF_NOT_FOUND
Bitstream filter not found.
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
#define AVERROR_EOF
End of file.
#define av_err2str(errnum)
Convenience macro, the return value should be used only directly in function arguments but never stan...
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
#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_VERBOSE
Detailed information.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
static double av_q2d(AVRational a)
Convert an AVRational to a double.
static int av_cmp_q(AVRational a, AVRational b)
Compare two rationals.
static av_always_inline AVRational av_inv_q(AVRational q)
Invert a rational.
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.
int64_t av_rescale(int64_t a, int64_t b, int64_t c)
Rescale a 64-bit integer with rounding to nearest.
int64_t av_rescale_q_rnd(int64_t a, AVRational bq, AVRational cq, enum AVRounding rnd)
Rescale a 64-bit integer by 2 rational numbers with specified rounding.
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
@ AV_ROUND_UP
Round toward +infinity.
const char * av_get_media_type_string(enum AVMediaType media_type)
Return a string describing the media_type enum, NULL if media_type is unknown.
#define av_fourcc2str(fourcc)
@ AVMEDIA_TYPE_ATTACHMENT
Opaque data information usually sparse.
@ AVMEDIA_TYPE_DATA
Opaque data information usually continuous.
#define AV_NOPTS_VALUE
Undefined timestamp value.
#define AV_TIME_BASE
Internal time base represented as integer.
#define AV_TIME_BASE_Q
Internal time base represented as fractional value.
#define AV_OPT_SEARCH_CHILDREN
Search in possible children of the given object first.
void av_opt_free(void *obj)
Free all allocated objects in obj.
void av_opt_set_defaults(void *s)
Set the values of all AVOption fields to their default values.
int av_opt_set_dict2(void *obj, AVDictionary **options, int search_flags)
Set all the options from a given dictionary on an object.
int av_set_options_string(void *ctx, const char *opts, const char *key_val_sep, const char *pairs_sep)
Parse the key/value pairs list in opts.
int av_opt_set_dict(void *obj, AVDictionary **options)
Set all the options from a given dictionary on an object.
#define MAX_REORDER_DELAY
common internal api header.
unsigned int ff_toupper4(unsigned int x)
int av_get_audio_frame_duration2(AVCodecParameters *par, int frame_bytes)
common internal API header
#define FF_DISABLE_DEPRECATION_WARNINGS
#define FF_ENABLE_DEPRECATION_WARNINGS
#define FFSWAP(type, a, b)
#define MKTAG(a, b, c, d)
Memory handling functions.
#define FF_OFMT_FLAG_ALLOW_FLUSH
This flag indicates that the muxer stores data internally and supports flushing it.
#define FF_OFMT_FLAG_MAX_ONE_OF_EACH
If this flag is set, it indicates that for each codec type whose corresponding default codec (i....
@ AV_WRITE_UNCODED_FRAME_QUERY
Query whether the feature is possible on this stream.
#define FF_OFMT_FLAG_ONLY_DEFAULT_CODECS
If this flag is set, then the only permitted audio/video/subtitle codec ids are AVOutputFormat....
static const FFOutputFormat * ffofmt(const AVOutputFormat *fmt)
#define FF_ARRAY_ELEMS(a)
The bitstream filter state.
AVRational time_base_out
The timebase used for the timestamps of the output packets.
void * priv_data
Opaque filter-specific private data.
AVCodecParameters * par_in
Parameters of the input stream.
AVRational time_base_in
The timebase used for the timestamps of the input packets.
const struct AVBitStreamFilter * filter
The bitstream filter this context is an instance of.
const AVClass * priv_class
A class for the private data, used to declare bitstream filter private AVOptions.
int nb_channels
Number of channels in this layout.
Describe the class of an AVClass context structure.
This struct describes the properties of a single codec described by an AVCodecID.
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.
enum AVMediaType codec_type
General type of the encoded data.
int block_align
The number of bytes per coded audio frame, required by some formats.
AVRational sample_aspect_ratio
The aspect ratio (width/height) which a single pixel should have when displayed.
int video_delay
Number of delayed frames.
uint32_t codec_tag
Additional information about the codec (corresponds to the AVI FOURCC).
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
int sample_rate
The number of audio samples per second.
This structure describes decoded (raw) audio or video data.
This structure stores auxiliary information for decoding, presenting, or otherwise processing the cod...
This structure stores compressed data.
AVBufferRef * buf
A reference to the reference-counted buffer where the packet data is stored.
int flags
A combination of AV_PKT_FLAG values.
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed.
Rational number (pair of numerator and denominator).
AVStreamGroupTileGrid holds information on how to combine several independent images on a single canv...
enum AVStreamGroupParamsType type
Group type.
struct AVStreamGroupTileGrid * tile_grid
int nb_coded_side_data
Amount of entries in coded_side_data.
union AVStreamGroup::@313244315204024013007202273061153315146016101155 params
Group type-specific parameters.
AVPacketSideData * coded_side_data
Additional data associated with the group.
AVCodecParameters * codecpar
Codec parameters associated with this stream.
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown)
int64_t nb_frames
number of frames in this stream if known or 0
int index
stream index in AVFormatContext
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.
int disposition
Stream disposition - a combination of AV_DISPOSITION_* flags.
enum FFFormatContext::@117142222231113272376067204111240071266247245201 avoid_negative_ts_status
Whether the timestamp shift offset has already been determined.
PacketList packet_buffer
This buffer is only needed when packets were already buffered but not decoded, for example to get the...
AVFormatContext pub
The public context.
int avoid_negative_ts_use_pts
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.
The exact value of the fractional number is: 'val + num / den'.
int64_t lowest_ts_allowed
This is the lowest ts allowed in this track; it may be set by the muxer during init or write_header a...
int64_t mux_ts_offset
Timestamp offset added to timestamps before muxing.
struct AVBSFContext * bsfc
bitstream filter to run on stream
int64_t pts_buffer[MAX_REORDER_DELAY+1]
PacketListEntry * last_in_packet_buffer
last packet in packet_buffer for this stream when muxing.
AVStream pub
The public context.
int64_t interleaver_chunk_size
int64_t interleaver_chunk_duration
int bitstream_checked
Whether or not check_bitstream should still be run on each packet.
int reorder
Set to 1 if the codec allows reordering, so pts can be different from dts.
AVIndexEntry * index_entries
Only used if the format does not support seeking natively.
int(* interleave_packet)(struct AVFormatContext *s, AVPacket *pkt, int flush, int has_packet)
The interleavement function in use.
int nb_interleaved_streams
Number of streams relevant for interleaving.
int initialized
Whether or not avformat_init_output has already been called.
int streams_initialized
Whether or not avformat_init_output fully initialized streams.
struct PacketListEntry * next
static void error(const char *err)
timestamp utils, mostly useful for debugging/logging purposes
#define av_ts2str(ts)
Convenience macro, the return value should be used only directly in function arguments but never stan...
static float compare(const AVFrame *haystack, const AVFrame *obj, int offx, int offy)
static void interleave(uint8_t *dst, uint8_t *src, int w, int h, int dst_linesize, int src_linesize, enum FilterMode mode, int swap)