36 #define MAX_PAGE_SIZE 65025 79 #define OFFSET(x) offsetof(OGGContext, x) 80 #define PARAM AV_OPT_FLAG_ENCODING_PARAM 83 {
"serial_offset",
"serial number offset",
85 {
"oggpagesize",
"Set preferred Ogg page size.",
87 {
"pagesize",
"preferred page size in bytes (deprecated)",
89 {
"page_duration",
"preferred page duration, in microseconds",
94 #define OGG_CLASS(flavor, name)\ 95 static const AVClass flavor ## _muxer_class = {\ 96 .class_name = #name " muxer",\ 97 .item_name = av_default_item_name,\ 99 .version = LIBAVUTIL_VERSION_INT,\ 105 uint8_t buf[4 + 1 + 1 + 8 + 4 + 4 + 4 + 1 + 255], *ptr = buf, *crc_pos;
109 bytestream_put_le32(&ptr,
MKTAG(
'O',
'g',
'g',
'S'));
110 bytestream_put_byte(&ptr, 0);
111 bytestream_put_byte(&ptr, page->
flags | extra_flags);
112 bytestream_put_le64(&ptr, page->
granule);
113 bytestream_put_le32(&ptr, oggstream->
serial_num);
116 bytestream_put_le32(&ptr, 0);
120 crc =
av_crc(crc_table, 0, buf, ptr - buf);
122 bytestream_put_be32(&crc_pos, crc);
132 return (oggstream->
kfgshift && !(granule & ((1<<oggstream->
kfgshift)-1))) ||
133 (oggstream->
isvp8 && !((granule >> 3) & 0x07ffffff));
139 return (granule>>oggstream->
kfgshift) +
140 (granule & ((1<<oggstream->
kfgshift)-1));
141 else if (oggstream->
isvp8)
142 return granule >> 32;
151 int64_t next_granule, cur_granule;
160 return next_granule > cur_granule;
203 int total_segments = size / 255 + 1;
222 if (!header && oggstream->
page.
size > 0 &&
227 for (i = 0; i < total_segments; ) {
238 len =
FFMIN(size, segments*255);
240 memcpy(page->
data+page->
size, p, len);
246 if (i == total_segments)
259 }
else if (!header) {
276 AVChapter **chapters,
unsigned int nb_chapters)
316 bytestream_put_byte(&p, 0x7F);
318 bytestream_put_byte(&p, 1);
319 bytestream_put_byte(&p, 0);
320 bytestream_put_be16(&p, 1);
322 bytestream_put_byte(&p, 0x00);
323 bytestream_put_be24(&p, 34);
331 bytestream_put_byte(&p, 0x84);
332 bytestream_put_be24(&p, oggstream->
header_len[1] - 4);
337 #define SPEEX_HEADER_SIZE 80 366 #define OPUS_HEADER_SIZE 19 371 unsigned int nb_chapters)
396 #define VP8_HEADER_SIZE 26 410 bytestream_put_byte(&p, 0x4f);
412 bytestream_put_byte(&p, 1);
413 bytestream_put_byte(&p, 1);
414 bytestream_put_byte(&p, 0);
415 bytestream_put_be16(&p, par->
width);
416 bytestream_put_be16(&p, par->
height);
436 bytestream_put_byte(&p, 0x4f);
438 bytestream_put_byte(&p, 2);
439 bytestream_put_byte(&p, 0x20);
442 oggstream->
isvp8 = 1;
461 flush == 1 && oggstream->
page_count == 1 ? 4 : 0);
514 for (j = 0; j <
i; j++) {
572 framing_bit,
NULL, 0);
577 bytestream_put_byte(&p, header_type);
617 for (i = 1; i < 3; i++) {
646 if (pframe_count >= (1<<oggstream->
kfgshift)) {
657 int64_t
pts, invcnt, dist;
660 visible = (pkt->
data[0] >> 4) & 1;
663 invcnt = visible ? 3 : (invcnt == 3 ? 0 : invcnt + 1);
666 granule = (pts << 32) | (invcnt << 30) | (dist << 3);
751 .mime_type =
"application/ogg",
753 #if !CONFIG_OGV_MUXER 756 #if !CONFIG_SPX_MUXER 759 #if !CONFIG_OPUS_MUXER 764 .audio_codec = CONFIG_LIBVORBIS_ENCODER ?
773 .priv_class = &ogg_muxer_class,
782 .mime_type =
"audio/ogg",
792 .priv_class = &oga_muxer_class,
801 .mime_type =
"video/ogg",
804 .audio_codec = CONFIG_LIBVORBIS_ENCODER ?
806 .video_codec = CONFIG_LIBTHEORA_ENCODER ?
814 .priv_class = &ogv_muxer_class,
823 .mime_type =
"audio/ogg",
833 .priv_class = &spx_muxer_class,
837 #if CONFIG_OPUS_MUXER 842 .mime_type =
"audio/ogg",
843 .extensions =
"opus",
852 .priv_class = &opus_muxer_class,
unsigned int nb_chapters
Number of chapters in AVChapter array.
static int ogg_write_header(AVFormatContext *s)
static void write_packet(OutputFile *of, AVPacket *pkt, OutputStream *ost, int unqueue)
int64_t last_granule
last packet granule
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
ptrdiff_t const GLvoid * data
static void flush(AVCodecContext *avctx)
#define AV_LOG_WARNING
Something somehow does not look correct.
unsigned page_count
number of page buffered
#define AV_DICT_DONT_OVERWRITE
Don't overwrite existing entries.
static av_cold int init(AVCodecContext *avctx)
AVRational sample_aspect_ratio
Video only.
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
int av_dict_copy(AVDictionary **dst, const AVDictionary *src, int flags)
Copy entries from one AVDictionary struct into another.
uint8_t data[MAX_PAGE_SIZE]
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
This struct describes the properties of an encoded stream.
static void ogg_free(AVFormatContext *s)
A point in the output bytestream where the underlying AVIOContext might flush the buffer depending on...
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
int64_t duration
Duration of this packet in AVStream->time_base units, 0 if unknown.
void avio_write_marker(AVIOContext *s, int64_t time, enum AVIODataMarkerType type)
Mark the written bytestream as a specific type.
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_WL16 uint64_t_TMPL AV_WB64 unsigned int_TMPL AV_RB32
AVStream ** streams
A list of all streams in the file.
static int ogg_build_speex_headers(AVCodecParameters *par, OGGStreamContext *oggstream, int bitexact, AVDictionary **m)
Public header for CRC hash function implementation.
int initial_padding
Audio only.
AVDictionaryEntry * av_dict_get(const AVDictionary *m, const char *key, const AVDictionaryEntry *prev, int flags)
Get a dictionary entry with matching key.
int flags
Flags modifying the (de)muxer behaviour.
static const uint8_t header[24]
void avio_write(AVIOContext *s, const unsigned char *buf, int size)
static const AVOption options[]
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
static int ogg_build_flac_headers(AVCodecParameters *par, OGGStreamContext *oggstream, int bitexact, AVDictionary **m)
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
AVDictionary * metadata
Metadata that applies to the whole file.
static int ogg_buffer_data(AVFormatContext *s, AVStream *st, uint8_t *data, unsigned size, int64_t granule, int header)
FLAC (Free Lossless Audio Codec) decoder/demuxer common functions.
struct OGGPageList * next
int pref_size
preferred page size (0 => fill all segments)
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
enum AVMediaType codec_type
General type of the encoded data.
static void ogg_write_page(AVFormatContext *s, OGGPage *page, int extra_flags)
static int ogg_reset_cur_page(OGGStreamContext *oggstream)
static int64_t ogg_granule_to_timestamp(OGGStreamContext *oggstream, int64_t granule)
int flags
A combination of AV_PKT_FLAG values.
int extradata_size
Size of the extradata content in bytes.
static int ogg_write_packet_internal(AVFormatContext *s, AVPacket *pkt)
unsigned int nb_streams
Number of elements in AVFormatContext.streams.
static int ogg_write_trailer(AVFormatContext *s)
static int ogg_build_opus_headers(AVCodecParameters *par, OGGStreamContext *oggstream, int bitexact, AVDictionary **m, AVChapter **chapters, unsigned int nb_chapters)
static int write_trailer(AVFormatContext *s1)
static int ogg_compare_granule(AVFormatContext *s, OGGPage *next, OGGPage *page)
uint32_t av_crc(const AVCRC *ctx, uint32_t crc, const uint8_t *buffer, size_t length)
Calculate the CRC of a block.
#define FLAC_STREAMINFO_SIZE
int avpriv_split_xiph_headers(const uint8_t *extradata, int extradata_size, int first_header_size, const uint8_t *header_start[3], int header_len[3])
Split a single extradata buffer into the three headers that most Xiph codecs use. ...
#define SPEEX_HEADER_SIZE
#define AV_TIME_BASE_Q
Internal time base represented as fractional value.
AVIOContext * pb
I/O context.
void avio_w8(AVIOContext *s, int b)
static int ogg_buffer_page(AVFormatContext *s, OGGStreamContext *oggstream)
static int ogg_write_packet(AVFormatContext *s, AVPacket *pkt)
Describe the class of an AVClass context structure.
#define OGG_CLASS(flavor, name)
Rational number (pair of numerator and denominator).
unsigned serial_num
serial number
static int ogg_init(AVFormatContext *s)
const AVCRC * av_crc_get_table(AVCRCId crc_id)
Get an initialized standard CRC table.
int sample_rate
Audio only.
int ffio_init_context(AVIOContext *s, unsigned char *buffer, int buffer_size, int write_flag, void *opaque, int(*read_packet)(void *opaque, uint8_t *buf, int buf_size), int(*write_packet)(void *opaque, uint8_t *buf, int buf_size), int64_t(*seek)(void *opaque, int64_t offset, int whence))
static int ogg_key_granule(OGGStreamContext *oggstream, int64_t granule)
int kfgshift
for theora granule
static av_always_inline void bytestream_put_buffer(uint8_t **b, const uint8_t *src, unsigned int size)
A Quick Description Of Rate Distortion Theory We want to encode a video
void * priv_data
Format private data.
static void write_header(FFV1Context *f)
uint8_t * extradata
Extra binary data needed for initializing the decoder, codec-dependent.
#define AV_DICT_IGNORE_SUFFIX
Return first entry in a dictionary whose first part corresponds to the search key, ignoring the suffix of the found key string.
uint32_t av_get_random_seed(void)
Get a seed to use in conjunction with random functions.
AVCodecParameters * codecpar
Codec parameters associated with this stream.
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented...
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
int64_t pref_duration
preferred page duration (0 => fill all segments)
#define MKTAG(a, b, c, d)
AVRational r_frame_rate
Real base framerate of the stream.
static void ogg_write_pages(AVFormatContext *s, int flush)
This structure stores compressed data.
static uint8_t * ogg_write_vorbiscomment(int64_t offset, int bitexact, int *header_len, AVDictionary **m, int framing_bit, AVChapter **chapters, unsigned int nb_chapters)
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
static int ogg_build_vp8_headers(AVFormatContext *s, AVStream *st, OGGStreamContext *oggstream, int bitexact)
#define AV_NOPTS_VALUE
Undefined timestamp value.