[libav-devel] [PATCH] oggenc: Support flushing the muxer

Martin Storsjö martin at martin.st
Tue Jun 3 08:39:50 CEST 2014


On Thu, 29 May 2014, Martin Storsjö wrote:

> This allows the caller to write all buffered data to disk, allowing
> the caller to know at what byte position in the file a certain
> packet starts (any packet written after the flush will be located
> after that byte position).
> ---
> I'm not familiar enough with ogg to know whether it is ok to do
> things like this or if this violates some aspect of the container's
> structure, but it seems to work for me.
> ---
> libavformat/oggenc.c | 21 +++++++++++++++++++--
> 1 file changed, 19 insertions(+), 2 deletions(-)
>
> diff --git a/libavformat/oggenc.c b/libavformat/oggenc.c
> index c30315a..0d8e239 100644
> --- a/libavformat/oggenc.c
> +++ b/libavformat/oggenc.c
> @@ -545,7 +545,7 @@ static int ogg_write_header(AVFormatContext *s)
>     return 0;
> }
>
> -static int ogg_write_packet(AVFormatContext *s, AVPacket *pkt)
> +static int ogg_write_packet_internal(AVFormatContext *s, AVPacket *pkt)
> {
>     AVStream *st = s->streams[pkt->stream_index];
>     OGGStreamContext *oggstream = st->priv_data;
> @@ -583,6 +583,23 @@ static int ogg_write_packet(AVFormatContext *s, AVPacket *pkt)
>     return 0;
> }
>
> +static int ogg_write_packet(AVFormatContext *s, AVPacket *pkt)
> +{
> +    int i;
> +
> +    if (pkt)
> +        return ogg_write_packet_internal(s, pkt);
> +
> +    for (i = 0; i < s->nb_streams; i++) {
> +        OGGStreamContext *oggstream = s->streams[i]->priv_data;
> +        if (oggstream->page.segments_count)
> +            ogg_buffer_page(s, oggstream);
> +    }
> +
> +    ogg_write_pages(s, 2);
> +    return 0;
> +}
> +
> static int ogg_write_trailer(AVFormatContext *s)
> {
>     int i;
> @@ -623,6 +640,6 @@ AVOutputFormat ff_ogg_muxer = {
>     .write_header      = ogg_write_header,
>     .write_packet      = ogg_write_packet,
>     .write_trailer     = ogg_write_trailer,
> -    .flags             = AVFMT_TS_NEGATIVE,
> +    .flags             = AVFMT_TS_NEGATIVE | AVFMT_ALLOW_FLUSH,
>     .priv_class        = &ogg_muxer_class,
> };
> -- 
> 1.8.5.2 (Apple Git-48)

Ok'd by Luca on irc.

// Martin


More information about the libav-devel mailing list