FFmpeg
Macros | Functions
mux.c File Reference
#include "avformat.h"
#include "internal.h"
#include "mux.h"
#include "version.h"
#include "libavcodec/bsf.h"
#include "libavcodec/codec_desc.h"
#include "libavcodec/internal.h"
#include "libavcodec/packet_internal.h"
#include "libavutil/mem.h"
#include "libavutil/opt.h"
#include "libavutil/dict.h"
#include "libavutil/timestamp.h"
#include "libavutil/avassert.h"
#include "libavutil/frame.h"
#include "libavutil/internal.h"
#include "libavutil/mathematics.h"

Go to the source code of this file.

Macros

#define AV_PKT_FLAG_UNCODED_FRAME   0x2000
 
#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...
 
int avformat_alloc_output_context2 (AVFormatContext **avctx, const AVOutputFormat *oformat, const char *format, const char *filename)
 Allocate an AVFormatContext for an output format. More...
 
static int validate_codec_tag (const AVFormatContext *s, const AVStream *st)
 
static int init_muxer (AVFormatContext *s, AVDictionary **options)
 
static int init_pts (AVFormatContext *s)
 
static void flush_if_needed (AVFormatContext *s)
 
static void deinit_muxer (AVFormatContext *s)
 
int avformat_init_output (AVFormatContext *s, AVDictionary **options)
 Allocate the stream private data and initialize the codec, but do not write the header. More...
 
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 FF_DISABLE_DEPRECATION_WARNINGS int compute_muxer_pkt_fields (AVFormatContext *s, AVStream *st, AVPacket *pkt)
 
static FF_ENABLE_DEPRECATION_WARNINGS void guess_pkt_duration (AVFormatContext *s, AVStream *st, AVPacket *pkt)
 
static void handle_avoid_negative_ts (FFFormatContext *si, FFStream *sti, AVPacket *pkt)
 
static int write_packet (AVFormatContext *s, AVPacket *pkt)
 Shift timestamps and call muxer; the original pts/dts are not kept. More...
 
static int check_packet (AVFormatContext *s, AVPacket *pkt)
 
static int prepare_input_packet (AVFormatContext *s, AVStream *st, AVPacket *pkt)
 
int ff_interleave_add_packet (AVFormatContext *s, AVPacket *pkt, int(*compare)(AVFormatContext *, const AVPacket *, const AVPacket *))
 Add packet to an AVFormatContext's packet_buffer list, determining its interleaved position using compare() function argument. More...
 
static int interleave_compare_dts (AVFormatContext *s, const AVPacket *next, const AVPacket *pkt)
 
int ff_interleave_packet_per_dts (AVFormatContext *s, AVPacket *pkt, int flush, int has_packet)
 Interleave an AVPacket per dts so it can be muxed. More...
 
int ff_interleave_packet_passthrough (AVFormatContext *s, AVPacket *pkt, int flush, int has_packet)
 Interleave packets directly in the order in which they arrive without any sort of buffering. More...
 
int ff_get_muxer_ts_offset (AVFormatContext *s, int stream_index, int64_t *offset)
 
const AVPacketff_interleaved_peek (AVFormatContext *s, int stream)
 Find the next packet in the interleaving queue for the given stream. More...
 
static int check_bitstream (AVFormatContext *s, FFStream *sti, AVPacket *pkt)
 
static int interleaved_write_packet (AVFormatContext *s, AVPacket *pkt, int flush, int has_packet)
 
static int write_packet_common (AVFormatContext *s, AVStream *st, AVPacket *pkt, int interleaved)
 
static int write_packets_from_bsfs (AVFormatContext *s, AVStream *st, AVPacket *pkt, int interleaved)
 
static int write_packets_common (AVFormatContext *s, AVPacket *pkt, int interleaved)
 
int av_write_frame (AVFormatContext *s, AVPacket *in)
 Write a packet to an output media file. 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_stream_add_bitstream_filter (AVStream *st, const char *name, const char *args)
 Add a bitstream filter to a stream. 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 void uncoded_frame_free (void *unused, uint8_t *data)
 
static int 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 an uncoded frame to an output media file. More...
 
int av_interleaved_write_uncoded_frame (AVFormatContext *s, int stream_index, AVFrame *frame)
 Write an 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

◆ AV_PKT_FLAG_UNCODED_FRAME

#define AV_PKT_FLAG_UNCODED_FRAME   0x2000

Definition at line 523 of file mux.c.

◆ CHUNK_START

#define CHUNK_START   0x1000

Definition at line 853 of file mux.c.

Function Documentation

◆ frac_init()

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 56 of file mux.c.

Referenced by init_pts().

◆ frac_add()

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 74 of file mux.c.

Referenced by compute_muxer_pkt_fields().

◆ avformat_alloc_output_context2()

int avformat_alloc_output_context2 ( AVFormatContext **  ctx,
const 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
ctxpointee is 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
Examples
mux.c.

Definition at line 94 of file mux.c.

Referenced by avdevice_list_output_sinks(), fifo_mux_init(), hls_mux_init(), initialize_fifo_tst_muxer_chain(), main(), mov_init_ttml_writer(), of_open(), open_output_file(), open_slave(), segment_mux_init(), webm_chunk_init(), and write_muxed_file().

◆ validate_codec_tag()

static int validate_codec_tag ( const AVFormatContext s,
const 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 152 of file mux.c.

Referenced by init_muxer().

◆ init_muxer()

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

Definition at line 186 of file mux.c.

Referenced by avformat_init_output().

◆ init_pts()

static int init_pts ( AVFormatContext s)
static

Definition at line 403 of file mux.c.

Referenced by avformat_init_output(), and avformat_write_header().

◆ flush_if_needed()

static void flush_if_needed ( AVFormatContext s)
static

Definition at line 446 of file mux.c.

Referenced by av_write_frame(), avformat_write_header(), and write_packet().

◆ deinit_muxer()

static void deinit_muxer ( AVFormatContext s)
static

Definition at line 456 of file mux.c.

Referenced by av_write_trailer(), and avformat_write_header().

◆ compute_muxer_pkt_fields()

static FF_DISABLE_DEPRECATION_WARNINGS int compute_muxer_pkt_fields ( AVFormatContext s,
AVStream st,
AVPacket pkt 
)
static

Definition at line 529 of file mux.c.

Referenced by write_packet_common().

◆ guess_pkt_duration()

static FF_ENABLE_DEPRECATION_WARNINGS void guess_pkt_duration ( AVFormatContext s,
AVStream st,
AVPacket pkt 
)
static

Definition at line 625 of file mux.c.

Referenced by write_packet_common().

◆ handle_avoid_negative_ts()

static void handle_avoid_negative_ts ( FFFormatContext si,
FFStream sti,
AVPacket pkt 
)
static

Definition at line 656 of file mux.c.

Referenced by write_packet().

◆ write_packet()

static int write_packet ( AVFormatContext s,
AVPacket pkt 
)
static

Shift timestamps and call muxer; the original pts/dts are not kept.

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 742 of file mux.c.

Referenced by interleaved_write_packet(), and write_packet_common().

◆ check_packet()

static int check_packet ( AVFormatContext s,
AVPacket pkt 
)
static

Definition at line 781 of file mux.c.

Referenced by write_packets_common().

◆ prepare_input_packet()

static int prepare_input_packet ( AVFormatContext s,
AVStream st,
AVPacket pkt 
)
static

Definition at line 797 of file mux.c.

Referenced by write_packets_common().

◆ ff_interleave_add_packet()

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

Add packet to an AVFormatContext's packet_buffer list, determining its interleaved position using compare() function argument.

Returns
0 on success, < 0 on error. pkt will always be blank on return.

Definition at line 855 of file mux.c.

Referenced by ff_interleave_packet_per_dts(), gxf_interleave_packet(), and mxf_interleave().

◆ interleave_compare_dts()

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

Definition at line 929 of file mux.c.

Referenced by ff_interleave_packet_per_dts().

◆ ff_interleave_packet_per_dts()

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

Interleave an AVPacket per dts so it can be muxed.

See the documentation of AVOutputFormat.interleave_packet for details.

Definition at line 959 of file mux.c.

Referenced by gxf_interleave_packet(), and init_muxer().

◆ ff_interleave_packet_passthrough()

int ff_interleave_packet_passthrough ( AVFormatContext s,
AVPacket pkt,
int  flush,
int  has_packet 
)

Interleave packets directly in the order in which they arrive without any sort of buffering.

Definition at line 1079 of file mux.c.

Referenced by init_muxer().

◆ ff_get_muxer_ts_offset()

int ff_get_muxer_ts_offset ( AVFormatContext s,
int  stream_index,
int64_t offset 
)

Definition at line 1085 of file mux.c.

Referenced by mov_flush_fragment().

◆ ff_interleaved_peek()

const AVPacket* ff_interleaved_peek ( AVFormatContext s,
int  stream 
)

Find the next packet in the interleaving queue for the given stream.

Returns
a pointer to a packet if one was found, NULL otherwise.

Definition at line 1101 of file mux.c.

Referenced by mov_flush_fragment().

◆ check_bitstream()

static int check_bitstream ( AVFormatContext s,
FFStream sti,
AVPacket pkt 
)
static

Definition at line 1114 of file mux.c.

Referenced by write_packets_common().

◆ interleaved_write_packet()

static int interleaved_write_packet ( AVFormatContext s,
AVPacket pkt,
int  flush,
int  has_packet 
)
static

Definition at line 1133 of file mux.c.

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

◆ write_packet_common()

static int write_packet_common ( AVFormatContext s,
AVStream st,
AVPacket pkt,
int  interleaved 
)
static

Definition at line 1151 of file mux.c.

Referenced by write_packets_common(), and write_packets_from_bsfs().

◆ write_packets_from_bsfs()

static int write_packets_from_bsfs ( AVFormatContext s,
AVStream st,
AVPacket pkt,
int  interleaved 
)
static

Definition at line 1175 of file mux.c.

Referenced by av_write_trailer(), and write_packets_common().

◆ write_packets_common()

static int write_packets_common ( AVFormatContext s,
AVPacket pkt,
int  interleaved 
)
static

Definition at line 1208 of file mux.c.

Referenced by av_interleaved_write_frame(), and av_write_frame().

◆ ff_stream_add_bitstream_filter()

int ff_stream_add_bitstream_filter ( AVStream st,
const char *  name,
const char *  args 
)

Add a bitstream filter to a stream.

Parameters
stoutput stream to add a filter to
namethe name of the filter to add
argsfilter-specific argument string
Returns
>0 on success; AVERROR code on failure

Definition at line 1351 of file mux.c.

Referenced by daud_init(), flv_check_bitstream(), gxf_write_header(), ivf_init(), latm_check_bitstream(), mkv_check_bitstream(), mov_check_bitstream(), mpegts_check_bitstream(), mxf_check_bitstream(), and mxf_init().

◆ ff_write_chained()

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. It will be returned blank when av_interleaved_write_frame() is used, unchanged otherwise.
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 1394 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().

◆ uncoded_frame_free()

static void uncoded_frame_free ( void *  unused,
uint8_t *  data 
)
static

Definition at line 1424 of file mux.c.

Referenced by write_uncoded_frame_internal().

◆ write_uncoded_frame_internal()

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

Definition at line 1430 of file mux.c.

Referenced by av_interleaved_write_uncoded_frame(), and av_write_uncoded_frame().