FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Macros | Functions
mux.c File Reference

muxing functions for use within libavformat More...

#include "avformat.h"
#include "avio_internal.h"
#include "internal.h"
#include "libavcodec/internal.h"
#include "libavcodec/bytestream.h"
#include "libavutil/opt.h"
#include "libavutil/dict.h"
#include "libavutil/pixdesc.h"
#include "libavutil/timestamp.h"
#include "metadata.h"
#include "id3v2.h"
#include "libavutil/avassert.h"
#include "libavutil/avstring.h"
#include "libavutil/internal.h"
#include "libavutil/mathematics.h"
#include "libavutil/parseutils.h"
#include "libavutil/time.h"
#include "riff.h"
#include "audiointerleave.h"
#include "url.h"
#include <stdarg.h>

Go to the source code of this file.

Macros

#define AV_PKT_FLAG_UNCODED_FRAME   0x2000
 
#define UNCODED_FRAME_PACKET_SIZE   (INT_MIN / 3 * 2 + (int)sizeof(AVFrame))
 
#define CHUNK_START   0x1000
 

Functions

static void frac_init (FFFrac *f, int64_t val, int64_t num, int64_t den)
 f = val + (num / den) + 0.5. More...
 
static void frac_add (FFFrac *f, int64_t incr)
 Fractional addition to f: f = f + (incr / f->den). More...
 
AVRational ff_choose_timebase (AVFormatContext *s, AVStream *st, int min_precision)
 Chooses a timebase for muxing the specified stream. More...
 
enum AVChromaLocation ff_choose_chroma_location (AVFormatContext *s, AVStream *st)
 Chooses a timebase for muxing the specified stream. More...
 
int avformat_alloc_output_context2 (AVFormatContext **avctx, AVOutputFormat *oformat, const char *format, const char *filename)
 Allocate an AVFormatContext for an output format. More...
 
static int validate_codec_tag (AVFormatContext *s, AVStream *st)
 
static int init_muxer (AVFormatContext *s, AVDictionary **options)
 
static int init_pts (AVFormatContext *s)
 
int avformat_write_header (AVFormatContext *s, AVDictionary **options)
 Allocate the stream private data and write the stream header to an output media file. More...
 
static int write_packet (AVFormatContext *s, AVPacket *pkt)
 Make timestamps non negative, move side data from payload to internal struct, call muxer, and restore sidedata. More...
 
static int check_packet (AVFormatContext *s, AVPacket *pkt)
 
static int prepare_input_packet (AVFormatContext *s, AVPacket *pkt)
 
int av_write_frame (AVFormatContext *s, AVPacket *pkt)
 Write a packet to an output media file. More...
 
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() function argument. More...
 
static int interleave_compare_dts (AVFormatContext *s, AVPacket *next, AVPacket *pkt)
 
int ff_interleave_packet_per_dts (AVFormatContext *s, AVPacket *out, AVPacket *pkt, int flush)
 Interleave a packet per dts in an output media file. More...
 
static int interleave_packet (AVFormatContext *s, AVPacket *out, AVPacket *in, int flush)
 Interleave an AVPacket correctly so it can be muxed. More...
 
int av_interleaved_write_frame (AVFormatContext *s, AVPacket *pkt)
 Write a packet to an output media file ensuring correct interleaving. More...
 
int av_write_trailer (AVFormatContext *s)
 Write the stream trailer to an output media file and free the file private data. More...
 
int av_get_output_timestamp (struct AVFormatContext *s, int stream, int64_t *dts, int64_t *wall)
 Get timing information for the data currently output. More...
 
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. More...
 
static int av_write_uncoded_frame_internal (AVFormatContext *s, int stream_index, AVFrame *frame, int interleaved)
 
int av_write_uncoded_frame (AVFormatContext *s, int stream_index, AVFrame *frame)
 Write a uncoded frame to an output media file. More...
 
int av_interleaved_write_uncoded_frame (AVFormatContext *s, int stream_index, AVFrame *frame)
 Write a uncoded frame to an output media file. More...
 
int av_write_uncoded_frame_query (AVFormatContext *s, int stream_index)
 Test whether a muxer supports uncoded frame. More...
 

Detailed Description

muxing functions for use within libavformat

Definition in file mux.c.

Macro Definition Documentation

#define AV_PKT_FLAG_UNCODED_FRAME   0x2000

Definition at line 483 of file mux.c.

Referenced by av_write_uncoded_frame_internal(), ff_interleave_add_packet(), and write_packet().

#define UNCODED_FRAME_PACKET_SIZE   (INT_MIN / 3 * 2 + (int)sizeof(AVFrame))

Definition at line 489 of file mux.c.

Referenced by av_write_uncoded_frame_internal(), ff_interleave_add_packet(), and write_packet().

#define CHUNK_START   0x1000

Definition at line 813 of file mux.c.

Referenced by ff_interleave_add_packet().

Function Documentation

static void frac_init ( FFFrac f,
int64_t  val,
int64_t  num,
int64_t  den 
)
static

f = val + (num / den) + 0.5.

'num' is normalized so that it is such as 0 <= num < den.

Parameters
ffractional number
valinteger value
nummust be >= 0
denmust be >= 1

Definition at line 64 of file mux.c.

Referenced by init_pts().

static void frac_add ( FFFrac f,
int64_t  incr 
)
static

Fractional addition to f: f = f + (incr / f->den).

Parameters
ffractional number
incrincrement, can be positive or negative

Definition at line 82 of file mux.c.

AVRational ff_choose_timebase ( AVFormatContext s,
AVStream st,
int  min_precision 
)

Chooses a timebase for muxing the specified stream.

The chosen timebase allows sample accurate timestamps based on the framerate or sample rate for audio streams. It also is at least as precise as 1/min_precision would be.

Definition at line 102 of file mux.c.

Referenced by nut_write_header().

enum AVChromaLocation ff_choose_chroma_location ( AVFormatContext s,
AVStream st 
)

Chooses a timebase for muxing the specified stream.

Definition at line 118 of file mux.c.

Referenced by mxf_write_header().

int avformat_alloc_output_context2 ( AVFormatContext **  ctx,
AVOutputFormat oformat,
const char *  format_name,
const char *  filename 
)

Allocate an AVFormatContext for an output format.

avformat_free_context() can be used to free the context and everything allocated by the framework within it.

Parameters
*ctxis set to the created format context, or to NULL in case of failure
oformatformat to use for allocating the context, if NULL format_name and filename are used instead
format_namethe name of output format to use for allocating the context, if NULL filename is used instead
filenamethe name of the filename to use for allocating the context, may be NULL
Returns
>= 0 in case of success, a negative AVERROR code in case of failure

Definition at line 148 of file mux.c.

Referenced by avdevice_list_output_sinks(), chunk_mux_init(), hls_mux_init(), main(), open_output_file(), open_slave(), segment_mux_init(), and write_packet().

static int validate_codec_tag ( AVFormatContext s,
AVStream st 
)
static

Check that tag + id is in the table If neither is in the table -> OK If tag is in the table with another id -> FAIL If id is in the table with another tag -> FAIL unless strict < normal

Definition at line 201 of file mux.c.

Referenced by init_muxer().

static int init_muxer ( AVFormatContext s,
AVDictionary **  options 
)
static

Definition at line 235 of file mux.c.

Referenced by avformat_write_header().

static int init_pts ( AVFormatContext s)
static

Definition at line 414 of file mux.c.

Referenced by avformat_write_header().

static int write_packet ( AVFormatContext s,
AVPacket pkt 
)
static

Make timestamps non negative, move side data from payload to internal struct, call muxer, and restore sidedata.

FIXME: this function should NEVER get undefined pts/dts beside when the AVFMT_NOTIMESTAMPS is set. Those additional safety checks should be dropped once the correct checks are set in the callers.

Definition at line 609 of file mux.c.

Referenced by av_interleaved_write_frame(), av_write_frame(), and av_write_trailer().

static int check_packet ( AVFormatContext s,
AVPacket pkt 
)
static

Definition at line 706 of file mux.c.

Referenced by prepare_input_packet().

static int prepare_input_packet ( AVFormatContext s,
AVPacket pkt 
)
static

Definition at line 725 of file mux.c.

Referenced by av_interleaved_write_frame(), and av_write_frame().

int ff_interleave_add_packet ( AVFormatContext s,
AVPacket pkt,
int(*)(AVFormatContext *, AVPacket *, AVPacket *)  compare 
)

Add packet to AVFormatContext->packet_buffer list, determining its interleaved position using compare() function argument.

Returns
0, or < 0 on error

Definition at line 815 of file mux.c.

Referenced by ff_audio_rechunk_interleave(), and ff_interleave_packet_per_dts().

static int interleave_compare_dts ( AVFormatContext s,
AVPacket next,
AVPacket pkt 
)
static

Definition at line 893 of file mux.c.

Referenced by ff_interleave_packet_per_dts().

int ff_interleave_packet_per_dts ( AVFormatContext s,
AVPacket out,
AVPacket pkt,
int  flush 
)

Interleave a packet per dts in an output media file.

Packets with pkt->destruct == av_destruct_packet will be freed inside this function, so they cannot be used after it. Note that calling av_packet_unref() on them is still safe.

Parameters
smedia file handle
outthe interleaved packet will be output here
pktthe input packet
flush1 if no further packets are available as input and all remaining packets should be output
Returns
1 if a packet was output, 0 if no packet could be output, < 0 if an error occurred

Definition at line 916 of file mux.c.

Referenced by gxf_interleave_packet(), and interleave_packet().

static int interleave_packet ( AVFormatContext s,
AVPacket out,
AVPacket in,
int  flush 
)
static

Interleave an AVPacket correctly so it can be muxed.

Parameters
outthe interleaved packet will be output here
inthe input packet
flush1 if no further packets are available as input and all remaining packets should be output
Returns
1 if a packet was output, 0 if no packet could be output, < 0 if an error occurred

Definition at line 1005 of file mux.c.

Referenced by av_interleaved_write_frame(), and av_write_trailer().

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.

Useful when chaining muxers, where one muxer internally writes a received packet to another muxer.

Parameters
dstthe muxer to write the packet to
dst_streamthe stream index within dst to write the packet to
pktthe packet to be written
srcthe muxer the packet originally was intended for
interleave0->use av_write_frame, 1->av_interleaved_write_frame
Returns
the value av_write_frame returned

Definition at line 1152 of file mux.c.

Referenced by dash_write_packet(), ff_mov_add_hinted_packet(), hds_write_packet(), hls_write_packet(), ism_write_packet(), rtsp_write_packet(), sap_write_packet(), and seg_write_packet().

static int av_write_uncoded_frame_internal ( AVFormatContext s,
int  stream_index,
AVFrame frame,
int  interleaved 
)
static

Definition at line 1181 of file mux.c.

Referenced by av_interleaved_write_uncoded_frame(), and av_write_uncoded_frame().