FFmpeg
mux.h
Go to the documentation of this file.
1 /*
2  * copyright (c) 2001 Fabrice Bellard
3  *
4  * This file is part of FFmpeg.
5  *
6  * FFmpeg is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * FFmpeg is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with FFmpeg; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 
21 #ifndef AVFORMAT_MUX_H
22 #define AVFORMAT_MUX_H
23 
24 #include <stdint.h>
25 #include "libavcodec/packet.h"
26 #include "avformat.h"
27 
28 struct AVDeviceInfoList;
29 
30 /**
31  * This flag indicates that the muxer stores data internally
32  * and supports flushing it. Flushing is signalled by sending
33  * a NULL packet to the muxer's write_packet callback;
34  * without this flag, a muxer never receives NULL packets.
35  * So the documentation of write_packet below for the semantics
36  * of the return value in case of flushing.
37  */
38 #define FF_OFMT_FLAG_ALLOW_FLUSH (1 << 1)
39 /**
40  * If this flag is set, it indicates that for each codec type
41  * whose corresponding default codec (i.e. AVOutputFormat.audio_codec,
42  * AVOutputFormat.video_codec and AVOutputFormat.subtitle_codec)
43  * is set (i.e. != AV_CODEC_ID_NONE) only one stream of this type
44  * can be muxed. It furthermore indicates that no stream with
45  * a codec type that has no default codec or whose default codec
46  * is AV_CODEC_ID_NONE can be muxed.
47  * Both of these restrictions are checked generically before
48  * the actual muxer's init/write_header callbacks.
49  */
50 #define FF_OFMT_FLAG_MAX_ONE_OF_EACH (1 << 2)
51 /**
52  * If this flag is set, then the only permitted audio/video/subtitle
53  * codec ids are AVOutputFormat.audio/video/subtitle_codec;
54  * if any of the latter is unset (i.e. equal to AV_CODEC_ID_NONE),
55  * then no stream of the corresponding type is supported.
56  * In addition, codec types without default codec field
57  * are disallowed.
58  */
59 #define FF_OFMT_FLAG_ONLY_DEFAULT_CODECS (1 << 3)
60 
61 typedef struct FFOutputFormat {
62  /**
63  * The public AVOutputFormat. See avformat.h for it.
64  */
66  /**
67  * size of private data so that it can be allocated in the wrapper
68  */
70 
71  /**
72  * Internal flags. See FF_OFMT_FLAG_* above and FF_FMT_FLAG_* in internal.h.
73  */
75 
77  /**
78  * Write a packet. If FF_OFMT_FLAG_ALLOW_FLUSH is set in flags_internal,
79  * pkt can be NULL in order to flush data buffered in the muxer.
80  * When flushing, return 0 if there still is more data to flush,
81  * or 1 if everything was flushed and there is no more buffered
82  * data.
83  */
86  /**
87  * A format-specific function for interleavement.
88  * If unset, packets will be interleaved by dts.
89  *
90  * @param s An AVFormatContext for output. pkt will be added to
91  * resp. taken from its packet buffer.
92  * @param[in,out] pkt A packet to be interleaved if has_packet is set;
93  * also used to return packets. If no packet is returned
94  * (e.g. on error), pkt is blank on return.
95  * @param flush 1 if no further packets are available as input and
96  * all remaining packets should be output.
97  * @param has_packet If set, pkt contains a packet to be interleaved
98  * on input; otherwise pkt is blank on input.
99  * @return 1 if a packet was output, 0 if no packet could be output,
100  * < 0 if an error occurred
101  */
103  int flush, int has_packet);
104  /**
105  * Test if the given codec can be stored in this container.
106  *
107  * @return 1 if the codec is supported, 0 if it is not.
108  * A negative number if unknown.
109  * MKTAG('A', 'P', 'I', 'C') if the codec is only supported as AV_DISPOSITION_ATTACHED_PIC
110  */
111  int (*query_codec)(enum AVCodecID id, int std_compliance);
112 
113  void (*get_output_timestamp)(AVFormatContext *s, int stream,
114  int64_t *dts, int64_t *wall);
115  /**
116  * Allows sending messages from application to device.
117  */
119  void *data, size_t data_size);
120 
121  /**
122  * Write an uncoded AVFrame.
123  *
124  * See av_write_uncoded_frame() for details.
125  *
126  * The library will free *frame afterwards, but the muxer can prevent it
127  * by setting the pointer to NULL.
128  */
129  int (*write_uncoded_frame)(AVFormatContext *, int stream_index,
130  struct AVFrame **frame, unsigned flags);
131  /**
132  * Returns device list with it properties.
133  * @see avdevice_list_devices() for more details.
134  */
136  /**
137  * Initialize format. May allocate data here, and set any AVFormatContext or
138  * AVStream parameters that need to be set before packets are sent.
139  * This method must not write output.
140  *
141  * Return 0 if streams were fully configured, 1 if not, negative AVERROR on failure
142  *
143  * Any allocations made here must be freed in deinit().
144  */
146  /**
147  * Deinitialize format. If present, this is called whenever the muxer is being
148  * destroyed, regardless of whether or not the header has been written.
149  *
150  * If a trailer is being written, this is called after write_trailer().
151  *
152  * This is called if init() fails as well.
153  */
155  /**
156  * Set up any necessary bitstream filtering and extract any extra data needed
157  * for the global header.
158  *
159  * @note pkt might have been directly forwarded by a meta-muxer; therefore
160  * pkt->stream_index as well as the pkt's timebase might be invalid.
161  * Return 0 if more packets from this stream must be checked; 1 if not.
162  */
164  const AVPacket *pkt);
166 
167 static inline const FFOutputFormat *ffofmt(const AVOutputFormat *fmt)
168 {
169  return (const FFOutputFormat*)fmt;
170 }
171 
172 /**
173  * Add packet to an AVFormatContext's packet_buffer list, determining its
174  * interleaved position using compare() function argument.
175  * @return 0 on success, < 0 on error. pkt will always be blank on return.
176  */
178  int (*compare)(AVFormatContext *, const AVPacket *, const AVPacket *));
179 
180 /**
181  * Interleave an AVPacket per dts so it can be muxed.
182  * See the documentation of AVOutputFormat.interleave_packet for details.
183  */
185  int flush, int has_packet);
186 
187 /**
188  * Interleave packets directly in the order in which they arrive
189  * without any sort of buffering.
190  */
192  int flush, int has_packet);
193 
194 /**
195  * Find the next packet in the interleaving queue for the given stream.
196  *
197  * @return a pointer to a packet if one was found, NULL otherwise.
198  */
199 const AVPacket *ff_interleaved_peek(AVFormatContext *s, int stream);
200 
201 int ff_get_muxer_ts_offset(AVFormatContext *s, int stream_index, int64_t *offset);
202 
203 /**
204  * Add a bitstream filter to a stream.
205  *
206  * @param st output stream to add a filter to
207  * @param name the name of the filter to add
208  * @param args filter-specific argument string
209  * @return >0 on success;
210  * AVERROR code on failure
211  */
212 int ff_stream_add_bitstream_filter(AVStream *st, const char *name, const char *args);
213 
214 /**
215  * Write a packet to another muxer than the one the user originally
216  * intended. Useful when chaining muxers, where one muxer internally
217  * writes a received packet to another muxer.
218  *
219  * @param dst the muxer to write the packet to
220  * @param dst_stream the stream index within dst to write the packet to
221  * @param pkt the packet to be written. It will be returned blank when
222  * av_interleaved_write_frame() is used, unchanged otherwise.
223  * @param src the muxer the packet originally was intended for
224  * @param interleave 0->use av_write_frame, 1->av_interleaved_write_frame
225  * @return the value av_write_frame returned
226  */
227 int ff_write_chained(AVFormatContext *dst, int dst_stream, AVPacket *pkt,
229 
230 /**
231  * Flags for AVFormatContext.write_uncoded_frame()
232  */
234 
235  /**
236  * Query whether the feature is possible on this stream.
237  * The frame argument is ignored.
238  */
240 
241 };
242 
243 /**
244  * Make shift_size amount of space at read_start by shifting data in the output
245  * at read_start until the current IO position. The underlying IO context must
246  * be seekable.
247  */
248 int ff_format_shift_data(AVFormatContext *s, int64_t read_start, int shift_size);
249 
250 /**
251  * Utility function to open IO stream of output format.
252  *
253  * @param s AVFormatContext
254  * @param url URL or file name to open for writing
255  * @options optional options which will be passed to io_open callback
256  * @return >=0 on success, negative AVERROR in case of failure
257  */
259 
260 /**
261  * Parse creation_time in AVFormatContext metadata if exists and warn if the
262  * parsing fails.
263  *
264  * @param s AVFormatContext
265  * @param timestamp parsed timestamp in microseconds, only set on successful parsing
266  * @param return_seconds set this to get the number of seconds in timestamp instead of microseconds
267  * @return 1 if OK, 0 if the metadata was not present, AVERROR(EINVAL) on parse error
268  */
269 int ff_parse_creation_time_metadata(AVFormatContext *s, int64_t *timestamp, int return_seconds);
270 
271 /**
272  * Standardize creation_time metadata in AVFormatContext to an ISO-8601
273  * timestamp string.
274  *
275  * @param s AVFormatContext
276  * @return <0 on error
277  */
279 
280 #endif /* AVFORMAT_MUX_H */
name
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf default minimum maximum flags name is the option name
Definition: writing_filters.txt:88
FFOutputFormat::get_device_list
int(* get_device_list)(AVFormatContext *s, struct AVDeviceInfoList *device_list)
Returns device list with it properties.
Definition: mux.h:135
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: mux.c:1078
int64_t
long long int64_t
Definition: coverity.c:34
FFOutputFormat::control_message
int(* control_message)(AVFormatContext *s, int type, void *data, size_t data_size)
Allows sending messages from application to device.
Definition: mux.h:118
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:344
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.
Definition: mux.c:1393
FFOutputFormat::flags_internal
int flags_internal
Internal flags.
Definition: mux.h:74
data
const char data[16]
Definition: mxf.c:148
ff_parse_creation_time_metadata
int ff_parse_creation_time_metadata(AVFormatContext *s, int64_t *timestamp, int return_seconds)
Parse creation_time in AVFormatContext metadata if exists and warn if the parsing fails.
Definition: mux_utils.c:138
AVDictionary
Definition: dict.c:34
FFOutputFormat::p
AVOutputFormat p
The public AVOutputFormat.
Definition: mux.h:65
ff_interleave_add_packet
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 com...
Definition: mux.c:854
ff_interleaved_peek
const AVPacket * ff_interleaved_peek(AVFormatContext *s, int stream)
Find the next packet in the interleaving queue for the given stream.
Definition: mux.c:1100
type
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf type
Definition: writing_filters.txt:86
pkt
AVPacket * pkt
Definition: movenc.c:59
s
#define s(width, name)
Definition: cbs_vp9.c:198
ffofmt
static const FFOutputFormat * ffofmt(const AVOutputFormat *fmt)
Definition: mux.h:167
ff_format_shift_data
int ff_format_shift_data(AVFormatContext *s, int64_t read_start, int shift_size)
Make shift_size amount of space at read_start by shifting data in the output at read_start until the ...
Definition: mux_utils.c:72
frame
static AVFrame * frame
Definition: demux_decode.c:54
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.
Definition: mux.c:958
AVFormatContext
Format I/O context.
Definition: avformat.h:1255
FFOutputFormat::write_packet
int(* write_packet)(AVFormatContext *, AVPacket *pkt)
Write a packet.
Definition: mux.h:84
FFOutputFormat::deinit
void(* deinit)(AVFormatContext *)
Deinitialize format.
Definition: mux.h:154
flush
void(* flush)(AVBSFContext *ctx)
Definition: dts2pts.c:367
FFOutputFormat
Definition: mux.h:61
AVCodecID
AVCodecID
Identify the syntax and semantics of the bitstream.
Definition: codec_id.h:49
interleave
static void interleave(uint8_t *dst, uint8_t *src, int w, int h, int dst_linesize, int src_linesize, enum FilterMode mode, int swap)
Definition: vf_il.c:110
options
const OptionDef options[]
ff_standardize_creation_time
int ff_standardize_creation_time(AVFormatContext *s)
Standardize creation_time metadata in AVFormatContext to an ISO-8601 timestamp string.
Definition: mux_utils.c:155
FFOutputFormat::query_codec
int(* query_codec)(enum AVCodecID id, int std_compliance)
Test if the given codec can be stored in this container.
Definition: mux.h:111
FFOutputFormat::check_bitstream
int(* check_bitstream)(AVFormatContext *s, AVStream *st, const AVPacket *pkt)
Set up any necessary bitstream filtering and extract any extra data needed for the global header.
Definition: mux.h:163
FFOutputFormat::interleave_packet
int(* interleave_packet)(AVFormatContext *s, AVPacket *pkt, int flush, int has_packet)
A format-specific function for interleavement.
Definition: mux.h:102
offset
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf offset
Definition: writing_filters.txt:86
FFOutputFormat::priv_data_size
int priv_data_size
size of private data so that it can be allocated in the wrapper
Definition: mux.h:69
FFOutputFormat::write_header
int(* write_header)(AVFormatContext *)
Definition: mux.h:76
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.
Definition: mux.c:1350
AVOutputFormat
Definition: avformat.h:509
packet.h
ff_get_muxer_ts_offset
int ff_get_muxer_ts_offset(AVFormatContext *s, int stream_index, int64_t *offset)
Definition: mux.c:1084
FFOutputFormat::get_output_timestamp
void(* get_output_timestamp)(AVFormatContext *s, int stream, int64_t *dts, int64_t *wall)
Definition: mux.h:113
AVStream
Stream structure.
Definition: avformat.h:743
AVDeviceInfoList
List of devices.
Definition: avdevice.h:343
avformat.h
id
enum AVCodecID id
Definition: dts2pts.c:364
compare
static float compare(const AVFrame *haystack, const AVFrame *obj, int offx, int offy)
Definition: vf_find_rect.c:96
AV_WRITE_UNCODED_FRAME_QUERY
@ AV_WRITE_UNCODED_FRAME_QUERY
Query whether the feature is possible on this stream.
Definition: mux.h:239
AVPacket
This structure stores compressed data.
Definition: packet.h:499
src
INIT_CLIP pixel * src
Definition: h264pred_template.c:418
FFOutputFormat::write_trailer
int(* write_trailer)(AVFormatContext *)
Definition: mux.h:85
flags
#define flags(name, subs,...)
Definition: cbs_av1.c:482
ff_format_output_open
int ff_format_output_open(AVFormatContext *s, const char *url, AVDictionary **options)
Utility function to open IO stream of output format.
Definition: mux_utils.c:128
FFOutputFormat::init
int(* init)(AVFormatContext *)
Initialize format.
Definition: mux.h:145
int
int
Definition: ffmpeg_filter.c:409
FFOutputFormat::write_uncoded_frame
int(* write_uncoded_frame)(AVFormatContext *, int stream_index, struct AVFrame **frame, unsigned flags)
Write an uncoded AVFrame.
Definition: mux.h:129
AVWriteUncodedFrameFlags
AVWriteUncodedFrameFlags
Flags for AVFormatContext.write_uncoded_frame()
Definition: mux.h:233