On Tue, Jan 25, 2011 at 08:16:30PM +0100, Andres Gonzalez wrote:
Please let me know if there is something wrong or missing.
--- a/libavformat/oggenc.c +++ b/libavformat/oggenc.c + +static const AVClass ogg_muxer_class = { + "OGG muxer",
The format is called "Ogg", not "OGG". Diego
This is the patch with: - No tabs - #include ".../avassert.h" removed - Ogg instead of OGG. -- Andr?s Gonz?lez T: 91 458 51 19 (ext:165) HI-IBERIA INGENIERIA Y PROYECTOS C/ Bolivia 5 - Madrid - 28016
Hi, 2011/1/26 Andres Gonzalez <acandido at hi-iberia.es>:
This is the patch with: - No tabs - #include ".../avassert.h" removed - Ogg instead of OGG.
Looks ok to me. Ronald
Hi, On 01/26/2011 03:03 AM, Andres Gonzalez wrote:
This is the patch with: - No tabs - #include ".../avassert.h" removed - Ogg instead of OGG.
[...]
+ if(ogg->pref_size<= 0) { + if (page->segments_count == 255) { + ogg_buffer_page(s, oggstream); + } + } else { + if (page->size>= ogg->pref_size) { + ogg_buffer_page(s, oggstream);
You still have to buffer the page at segments_count == 255. -- Baptiste COUDURIER Key fingerprint 8D77134D20CC9220201FC5DB0AC9325C5C1ABAAA FFmpeg maintainer http://www.ffmpeg.org
I think this is a pretty poor solution for the stated problem. It would basically be copying the braindead behaviour we're stuck with in libogg because of some poorly thought out parts of our ABI. The fundamental issue here is that more tightly packed pages mean greater efficiency, but they also mean higher delay. If you don't care about delay? pack away. But if you care then you have issues. The reason this solution is not good is that a straight size limit does _not_ bound the delay very tightly. If the packets being emitted by the codec are very small then you can still get up to 255 of them in a single page? which is the same worst case delay you had with maximum size pages! This means that your delay bounded streaming app will mostly work, but if the bitrate drops down it will stall and rebuffer. The _correct_ behaviour is to decide how much delay you are willing to tolerate and flush at least that often? regardless of how much data is in the pages. Gstreamer does this. Ffmpeg2theora also has a cap on the number of packets it will attempt to place per page. Libogg itself doesn't handle this well because the required data isn't passed into it. It does its own dumb flushing based on "4 packets or 4k", though callers can use an alternative entry which doesn't impose this limit if they're going to be smart and initiate the flushing on their own. (and even the original, automatic flushing, interface can be manually flushed). I don't see any reason for ffmpeg to be this stupid. I'm forwarding a off-list thread I had with Andres that discussed this some. I apologize for not doing so before now? I'd lost track of the thread after asking for his permission to take it back on thread. 2011/1/20 Andres Gonzalez <acandido at hi-iberia.es>:
On 20/01/11 16:50, Gregory Maxwell wrote:
2011/1/20 Andres Gonzalez<acandido at hi-iberia.es>:
The main purpose is streaming OGG files encoded in real-time with FFmpeg to an Icecast server.
By default, FFmpeg writes pages as big as possible (this is, about 64 KiB). This is OK for most uses (less overhead) but if you want to stream this OGG file to an Icecast server, Icecast cannot manage big pages. Clients receive an HTTP response, and nothing else. So the easier way to solve this is sending small pages from the source client.
ffmpeg2theora makes small pages (~ 4 KB) and works well with Icecast, but does not have filters (AFAIK), which are very important for me. Gstreamer's shout2send element also make pages ~ 4 KB, but that's a harder solution...
What you want for this is a _delay_ based packetization, which gstreamer can do. E.g. Don't limit pages by size, limit them by the amount of seconds of data allowed inside them. This is much better for this purpose and will also avoid creating many continued pages.
Interesting idea. If I understand you, I agree with that in the sense that, just making smaller pages could end in big sequences of small pages of the same logical stream, which may cause a delay or starving of some of the streams in the player, on the listener client.
But I would like to keep an eye on the fact that the key problem is that Icecast does not manage well big buffers of data. That said, it's true that if I know (or set explicitly) the bitrate, I could set a delay limit such to get packets that don't exceed a size limit.
By the way, is that "delay limit" functionality available on ffmpeg already?
Here's a little more information about this topic, if you want to have a look:
http://lists.xiph.org/pipermail/icecast-dev/2010-October/001956.html http://lists.xiph.org/pipermail/icecast-dev/2010-October/001958.html
http://lists.mplayerhq.hu/pipermail/ffmpeg-user/2010-October/027597.html
Mind if I reflect this back to the list?
No problem, feel free.
-- Andr?s Gonz?lez
T: 91 458 51 19 (ext:165) HI-IBERIA INGENIERIA Y PROYECTOS C/ Bolivia 5 - Madrid - 28016
Hi, On Wed, Jan 26, 2011 at 4:11 PM, Gregory Maxwell <gmaxwell at gmail.com> wrote:
I think this is a pretty poor solution for the stated problem. It would basically be copying the braindead behaviour we're stuck with in libogg because of some poorly thought out parts of our ABI.
We can always add a better solution once implemented. Care to give it a shot? Ronald
Hi Gregory, On 01/26/2011 01:11 PM, Gregory Maxwell wrote:
I think this is a pretty poor solution for the stated problem. It would basically be copying the braindead behaviour we're stuck with in libogg because of some poorly thought out parts of our ABI.
The fundamental issue here is that more tightly packed pages mean greater efficiency, but they also mean higher delay. If you don't care about delay? pack away. But if you care then you have issues.
The reason this solution is not good is that a straight size limit does _not_ bound the delay very tightly. If the packets being emitted by the codec are very small then you can still get up to 255 of them in a single page? which is the same worst case delay you had with maximum size pages! This means that your delay bounded streaming app will mostly work, but if the bitrate drops down it will stall and rebuffer.
The _correct_ behaviour is to decide how much delay you are willing to tolerate and flush at least that often? regardless of how much data is in the pages. Gstreamer does this. Ffmpeg2theora also has a cap on the number of packets it will attempt to place per page.
I definitely agree with this and implemented something like this in the past. Anyway with the per muxer options, it's easy to add. [...] -- Baptiste COUDURIER Key fingerprint 8D77134D20CC9220201FC5DB0AC9325C5C1ABAAA FFmpeg maintainer http://www.ffmpeg.org
On Thu, Jan 27, 2011 at 03:33:27PM -0800, Baptiste Coudurier wrote:
Hi Gregory,
On 01/26/2011 01:11 PM, Gregory Maxwell wrote:
I think this is a pretty poor solution for the stated problem. It would basically be copying the braindead behaviour we're stuck with in libogg because of some poorly thought out parts of our ABI.
The fundamental issue here is that more tightly packed pages mean greater efficiency, but they also mean higher delay. If you don't care about delay? pack away. But if you care then you have issues.
The reason this solution is not good is that a straight size limit does _not_ bound the delay very tightly. If the packets being emitted by the codec are very small then you can still get up to 255 of them in a single page? which is the same worst case delay you had with maximum size pages! This means that your delay bounded streaming app will mostly work, but if the bitrate drops down it will stall and rebuffer.
The _correct_ behaviour is to decide how much delay you are willing to tolerate and flush at least that often? regardless of how much data is in the pages. Gstreamer does this. Ffmpeg2theora also has a cap on the number of packets it will attempt to place per page.
I definitely agree with this and implemented something like this in the past.
Anyway with the per muxer options, it's easy to add.
Does this not apply to several muxers? and is not the existing max_delay option useable for it? [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB The bravest are surely those who have the clearest vision of what is before them, glory and danger alike, and yet notwithstanding go out to meet it. -- Thucydides
On 26/01/11 21:54, Baptiste Coudurier wrote:
You still have to buffer the page at segments_count == 255.
Ok! Here it is. -- Andr?s Gonz?lez T: 91 458 51 19 (ext:165) HI-IBERIA INGENIERIA Y PROYECTOS C/ Bolivia 5 - Madrid - 28016
Hi, 2011/1/27 Andres Gonzalez <acandido at hi-iberia.es>:
On 26/01/11 21:54, Baptiste Coudurier wrote:
You still have to buffer the page at segments_count == 255.
Ok! Here it is. [..] @@ -208,8 +227,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);
You broke the indent of that last line, should be 4-spaces not 3-spaces. Still OK apart from that, whoever commits can fix that himself... Ronald
On Thu, Jan 27, 2011 at 09:30:05AM -0500, Ronald S. Bultje wrote:
Hi,
2011/1/27 Andres Gonzalez <acandido at hi-iberia.es>:
On 26/01/11 21:54, Baptiste Coudurier wrote:
You still have to buffer the page at segments_count == 255.
Ok! Here it is. [..] @@ -208,8 +227,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);
You broke the indent of that last line, should be 4-spaces not 3-spaces. Still OK apart from that, whoever commits can fix that himself...
and missing space between 'if' and '('. both fixed locally and queued Janne
On Thu, Jan 27, 2011 at 06:24:15PM +0100, Janne Grunau wrote:
On Thu, Jan 27, 2011 at 09:30:05AM -0500, Ronald S. Bultje wrote:
Hi,
2011/1/27 Andres Gonzalez <acandido at hi-iberia.es>:
On 26/01/11 21:54, Baptiste Coudurier wrote:
You still have to buffer the page at segments_count == 255.
Ok! Here it is. [..] @@ -208,8 +227,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);
You broke the indent of that last line, should be 4-spaces not 3-spaces. Still OK apart from that, whoever commits can fix that himself...
and missing space between 'if' and '('. both fixed locally and queued
dropped in favour of the delay based solution Janne
On 28/01/11 17:31, Janne Grunau wrote:
On Thu, Jan 27, 2011 at 06:24:15PM +0100, Janne Grunau wrote:
dropped in favour of the delay based solution Ok. Thank you all for the reviews and comments.
Regards, Andres -- Andr?s Gonz?lez T: 91 458 51 19 (ext:165) HI-IBERIA INGENIERIA Y PROYECTOS C/ Bolivia 5 - Madrid - 28016
On 01/27/2011 01:31 AM, Andres Gonzalez wrote:
On 26/01/11 21:54, Baptiste Coudurier wrote:
You still have to buffer the page at segments_count == 255.
Ok! Here it is.
0001-Added-oggpagesize-option-for-Ogg-encoding.-Allows-se.patch
From fe16ae48a9a2bbb07b3c841d01daf4e506e2e207 Mon Sep 17 00:00:00 2001 From: Andres Gonzalez<acandido at hi-iberia.es> Date: Thu, 27 Jan 2011 10:14:21 +0100 Subject: [PATCH] Added oggpagesize option for Ogg encoding. Allows setting a preferred page size. When set, if an Ogg stream buffer has enough data, a page is made, instead of filling maximum-size pages.
--- libavformat/oggenc.c | 25 +++++++++++++++++++++++-- 1 files changed, 23 insertions(+), 2 deletions(-)
diff --git a/libavformat/oggenc.c b/libavformat/oggenc.c index b72efc8..cf4ff91 100644 --- a/libavformat/oggenc.c +++ b/libavformat/oggenc.c @@ -20,6 +20,7 @@ */
#include "libavutil/crc.h" +#include "libavutil/opt.h" #include "libavutil/random_seed.h" #include "libavcodec/xiph.h" #include "libavcodec/bytestream.h" @@ -61,9 +62,26 @@ typedef struct OGGPageList { } OGGPageList;
typedef struct { + const AVClass *class; OGGPageList *page_list; + int pref_size; ///< preferred page size (0 => fill all segments) } OGGContext;
+ +static const AVOption options[] = { + { "oggpagesize", "Set preferred Ogg page size.", + offsetof(OGGContext, pref_size), FF_OPT_TYPE_INT, 0, 0, MAX_PAGE_SIZE, AV_OPT_FLAG_ENCODING_PARAM}, + { NULL }, +}; + +static const AVClass ogg_muxer_class = { + "Ogg muxer", + av_default_item_name, + options, + LIBAVUTIL_VERSION_INT, +}; + + static void ogg_update_checksum(AVFormatContext *s, ByteIOContext *pb, int64_t crc_offset) { int64_t pos = url_ftell(pb); @@ -173,6 +191,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; @@ -208,8 +227,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); }
Here it is, and btw you can tweak this condition to buffer the page on a delay basis instead of page size. -- Baptiste COUDURIER Key fingerprint 8D77134D20CC9220201FC5DB0AC9325C5C1ABAAA FFmpeg maintainer http://www.ffmpeg.org
On Thu, Jan 27, 2011 at 10:31:51AM +0100, Andres Gonzalez wrote:
On 26/01/11 21:54, Baptiste Coudurier wrote:
You still have to buffer the page at segments_count == 255.
Ok! Here it is.
Applied a delay based solution is nice but theres no reason not to apply this until a delay based solution exists besides there are valid reasons to cut per size instead of time. MTU being one. [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB Those who are best at talking, realize last or never when they are wrong.
On Tue, May 10, 2011 at 1:31 PM, Michael Niedermayer <michaelni@gmx.at> wrote:
Applied a delay based solution is nice but theres no reason not to apply this until a delay based solution exists besides there are valid reasons to cut per size instead of time. MTU being one.
Delay based isn't just nice, it's the minimum required to achieve the original goal of the feature. I can't think of any application people care about where size actually matters. Are you actually aware of anything that will put Ogg pages in IP/UDP? I would expect people with that kind of application to use RTP... I'm quite curious. But I suppose it's nice to see people emulating libogg, even the completely brain-damaged parts of it.
On Tue, May 10, 2011 at 06:00:01PM -0400, Gregory Maxwell wrote:
On Tue, May 10, 2011 at 1:31 PM, Michael Niedermayer <michaelni@gmx.at> wrote:
Applied a delay based solution is nice but theres no reason not to apply this until a delay based solution exists besides there are valid reasons to cut per size instead of time. MTU being one.
Delay based isn't just nice, it's the minimum required to achieve the original goal of the feature.
I can't think of any application people care about where size actually matters. Are you actually aware of anything that will put Ogg pages in IP/UDP? I would expect people with that kind of application to use RTP... I'm quite curious.
size based limits make sense in environments that are bandwidth limited. you can limit delay to 1 sec but that might need 10sec to be actually received by the client when its bigger than the average bitrate. [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB The bravest are surely those who have the clearest vision of what is before them, glory and danger alike, and yet notwithstanding go out to meet it. -- Thucydides
Michael Niedermayer <michaelni <at> gmx.at> writes:
On Thu, Jan 27, 2011 at 10:31:51AM +0100, Andres Gonzalez wrote:
On 26/01/11 21:54, Baptiste Coudurier wrote:
You still have to buffer the page at segments_count == 255.
Ok! Here it is.
Applied a delay based solution is nice but theres no reason not to apply this until a delay based solution exists besides there are valid reasons to cut per size instead of time. MTU being one.
[...]
Thank you, Andres and Michael. :) Now my Ogg stream works with oggfwd/icecast2. Marcos
participants (10)
-
acandido@hi-iberia.es -
baptiste.coudurier@gmail.com -
diego@biurrun.de -
gmaxwell@gmail.com -
Gregory Maxwell -
janne-ffmpeg@jannau.net -
Marcos Mello -
Michael Niedermayer -
michaelni@gmx.at -
rsbultje@gmail.com