95 }
else if (num >= den) {
109 for (j=2; j<14; j+= 1+(j>2))
110 while (q.
den / q.
num < min_precision && q.
num % j == 0)
112 while (q.
den / q.
num < min_precision && q.
den < (1<<24))
149 const char *
format,
const char *filename)
162 av_log(s,
AV_LOG_ERROR,
"Requested output format '%s' is not a suitable output format\n", format);
256 #if FF_API_LAVF_BITEXACT
258 "Setting the AVFormatContext to bitexact mode, because "
259 "the AVCodecContext is in that mode. This behavior will "
260 "change in the future. To keep the current behavior, set "
261 "AVFormatContext.flags |= AVFMT_FLAG_BITEXACT.\n");
265 "The AVFormatContext is not in set to bitexact mode, only "
266 "the AVCodecContext. If this is not intended, set "
267 "AVFormatContext.flags |= AVFMT_FLAG_BITEXACT.\n");
283 #if FF_API_LAVF_CODEC_TB
287 "timebase hint to the muxer is deprecated. Set "
288 "AVStream.time_base instead.\n");
328 "(%d/%d) and encoder layer (%d/%d)\n",
355 char tagbuf[32], tagbuf2[32];
359 "Tag %s/0x%08x incompatible with output codec id '%d' (%s)\n",
460 if (ret >= 0 && s->
pb && s->
pb->
error < 0)
483 #define AV_PKT_FLAG_UNCODED_FRAME 0x2000
489 #define UNCODED_FRAME_PACKET_SIZE (INT_MIN / 3 * 2 + (int)sizeof(AVFrame))
492 #if FF_API_COMPUTE_PKT_FIELDS2
500 if (!s->
internal->missing_ts_warning &&
504 "Timestamps are unset in a packet for stream %d. "
505 "This is deprecated and will stop working in the future. "
506 "Fix your code to set the timestamps properly\n", st->
index);
507 s->
internal->missing_ts_warning = 1;
511 av_log(s,
AV_LOG_TRACE,
"compute_muxer_pkt_fields: pts:%s dts:%s cur_dts:%s b:%d size:%d st:%d\n",
559 "Application provided invalid, non monotonically increasing dts to muxer in stream %d: %s >= %s\n",
565 "pts (%s) < dts (%s) in stream %d\n",
650 "pts %s in stream %d.\n"
651 "Try -avoid_negative_ts 1 as a possible workaround.\n",
660 "Packets poorly interleaved, failed to avoid negative "
661 "timestamp %s in stream %d.\n"
662 "Try -max_interleave_delta 0 as a possible workaround.\n",
674 if (ret >= 0 && s->
pb && s->
pb->
error < 0)
692 if (s->
pb && ret >= 0) {
733 #if !FF_API_COMPUTE_PKT_FIELDS2
750 "Timestamps are unset in a packet for stream %d\n", st->
index);
760 "Application provided invalid, non monotonically increasing "
761 "dts to muxer in stream %d: %" PRId64
" >= %" PRId64
"\n",
766 if (pkt->
pts < pkt->
dts) {
790 if (ret >= 0 && s->
pb && s->
pb->
error < 0)
797 #if FF_API_COMPUTE_PKT_FIELDS2
805 if (ret >= 0 && s->
pb && s->
pb->
error < 0)
813 #define CHUNK_START 0x1000
856 int64_t syncto =
av_rescale(pkt->
dts + syncoffset, 1, max)*max - syncoffset;
869 && ((chunked && !((*next_point)->pkt.flags&
CHUNK_START))
870 || !
compare(s, &(*next_point)->pkt, pkt)))
871 next_point = &(*next_point)->
next;
883 this_pktl->
next = *next_point;
886 *next_point = this_pktl;
908 comp= (ts>ts2) - (ts<ts2);
920 int stream_count = 0;
921 int noninterleaved_count = 0;
935 ++noninterleaved_count;
948 int64_t delta_dts = INT64_MIN;
963 delta_dts =
FFMAX(delta_dts, last_dts - top_dts);
968 "Delay between the first packet and last packet in the "
969 "muxing queue is %"PRId64
" > %"PRId64
": forcing output\n",
975 if (stream_count && flush) {
1031 #if FF_API_COMPUTE_PKT_FIELDS2
1060 memset(pkt, 0,
sizeof(*pkt));
1109 if (ret >= 0 && s->
pb && s->
pb->
error < 0)
1144 int64_t *dts, int64_t *wall)
1175 pkt->
buf = local_pkt.
buf;
1195 pkt.
data = (
void *)frame;
#define AV_CODEC_PROP_REORDER
Codec supports frame reordering.
static float compare(const AVFrame *haystack, const AVFrame *obj, int offx, int offy)
int64_t interleaver_chunk_size
const char const char void * val
int audio_preload
Audio preload in microseconds.
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
int64_t av_frame_get_pkt_duration(const AVFrame *frame)
static int check_packet(AVFormatContext *s, AVPacket *pkt)
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
mpeg2/4 4:2:0, h264 default for 4:2:0
This structure describes decoded (raw) audio or video data.
int av_interleaved_write_frame(AVFormatContext *s, AVPacket *pkt)
Write a packet to an output media file ensuring correct interleaving.
int bitstream_checked
Whether or not check_bitstream should still be run on each packet.
static void flush(AVCodecContext *avctx)
int flush_packets
Flush the I/O context after each packet.
int av_write_frame(AVFormatContext *s, AVPacket *pkt)
Write a packet to an output media file.
#define AV_LOG_WARNING
Something somehow does not look correct.
int reorder
Set to 1 if the codec allows reordering, so pts can be different from dts.
int64_t pts_buffer[MAX_REORDER_DELAY+1]
int max_b_frames
maximum number of B-frames between non-B-frames Note: The output will be delayed by max_b_frames+1 re...
void av_opt_set_defaults(void *s)
Set the values of all AVOption fields to their default values.
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown)
int index
stream index in AVFormatContext
int ff_interleave_packet_per_dts(AVFormatContext *s, AVPacket *out, AVPacket *pkt, int flush)
Interleave a packet per dts in an output media file.
AVIndexEntry * index_entries
Only used if the format does not support seeking natively.
AVFormatInternal * internal
An opaque field for libavformat internal usage.
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown) That is the width of a pixel divided by the height of the pixel...
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
static int av_cmp_q(AVRational a, AVRational b)
Compare two rationals.
int av_dict_copy(AVDictionary **dst, const AVDictionary *src, int flags)
Copy entries from one AVDictionary struct into another.
int av_get_output_timestamp(struct AVFormatContext *s, int stream, int64_t *dts, int64_t *wall)
Get timing information for the data currently output.
size_t av_get_codec_tag_string(char *buf, size_t buf_size, unsigned int codec_tag)
Put a string representing the codec tag codec_tag in buf.
int av_write_uncoded_frame_query(AVFormatContext *s, int stream_index)
Test whether a muxer supports uncoded frame.
static int av_write_uncoded_frame_internal(AVFormatContext *s, int stream_index, AVFrame *frame, int interleaved)
int block_align
number of bytes per packet if constant and known or 0 Used by some WAV based audio codecs...
int strict_std_compliance
Allow non-standard and experimental extension.
uint8_t log2_chroma_w
Amount to shift the luma width right to find the chroma width.
int ff_write_chained(AVFormatContext *dst, int dst_stream, AVPacket *pkt, AVFormatContext *src, int interleave)
Write a packet to another muxer than the one the user originally intended.
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented...
int64_t output_ts_offset
Output timestamp offset, in microseconds.
#define av_assert0(cond)
assert() equivalent, that is always enabled.
#define av_assert2(cond)
assert() equivalent, that does lie in speed critical code.
timestamp utils, mostly useful for debugging/logging purposes
#define AV_LOG_TRACE
Extremely verbose debugging, useful for libav* development.
The exact value of the fractional number is: 'val + num / den'.
int64_t duration
Duration of this packet in AVStream->time_base units, 0 if unknown.
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
AVStream ** streams
A list of all streams in the file.
AVFormatContext * avformat_alloc_context(void)
Allocate an AVFormatContext.
static double av_q2d(AVRational a)
Convert rational to double.
AVDictionaryEntry * av_dict_get(const AVDictionary *m, const char *key, const AVDictionaryEntry *prev, int flags)
Get a dictionary entry with matching key.
int flags
Flags modifying the (de)muxer behaviour.
int64_t max_interleave_delta
Maximum buffering duration for interleaving.
static int interleave_packet(AVFormatContext *s, AVPacket *out, AVPacket *in, int flush)
Interleave an AVPacket correctly so it can be muxed.
const OptionDef options[]
enum AVChromaLocation chroma_sample_location
This defines the location of chroma samples.
int avformat_alloc_output_context2(AVFormatContext **avctx, AVOutputFormat *oformat, const char *format, const char *filename)
Allocate an AVFormatContext for an output format.
struct AVOutputFormat * oformat
The output container format.
int av_packet_ref(AVPacket *dst, const AVPacket *src)
Setup a new reference to the data described by a given packet.
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
AVCodecID
Identify the syntax and semantics of the bitstream.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
int has_b_frames
Size of the frame reordering buffer in the decoder.
AVDictionary * metadata
Metadata that applies to the whole file.
int av_get_bits_per_sample(enum AVCodecID codec_id)
Return codec bits per sample.
uint8_t log2_chroma_h
Amount to shift the luma height right to find the chroma height.
static int validate_codec_tag(AVFormatContext *s, AVStream *st)
#define AV_PKT_FLAG_UNCODED_FRAME
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
void av_dict_free(AVDictionary **pm)
Free all the memory allocated for an AVDictionary struct and all keys and values. ...
AVBufferRef * buf
A reference to the reference-counted buffer where the packet data is stored.
int flags
AV_CODEC_FLAG_*.
simple assert() macros that are a bit more flexible than ISO C assert().
static const uint8_t offset[127][2]
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 flags
A combination of AV_PKT_FLAG values.
const AVCodecDescriptor * avcodec_descriptor_get(enum AVCodecID id)
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.
AVCodecContext * codec
Codec context associated with this stream.
int av_packet_merge_side_data(AVPacket *pkt)
int props
Codec properties, a combination of AV_CODEC_PROP_* flags.
static int write_packet(AVFormatContext *s, AVPacket *pkt)
Make timestamps non negative, move side data from payload to internal struct, call muxer...
common internal API header
unsigned int nb_streams
Number of elements in AVFormatContext.streams.
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.
int void avio_flush(AVIOContext *s)
Force flushing of buffered data.
#define AV_CODEC_FLAG_BITEXACT
Use only bitexact stuff (except (I)DCT).
char filename[1024]
input or output filename
#define av_assert1(cond)
assert() equivalent, that does not lie in speed critical code.
int64_t av_rescale(int64_t a, int64_t b, int64_t c)
Rescale a 64-bit integer with rounding to nearest.
#define AV_TIME_BASE
Internal time base represented as integer.
int avformat_write_header(AVFormatContext *s, AVDictionary **options)
Allocate the stream private data and write the stream header to an output media file.
#define AV_OPT_SEARCH_CHILDREN
Search in possible children of the given object first.
int width
picture width / height.
ITU-R 601, SMPTE 274M 296M S314M(DV 4:1:1), mpeg2 4:2:2.
internal header for RIFF based (de)muxers do NOT include this in end user applications ...
int avoid_negative_ts
Avoid negative timestamps during muxing.
static void frac_init(FFFrac *f, int64_t val, int64_t num, int64_t den)
f = val + (num / den) + 0.5.
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 ticks_per_frame
For some codecs, the time base is closer to the field rate than the frame rate.
static int init_muxer(AVFormatContext *s, AVDictionary **options)
Opaque data information usually sparse.
int av_opt_set_dict2(void *obj, AVDictionary **options, int search_flags)
Set all the options from a given dictionary on an object.
preferred ID for MPEG-1/2 video decoding
int av_packet_split_side_data(AVPacket *pkt)
AVStreamInternal * internal
An opaque field for libavformat internal usage.
enum AVMediaType codec_type
int debug
Flags to enable debugging.
#define AV_TIME_BASE_Q
Internal time base represented as fractional value.
int av_opt_set_dict(void *obj, AVDictionary **options)
Set all the options from a given dictionary on an object.
int sample_rate
samples per second
AVIOContext * pb
I/O context.
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
main external API structure.
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
static const char * format
unsigned int codec_tag
fourcc (LSB first, so "ABCD" -> ('D'<<24) + ('C'<<16) + ('B'<<8) + 'A').
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(constint16_t *) pi >>8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(constint32_t *) pi >>24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(constfloat *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(constfloat *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(constfloat *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(constdouble *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(constdouble *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(constdouble *) pi *(1U<< 31))))#defineSET_CONV_FUNC_GROUP(ofmt, ifmt) staticvoidset_generic_function(AudioConvert *ac){}voidff_audio_convert_free(AudioConvert **ac){if(!*ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);}AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enumAVSampleFormatout_fmt, enumAVSampleFormatin_fmt, intchannels, intsample_rate, intapply_map){AudioConvert *ac;intin_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) returnNULL;ac->avr=avr;ac->out_fmt=out_fmt;ac->in_fmt=in_fmt;ac->channels=channels;ac->apply_map=apply_map;if(avr->dither_method!=AV_RESAMPLE_DITHER_NONE &&av_get_packed_sample_fmt(out_fmt)==AV_SAMPLE_FMT_S16 &&av_get_bytes_per_sample(in_fmt)>2){ac->dc=ff_dither_alloc(avr, out_fmt, in_fmt, channels, sample_rate, apply_map);if(!ac->dc){av_free(ac);returnNULL;}returnac;}in_planar=ff_sample_fmt_is_planar(in_fmt, channels);out_planar=ff_sample_fmt_is_planar(out_fmt, channels);if(in_planar==out_planar){ac->func_type=CONV_FUNC_TYPE_FLAT;ac->planes=in_planar?ac->channels:1;}elseif(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;elseac->func_type=CONV_FUNC_TYPE_DEINTERLEAVE;set_generic_function(ac);if(ARCH_AARCH64) ff_audio_convert_init_aarch64(ac);if(ARCH_ARM) ff_audio_convert_init_arm(ac);if(ARCH_X86) ff_audio_convert_init_x86(ac);returnac;}intff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in){intuse_generic=1;intlen=in->nb_samples;intp;if(ac->dc){av_log(ac->avr, AV_LOG_TRACE,"%dsamples-audio_convert:%sto%s(dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));returnff_convert_dither(ac-> in
int av_apply_bitstream_filters(AVCodecContext *codec, AVPacket *pkt, AVBitStreamFilterContext *bsfc)
Apply a list of bitstream filters to a packet.
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 UNCODED_FRAME_PACKET_SIZE
Describe the class of an AVClass context structure.
#define FF_COMPLIANCE_NORMAL
unsigned int avpriv_toupper4(unsigned int x)
rational number numerator/denominator
enum AVChromaLocation ff_choose_chroma_location(AVFormatContext *s, AVStream *st)
Chooses a timebase for muxing the specified stream.
AVRational ff_choose_timebase(AVFormatContext *s, AVStream *st, int min_precision)
Chooses a timebase for muxing the specified stream.
void avformat_free_context(AVFormatContext *s)
Free an AVFormatContext and all its streams.
AVBitStreamFilterContext * bsfc
bitstream filter to run on stream
int error
contains the error code or 0 if no error happened
int av_get_audio_frame_duration(AVCodecContext *avctx, int frame_bytes)
Return audio frame duration.
static void interleave(short *output, short **input, int channels, int samples)
This struct describes the properties of a single codec described by an AVCodecID. ...
int64_t interleaver_chunk_duration
AVPacketSideData * side_data
Additional packet data that can be provided by the container.
int ff_interleave_add_packet(AVFormatContext *s, AVPacket *pkt, int(*compare)(AVFormatContext *, AVPacket *, AVPacket *))
Add packet to AVFormatContext->packet_buffer list, determining its interleaved position using compare...
void av_opt_free(void *obj)
Free all allocated objects in obj.
#define FF_DISABLE_DEPRECATION_WARNINGS
int av_interleaved_write_uncoded_frame(AVFormatContext *s, int stream_index, AVFrame *frame)
Write a uncoded frame to an output media file.
common internal api header.
struct AVPacketList * next
int max_chunk_size
Max chunk size in bytes Note, not all formats support this and unpredictable things may happen if it ...
static void frac_add(FFFrac *f, int64_t incr)
Fractional addition to f: f = f + (incr / f->den).
static int init_pts(AVFormatContext *s)
void av_init_packet(AVPacket *pkt)
Initialize optional fields of a packet with default values.
int64_t nb_frames
number of frames in this stream if known or 0
int av_write_uncoded_frame(AVFormatContext *s, int stream_index, AVFrame *frame)
Write a uncoded frame to an output media file.
int64_t mux_ts_offset
Timestamp offset added to timestamps before muxing NOT PART OF PUBLIC API.
static int interleave_compare_dts(AVFormatContext *s, AVPacket *next, AVPacket *pkt)
#define FF_ENABLE_DEPRECATION_WARNINGS
#define av_ts2str(ts)
Convenience macro, the return value should be used only directly in function arguments but never stan...
int channels
number of audio channels
int max_chunk_duration
Max chunk time in microseconds.
void * priv_data
Format private data.
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed...
int av_write_trailer(AVFormatContext *s)
Write the stream trailer to an output media file and free the file private data.
static void comp(unsigned char *dst, int dst_stride, unsigned char *src, int src_stride, int add)
enum AVFieldOrder field_order
Field order.
#define AV_DICT_IGNORE_SUFFIX
Return first entry in a dictionary whose first part corresponds to the search key, ignoring the suffix of the found key string.
AVChromaLocation
Location of chroma samples.
unbuffered private I/O API
mpeg1 4:2:0, jpeg 4:2:0, h263 4:2:0
#define FFSWAP(type, a, b)
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented...
#define MKTAG(a, b, c, d)
unsigned int av_codec_get_tag(const struct AVCodecTag *const *tags, enum AVCodecID id)
Get the codec tag for the given codec id id.
This structure stores compressed data.
void * av_mallocz(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
static int prepare_input_packet(AVFormatContext *s, AVPacket *pkt)
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
struct AVPacketList * last_in_packet_buffer
last packet in packet_buffer for this stream when muxing.
#define AV_NOPTS_VALUE
Undefined timestamp value.