FFmpeg: libavformat/flacenc.c Source File
Go to the documentation of this file. 1 /*
2 * raw FLAC muxer
3 * Copyright (c) 2006-2009 Justin Ruggles
4 *
5 * This file is part of FFmpeg.
6 *
7 * FFmpeg is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * FFmpeg is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with FFmpeg; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
36
37
41
44 /* audio packets are queued here until we get all the attached pictures */
46
47 /* updated streaminfo sent by the encoder at the end */
50
53
55 int last_block)
56 {
57 avio_w8(pb, last_block ? 0x81 : 0x01);
60 return 0;
61 }
62
64 int last_block, int bitexact)
65 {
68
70
72 if (
len >= ((1<<24) - 4))
74
75 avio_w8(pb, last_block ? 0x84 : 0x04);
78
79 return 0;
80 }
81
83 {
89 const char *mimetype =
NULL, *
desc =
"";
91 int i, mimelen, desclen,
type = 0, blocklen;
92
94 return 0;
95
99 break;
100 }
101 mime++;
102 }
103 if (!mimetype) {
105 "write an attached picture.\n", st->
index);
107 }
108 mimelen = strlen(mimetype);
109
110 /* get the picture type */
115 break;
116 }
117 }
118
119 if ((
c->attached_types & (1 <<
type)) & 0x6) {
122 }
123
129 }
130
131 c->attached_types |= (1 <<
type);
132
133 /* get the description */
136 desclen = strlen(
desc);
137
138 blocklen = 4 + 4 + mimelen + 4 + desclen + 4 + 4 + 4 + 4 + 4 +
pkt->
size;
139 if (blocklen >= 1<<24) {
142 }
143
146
148
151
154
159 else
162
165 return 0;
166 }
167
169 {
170 int i,
ret, padding =
s->metadata_header_padding;
171 if (padding < 0)
172 padding = 8192;
173 /* The FLAC specification states that 24 bits are used to represent the
174 * size of a metadata block so we must clip this value to 2^24-1. */
176
177 for (
i = 0;
i <
s->nb_streams;
i++) {
181 continue;
186 }
187
192
193 /* The command line flac encoder defaults to placing a seekpoint
194 * every 10s. So one might add padding to allow that later
195 * but there seems to be no simple way to get the duration here.
196 * So just add the amount requested by the user. */
197 if (padding)
199
200 return 0;
201 }
202
204 {
208
209 c->audio_stream_idx = -1;
210 for (
i = 0;
i <
s->nb_streams;
i++) {
215 "audio stream is required.\n");
217 }
218 par =
s->streams[
i]->codecpar;
219 c->audio_stream_idx =
i;
223 continue;
227 }
else if (!
c->write_header) {
230 }
232 } else {
235 }
236 }
237 if (
c->audio_stream_idx < 0) {
240 }
241
242 /* add the channel layout tag */
248
249 if (chmask) {
251 "already present, this muxer will not overwrite it.\n");
252 } else {
253 uint8_t buf[32];
255 av_dict_set(&
s->metadata,
"WAVEFORMATEXTENSIBLE_CHANNEL_MASK", buf, 0);
256 }
257 }
258
259 return 0;
260 }
261
263 {
267
268 if (!
c->write_header)
269 return 0;
270
275
276 if (!
c->waiting_pics)
278
280 }
281
283 {
285 uint8_t *streaminfo;
286 size_t streaminfo_size;
287
288 /* check for updated streaminfo */
290 &streaminfo_size);
293 c->updated_streaminfo = 1;
294 }
295
298 return 0;
299 }
300
302 {
306
309 write = 0;
310
311 while (
c->queue.head) {
314 write = 0;
316 }
318 }
319
321 {
325
326 if (
c->waiting_pics) {
328 "attached pictures.\n");
330 }
331
332 if (!
c->write_header || !
c->updated_streaminfo)
333 return 0;
334
336 /* rewrite the STREAMINFO header block data */
341 } else {
343 }
344
345 return 0;
346 }
347
349 {
351
353 for (
unsigned i = 0;
i <
s->nb_streams;
i++)
355 }
356
358 {
361
363 if (
c->waiting_pics) {
364 /* buffer audio packets until we get all the pictures */
373 }
374 } else
376 } else {
378
379 if (!
c->waiting_pics ||
381 return 0;
382
383 /* warn only once for each stream */
387 }
389 return 0;
390
395
396 /* flush the buffered audio packets */
397 if (!
c->waiting_pics &&
400 }
401
402 return 0;
403 }
404
408 };
409
415 };
416
421 .
p.mime_type =
"audio/x-flac",
422 .p.extensions = "flac",
432 };
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
#define AV_LOG_WARNING
Something somehow does not look correct.
uint8_t * extradata
Extra binary data needed for initializing the decoder, codec-dependent.
#define AV_EF_EXPLODE
abort decoding on minor error detection
Filter the word "frame" indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
enum AVMediaType codec_type
General type of the encoded data.
This struct describes the properties of an encoded stream.
@ AV_PKT_DATA_NEW_EXTRADATA
The AV_PKT_DATA_NEW_EXTRADATA is used to notify the codec or the format that the extradata buffer was...
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
int av_strcasecmp(const char *a, const char *b)
Locale-independent case-insensitive compare.
int av_get_bits_per_pixel(const AVPixFmtDescriptor *pixdesc)
Return the number of bits per pixel used by the pixel format described by pixdesc.
enum AVChannelOrder order
Channel order used in this layout.
uint64_t mask
This member must be used for AV_CHANNEL_ORDER_NATIVE, and may be used for AV_CHANNEL_ORDER_AMBISONIC ...
int ff_flac_is_native_layout(uint64_t channel_layout)
void av_packet_free(AVPacket **pkt)
Free the packet, if the packet is reference counted, it will be unreferenced first.
static av_always_inline int64_t avio_tell(AVIOContext *s)
ftell() equivalent for AVIOContext.
int avpriv_packet_list_get(PacketList *pkt_buffer, AVPacket *pkt)
Remove the oldest AVPacket in the list and return it.
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
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
#define FF_ARRAY_ELEMS(a)
AVDictionaryEntry * av_dict_get(const AVDictionary *m, const char *key, const AVDictionaryEntry *prev, int flags)
Get a dictionary entry with matching key.
void avpriv_packet_list_free(PacketList *pkt_buf)
Wipe the list and unref all the packets in it.
AVCodecParameters * codecpar
Codec parameters associated with this stream.
#define LIBAVUTIL_VERSION_INT
Describe the class of an AVClass context structure.
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
int avpriv_packet_list_put(PacketList *packet_buffer, AVPacket *pkt, int(*copy)(AVPacket *dst, const AVPacket *src), int flags)
Append an AVPacket to the list.
const char * av_default_item_name(void *ptr)
Return the context name.
#define FLAC_STREAMINFO_SIZE
void avio_w8(AVIOContext *s, int b)
void ffio_fill(AVIOContext *s, int b, int64_t count)
AVChannelLayout ch_layout
Audio only.
const char *const ff_id3v2_picture_types[21]
#define AV_OPT_FLAG_ENCODING_PARAM
A generic parameter which can be set by the user for muxing or encoding.
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
const CodecMime ff_id3v2_mime_tags[]
int64_t nb_frames
number of frames in this stream if known or 0
int extradata_size
Size of the extradata content in bytes.
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
int seekable
A combination of AVIO_SEEKABLE_ flags or 0 when the stream is not seekable.
void avio_write(AVIOContext *s, const unsigned char *buf, int size)
void avio_wb32(AVIOContext *s, unsigned int val)
@ AV_CHANNEL_ORDER_NATIVE
The native channel order, i.e.
#define i(width, name, range_min, range_max)
uint8_t * av_packet_get_side_data(const AVPacket *pkt, enum AVPacketSideDataType type, size_t *size)
Get side information from packet.
uint8_t streaminfo[FLAC_STREAMINFO_SIZE]
int disposition
Stream disposition - a combination of AV_DISPOSITION_* flags.
int64_t avio_seek(AVIOContext *s, int64_t offset, int whence)
fseek() equivalent for AVIOContext.
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
int index
stream index in AVFormatContext
#define AVIO_SEEKABLE_NORMAL
Seeking works like for a local file.
union AVChannelLayout::@477 u
Details about which channels are present in this layout.
int ff_flac_write_header(AVIOContext *pb, const uint8_t *extradata, int extradata_size, int last_block)
IDirect3DDxgiInterfaceAccess _COM_Outptr_ void ** p
AVPacket * pkt
Used to hold temporary packets for the generic demuxing code.
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
void avio_wb24(AVIOContext *s, unsigned int val)
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
This structure stores compressed data.
@ AV_OPT_TYPE_BOOL
Underlying C type is int.
int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags)
Set the given entry in *pm, overwriting an existing entry.
static void write_header(FFV1Context *f)
AVPacket * av_packet_clone(const AVPacket *src)
Create a new packet that references the same data as src.
Generated on Sat Oct 18 2025 19:22:04 for FFmpeg by
doxygen
1.8.17