From 7c7469b345a3311c8e9a30103c276808f449d994 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Peter=20Zeb=C3=BChr?= <peter@zebuhr.se>
Date: Mon, 14 Dec 2020 16:13:03 +0100
Subject: [PATCH] Fix ogg page termination on even last packets

When the last packet of a stream was an even multiple of 255 and the
last terminating lacing value of 0 could not fit into the current page
because all 255 segements where used, then oggenc would fail to add a
last 'nil' page to properly terminate the stream. This would lead to
subsequent issues demuxing the produced stream with libogg. The fix is
to check if there are any segments left to write rather than just if
there is any data left to write when making the decision if a last page
should be created or or not.
---
 libavformat/oggenc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavformat/oggenc.c b/libavformat/oggenc.c
index f5032759a6..e57f6aaed4 100644
--- a/libavformat/oggenc.c
+++ b/libavformat/oggenc.c
@@ -706,7 +706,7 @@ static int ogg_write_trailer(AVFormatContext *s)
     for (i = 0; i < s->nb_streams; i++) {
         OGGStreamContext *oggstream = s->streams[i]->priv_data;
 
-        if (oggstream->page.size > 0)
+        if (oggstream->page.segments_count > 0)
             ogg_buffer_page(s, oggstream);
     }
 
-- 
2.28.0

