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