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 typedef struct FFOutputFormat {
31  /**
32  * The public AVOutputFormat. See avformat.h for it.
33  */
35  /**
36  * size of private data so that it can be allocated in the wrapper
37  */
39 
40  /**
41  * Internal flags. See FF_FMT_FLAG_* in internal.h.
42  */
44 
46  /**
47  * Write a packet. If AVFMT_ALLOW_FLUSH is set in flags,
48  * pkt can be NULL in order to flush data buffered in the muxer.
49  * When flushing, return 0 if there still is more data to flush,
50  * or 1 if everything was flushed and there is no more buffered
51  * data.
52  */
55  /**
56  * A format-specific function for interleavement.
57  * If unset, packets will be interleaved by dts.
58  *
59  * @param s An AVFormatContext for output. pkt will be added to
60  * resp. taken from its packet buffer.
61  * @param[in,out] pkt A packet to be interleaved if has_packet is set;
62  * also used to return packets. If no packet is returned
63  * (e.g. on error), pkt is blank on return.
64  * @param flush 1 if no further packets are available as input and
65  * all remaining packets should be output.
66  * @param has_packet If set, pkt contains a packet to be interleaved
67  * on input; otherwise pkt is blank on input.
68  * @return 1 if a packet was output, 0 if no packet could be output,
69  * < 0 if an error occurred
70  */
72  int flush, int has_packet);
73  /**
74  * Test if the given codec can be stored in this container.
75  *
76  * @return 1 if the codec is supported, 0 if it is not.
77  * A negative number if unknown.
78  * MKTAG('A', 'P', 'I', 'C') if the codec is only supported as AV_DISPOSITION_ATTACHED_PIC
79  */
80  int (*query_codec)(enum AVCodecID id, int std_compliance);
81 
82  void (*get_output_timestamp)(AVFormatContext *s, int stream,
83  int64_t *dts, int64_t *wall);
84  /**
85  * Allows sending messages from application to device.
86  */
88  void *data, size_t data_size);
89 
90  /**
91  * Write an uncoded AVFrame.
92  *
93  * See av_write_uncoded_frame() for details.
94  *
95  * The library will free *frame afterwards, but the muxer can prevent it
96  * by setting the pointer to NULL.
97  */
98  int (*write_uncoded_frame)(AVFormatContext *, int stream_index,
99  AVFrame **frame, unsigned flags);
100  /**
101  * Returns device list with it properties.
102  * @see avdevice_list_devices() for more details.
103  */
105  /**
106  * Initialize format. May allocate data here, and set any AVFormatContext or
107  * AVStream parameters that need to be set before packets are sent.
108  * This method must not write output.
109  *
110  * Return 0 if streams were fully configured, 1 if not, negative AVERROR on failure
111  *
112  * Any allocations made here must be freed in deinit().
113  */
115  /**
116  * Deinitialize format. If present, this is called whenever the muxer is being
117  * destroyed, regardless of whether or not the header has been written.
118  *
119  * If a trailer is being written, this is called after write_trailer().
120  *
121  * This is called if init() fails as well.
122  */
124  /**
125  * Set up any necessary bitstream filtering and extract any extra data needed
126  * for the global header.
127  *
128  * @note pkt might have been directly forwarded by a meta-muxer; therefore
129  * pkt->stream_index as well as the pkt's timebase might be invalid.
130  * Return 0 if more packets from this stream must be checked; 1 if not.
131  */
133  const AVPacket *pkt);
135 
136 static inline const FFOutputFormat *ffofmt(const AVOutputFormat *fmt)
137 {
138  return (const FFOutputFormat*)fmt;
139 }
140 
141 /**
142  * Add packet to an AVFormatContext's packet_buffer list, determining its
143  * interleaved position using compare() function argument.
144  * @return 0 on success, < 0 on error. pkt will always be blank on return.
145  */
147  int (*compare)(AVFormatContext *, const AVPacket *, const AVPacket *));
148 
149 /**
150  * Interleave an AVPacket per dts so it can be muxed.
151  * See the documentation of AVOutputFormat.interleave_packet for details.
152  */
154  int flush, int has_packet);
155 
156 /**
157  * Interleave packets directly in the order in which they arrive
158  * without any sort of buffering.
159  */
161  int flush, int has_packet);
162 
163 /**
164  * Find the next packet in the interleaving queue for the given stream.
165  *
166  * @return a pointer to a packet if one was found, NULL otherwise.
167  */
168 const AVPacket *ff_interleaved_peek(AVFormatContext *s, int stream);
169 
170 int ff_get_muxer_ts_offset(AVFormatContext *s, int stream_index, int64_t *offset);
171 
172 /**
173  * Add a bitstream filter to a stream.
174  *
175  * @param st output stream to add a filter to
176  * @param name the name of the filter to add
177  * @param args filter-specific argument string
178  * @return >0 on success;
179  * AVERROR code on failure
180  */
181 int ff_stream_add_bitstream_filter(AVStream *st, const char *name, const char *args);
182 
183 /**
184  * Write a packet to another muxer than the one the user originally
185  * intended. Useful when chaining muxers, where one muxer internally
186  * writes a received packet to another muxer.
187  *
188  * @param dst the muxer to write the packet to
189  * @param dst_stream the stream index within dst to write the packet to
190  * @param pkt the packet to be written. It will be returned blank when
191  * av_interleaved_write_frame() is used, unchanged otherwise.
192  * @param src the muxer the packet originally was intended for
193  * @param interleave 0->use av_write_frame, 1->av_interleaved_write_frame
194  * @return the value av_write_frame returned
195  */
196 int ff_write_chained(AVFormatContext *dst, int dst_stream, AVPacket *pkt,
198 
199 /**
200  * Flags for AVFormatContext.write_uncoded_frame()
201  */
203 
204  /**
205  * Query whether the feature is possible on this stream.
206  * The frame argument is ignored.
207  */
209 
210 };
211 
212 /**
213  * Make shift_size amount of space at read_start by shifting data in the output
214  * at read_start until the current IO position. The underlying IO context must
215  * be seekable.
216  */
217 int ff_format_shift_data(AVFormatContext *s, int64_t read_start, int shift_size);
218 
219 /**
220  * Utility function to open IO stream of output format.
221  *
222  * @param s AVFormatContext
223  * @param url URL or file name to open for writing
224  * @options optional options which will be passed to io_open callback
225  * @return >=0 on success, negative AVERROR in case of failure
226  */
228 
229 /**
230  * Parse creation_time in AVFormatContext metadata if exists and warn if the
231  * parsing fails.
232  *
233  * @param s AVFormatContext
234  * @param timestamp parsed timestamp in microseconds, only set on successful parsing
235  * @param return_seconds set this to get the number of seconds in timestamp instead of microseconds
236  * @return 1 if OK, 0 if the metadata was not present, AVERROR(EINVAL) on parse error
237  */
238 int ff_parse_creation_time_metadata(AVFormatContext *s, int64_t *timestamp, int return_seconds);
239 
240 /**
241  * Standardize creation_time metadata in AVFormatContext to an ISO-8601
242  * timestamp string.
243  *
244  * @param s AVFormatContext
245  * @return <0 on error
246  */
248 
249 #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:104
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:1040
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:87
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:330
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:1355
FFOutputFormat::flags_internal
int flags_internal
Internal flags.
Definition: mux.h:43
data
const char data[16]
Definition: mxf.c:146
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:126
AVDictionary
Definition: dict.c:32
FFOutputFormat::p
AVOutputFormat p
The public AVOutputFormat.
Definition: mux.h:34
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:819
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:1062
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:256
ffofmt
static const FFOutputFormat * ffofmt(const AVOutputFormat *fmt)
Definition: mux.h:136
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:60
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:923
AVFormatContext
Format I/O context.
Definition: avformat.h:1104
FFOutputFormat::write_packet
int(* write_packet)(AVFormatContext *, AVPacket *pkt)
Write a packet.
Definition: mux.h:53
FFOutputFormat::deinit
void(* deinit)(AVFormatContext *)
Deinitialize format.
Definition: mux.h:123
FFOutputFormat
Definition: mux.h:30
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:108
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:143
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:80
FFOutputFormat::write_uncoded_frame
int(* write_uncoded_frame)(AVFormatContext *, int stream_index, AVFrame **frame, unsigned flags)
Write an uncoded AVFrame.
Definition: mux.h:98
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:132
FFOutputFormat::interleave_packet
int(* interleave_packet)(AVFormatContext *s, AVPacket *pkt, int flush, int has_packet)
A format-specific function for interleavement.
Definition: mux.h:71
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:38
FFOutputFormat::write_header
int(* write_header)(AVFormatContext *)
Definition: mux.h:45
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:1312
AVOutputFormat
Definition: avformat.h:507
packet.h
ff_get_muxer_ts_offset
int ff_get_muxer_ts_offset(AVFormatContext *s, int stream_index, int64_t *offset)
Definition: mux.c:1046
FFOutputFormat::get_output_timestamp
void(* get_output_timestamp)(AVFormatContext *s, int stream, int64_t *dts, int64_t *wall)
Definition: mux.h:82
AVStream
Stream structure.
Definition: avformat.h:838
frame
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return or at least make progress towards producing a frame
Definition: filter_design.txt:264
AVDeviceInfoList
List of devices.
Definition: avdevice.h:343
avformat.h
id
enum AVCodecID id
Definition: dts2pts_bsf.c:364
compare
static float compare(const AVFrame *haystack, const AVFrame *obj, int offx, int offy)
Definition: vf_find_rect.c:95
AV_WRITE_UNCODED_FRAME_QUERY
@ AV_WRITE_UNCODED_FRAME_QUERY
Query whether the feature is possible on this stream.
Definition: mux.h:208
flush
void(* flush)(AVBSFContext *ctx)
Definition: dts2pts_bsf.c:367
AVPacket
This structure stores compressed data.
Definition: packet.h:351
src
INIT_CLIP pixel * src
Definition: h264pred_template.c:418
FFOutputFormat::write_trailer
int(* write_trailer)(AVFormatContext *)
Definition: mux.h:54
flags
#define flags(name, subs,...)
Definition: cbs_av1.c:561
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:116
FFOutputFormat::init
int(* init)(AVFormatContext *)
Initialize format.
Definition: mux.h:114
int
int
Definition: ffmpeg_filter.c:156
AVWriteUncodedFrameFlags
AVWriteUncodedFrameFlags
Flags for AVFormatContext.write_uncoded_frame()
Definition: mux.h:202