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,\
151 return (oggstream->
kfgshift && !(granule & ((1<<oggstream->
kfgshift)-1))) ||
152 (oggstream->
isvp8 && !((granule >> 3) & 0x07ffffff));
158 return (granule>>oggstream->
kfgshift) +
159 (granule & ((1<<oggstream->
kfgshift)-1));
160 else if (oggstream->
isvp8)
161 return granule >> 32;
170 int64_t next_granule, cur_granule;
179 return next_granule > cur_granule;
222 int total_segments = size / 255 + 1;
241 if (!header && oggstream->
page.
size > 0 &&
246 for (i = 0; i < total_segments; ) {
257 len =
FFMIN(size, segments*255);
259 memcpy(page->
data+page->
size, p, len);
265 if (i == total_segments)
278 }
else if (!header) {
313 bytestream_put_byte(&p, 1);
334 bytestream_put_byte(&p, 0x7F);
336 bytestream_put_byte(&p, 1);
337 bytestream_put_byte(&p, 0);
338 bytestream_put_be16(&p, 1);
340 bytestream_put_byte(&p, 0x00);
341 bytestream_put_be24(&p, 34);
349 bytestream_put_byte(&p, 0x84);
350 bytestream_put_be24(&p, oggstream->
header_len[1] - 4);
355 #define SPEEX_HEADER_SIZE 80
384 #define OPUS_HEADER_SIZE 19
413 #define VP8_HEADER_SIZE 26
427 bytestream_put_byte(&p, 0x4f);
429 bytestream_put_byte(&p, 1);
430 bytestream_put_byte(&p, 1);
431 bytestream_put_byte(&p, 0);
432 bytestream_put_be16(&p, par->
width);
433 bytestream_put_be16(&p, par->
height);
453 bytestream_put_byte(&p, 0x4f);
455 bytestream_put_byte(&p, 2);
456 bytestream_put_byte(&p, 0x20);
459 oggstream->
isvp8 = 1;
478 flush == 1 && oggstream->
page_count == 1 ? 4 : 0);
531 for (j = 0; j < i; j++) {
598 bytestream_put_byte(&p, header_type);
630 for (i = 1; i < 3; i++) {
659 if (pframe_count >= (1<<oggstream->
kfgshift)) {
670 int64_t
pts, invcnt, dist;
673 visible = (
pkt->
data[0] >> 4) & 1;
675 invcnt = (oggstream->last_granule >> 30) & 3;
676 invcnt = visible ? 3 : (invcnt == 3 ? 0 : invcnt + 1);
679 granule = (pts << 32) | (invcnt << 30) | (dist << 3);
684 oggstream->page.start_granule =
pkt->
pts;
692 oggstream->last_granule = granule;
748 .mime_type =
"application/ogg",
750 #if !CONFIG_OGV_MUXER
753 #if !CONFIG_SPX_MUXER
756 #if !CONFIG_OPUS_MUXER
761 .audio_codec = CONFIG_LIBVORBIS_ENCODER ?
768 .priv_class = &ogg_muxer_class,
777 .mime_type =
"audio/ogg",
780 .audio_codec = AV_CODEC_ID_FLAC,
785 .priv_class = &oga_muxer_class,
794 .mime_type =
"video/ogg",
797 .audio_codec = CONFIG_LIBVORBIS_ENCODER ?
799 .video_codec = CONFIG_LIBTHEORA_ENCODER ?
805 .priv_class = &ogv_muxer_class,
814 .mime_type =
"audio/ogg",
822 .priv_class = &spx_muxer_class,
826 #if CONFIG_OPUS_MUXER
831 .mime_type =
"audio/ogg",
832 .extensions =
"opus",
839 .priv_class = &opus_muxer_class,
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.
int avio_close_dyn_buf(AVIOContext *s, uint8_t **pbuffer)
Return the written size and a pointer to the buffer.
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.
AVRational sample_aspect_ratio
Video only.
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
int64_t avio_seek(AVIOContext *s, int64_t offset, int whence)
fseek() equivalent for AVIOContext.
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...
int avio_open_dyn_buf(AVIOContext **s)
Open a write only memory stream.
This struct describes the properties of an encoded stream.
static int ogg_write_page(AVFormatContext *s, OGGPage *page, int extra_flags)
static void ogg_update_checksum(AVFormatContext *s, AVIOContext *pb, int64_t crc_offset)
void avio_wl32(AVIOContext *s, unsigned int val)
int64_t duration
Duration of this packet in AVStream->time_base units, 0 if unknown.
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 av_always_inline int64_t avio_tell(AVIOContext *s)
ftell() equivalent for AVIOContext.
static const uint8_t header[24]
void avio_write(AVIOContext *s, const unsigned char *buf, int size)
static av_always_inline void ffio_wfourcc(AVIOContext *pb, const uint8_t *s)
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)
void avio_wl64(AVIOContext *s, uint64_t val)
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)
static int ogg_build_opus_headers(AVCodecParameters *par, OGGStreamContext *oggstream, int bitexact, AVDictionary **m)
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 const uint8_t offset[127][2]
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)
void ffio_init_checksum(AVIOContext *s, unsigned long(*update_checksum)(unsigned long c, const uint8_t *p, unsigned int len), unsigned long checksum)
int void avio_flush(AVIOContext *s)
Force flushing of buffered data.
static int write_trailer(AVFormatContext *s1)
unsigned long ff_crc04C11DB7_update(unsigned long checksum, const uint8_t *buf, unsigned int len)
static int ogg_compare_granule(AVFormatContext *s, OGGPage *next, OGGPage *page)
#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. ...
static volatile int checksum
#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 long ffio_get_checksum(AVIOContext *s)
static uint8_t * ogg_write_vorbiscomment(int64_t offset, int bitexact, int *header_len, AVDictionary **m, int framing_bit)
unsigned serial_num
serial number
static int64_t pts
Global timestamp for the audio frames.
int sample_rate
Audio only.
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)
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.
void avio_wb32(AVIOContext *s, unsigned int val)
#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
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented...
int64_t pref_duration
preferred page duration (0 => fill all segments)
AVRational r_frame_rate
Real base framerate of the stream.
static void ogg_write_pages(AVFormatContext *s, int flush)
This structure stores compressed data.
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.