mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2024-12-23 12:43:46 +02:00
oggenc: add pagesize option to set preferred page size
When set, if an Ogg stream buffer has enough data, a page is made instead of filling maximum-size pages. Using smaller pages results smaller seek intervals at the expense of higher container overhead. Signed-off-by: Justin Ruggles <justin.ruggles@gmail.com>
This commit is contained in:
parent
67aec401d8
commit
ed3e1b485a
@ -21,6 +21,7 @@
|
||||
|
||||
#include "libavutil/crc.h"
|
||||
#include "libavutil/mathematics.h"
|
||||
#include "libavutil/opt.h"
|
||||
#include "libavutil/random_seed.h"
|
||||
#include "libavcodec/xiph.h"
|
||||
#include "libavcodec/bytestream.h"
|
||||
@ -63,9 +64,28 @@ typedef struct OGGPageList {
|
||||
} OGGPageList;
|
||||
|
||||
typedef struct {
|
||||
const AVClass *class;
|
||||
OGGPageList *page_list;
|
||||
int pref_size; ///< preferred page size (0 => fill all segments)
|
||||
} OGGContext;
|
||||
|
||||
#define OFFSET(x) offsetof(OGGContext, x)
|
||||
#define PARAM AV_OPT_FLAG_ENCODING_PARAM
|
||||
|
||||
static const AVOption options[] = {
|
||||
{ "pagesize", "preferred page size in bytes",
|
||||
OFFSET(pref_size), AV_OPT_TYPE_INT, { 0 }, 0, MAX_PAGE_SIZE, PARAM },
|
||||
{ NULL },
|
||||
};
|
||||
|
||||
static const AVClass ogg_muxer_class = {
|
||||
.class_name = "Ogg muxer",
|
||||
.item_name = av_default_item_name,
|
||||
.option = options,
|
||||
.version = LIBAVUTIL_VERSION_INT,
|
||||
};
|
||||
|
||||
|
||||
static void ogg_update_checksum(AVFormatContext *s, AVIOContext *pb, int64_t crc_offset)
|
||||
{
|
||||
int64_t pos = avio_tell(pb);
|
||||
@ -175,6 +195,7 @@ static int ogg_buffer_data(AVFormatContext *s, AVStream *st,
|
||||
uint8_t *data, unsigned size, int64_t granule)
|
||||
{
|
||||
OGGStreamContext *oggstream = st->priv_data;
|
||||
OGGContext *ogg = s->priv_data;
|
||||
int total_segments = size / 255 + 1;
|
||||
uint8_t *p = data;
|
||||
int i, segments, len, flush = 0;
|
||||
@ -210,8 +231,9 @@ static int ogg_buffer_data(AVFormatContext *s, AVStream *st,
|
||||
if (i == total_segments)
|
||||
page->granule = granule;
|
||||
|
||||
if (page->segments_count == 255) {
|
||||
ogg_buffer_page(s, oggstream);
|
||||
if (page->segments_count == 255 ||
|
||||
(ogg->pref_size > 0 && page->size >= ogg->pref_size)) {
|
||||
ogg_buffer_page(s, oggstream);
|
||||
}
|
||||
}
|
||||
|
||||
@ -515,4 +537,5 @@ AVOutputFormat ff_ogg_muxer = {
|
||||
.write_header = ogg_write_header,
|
||||
.write_packet = ogg_write_packet,
|
||||
.write_trailer = ogg_write_trailer,
|
||||
.priv_class = &ogg_muxer_class,
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user