On 7/7/2016 9:58 PM, Michael Niedermayer wrote:
> On Thu, Jul 07, 2016 at 07:13:47PM -0300, James Almer wrote:
>> Signed-off-by: James Almer <jamr...@gmail.com>
>> ---
>>
>>  libavformat/oggenc.c | 10 +++++-----
>>  1 file changed, 5 insertions(+), 5 deletions(-)
>>
>> diff --git a/libavformat/oggenc.c b/libavformat/oggenc.c
>> index f998af3..296028e 100644
>> --- a/libavformat/oggenc.c
>> +++ b/libavformat/oggenc.c
>> @@ -263,10 +263,10 @@ static int ogg_buffer_data(AVFormatContext *s, 
>> AVStream *st,
>>          {
>>              AVStream *st = s->streams[page->stream_index];
>>  
>> -            int64_t start = av_rescale_q(page->start_granule, st->time_base,
>> -                                         AV_TIME_BASE_Q);
>> -            int64_t next  = av_rescale_q(page->granule, st->time_base,
>> -                                         AV_TIME_BASE_Q);
>> +            int64_t start = 
>> av_rescale_q(ogg_granule_to_timestamp(oggstream, page->start_granule),
>> +                                         st->time_base, AV_TIME_BASE_Q);
>> +            int64_t next  = 
>> av_rescale_q(ogg_granule_to_timestamp(oggstream, page->granule),
>> +                                         st->time_base, AV_TIME_BASE_Q);
>>  
>>              if (page->segments_count == 255) {
>>                  ogg_buffer_page(s, oggstream);
>> @@ -596,7 +596,7 @@ static int ogg_write_packet_internal(AVFormatContext *s, 
>> AVPacket *pkt)
>>          granule = pkt->pts + pkt->duration;
>>  
>>      if (oggstream->page.start_granule == AV_NOPTS_VALUE)
>> -        oggstream->page.start_granule = pkt->pts;
>> +        oggstream->page.start_granule = granule;
>>  
>>      ret = ogg_buffer_data(s, st, pkt->data, pkt->size, granule, 0);
>>      if (ret < 0)
> 
> this breaks fate

Mmh, the granule in ogg_write_packet_internal used for start_granule is
different than pkt->pts for all codecs after being converted into a
timestamp, so that probably changed the calculations for a page's length.
I looked at the output of fate-lavf-ogg and the one created with this
patch had a 0 byte eos packet, which even though valid seems worse than
before the patch.

Here's a version that achieves the same thing (convert granule to ts
before trying to rescale it) while keeping start_granule intact.

>From 7b8d0e5598103cfed0ca37914d1eed933e03d5aa Mon Sep 17 00:00:00 2001
From: James Almer <jamr...@gmail.com>
Date: Thu, 7 Jul 2016 22:41:55 -0300
Subject: [PATCH] avformat/oggenc: fix page duration calculation when granule differs from timestamp

Signed-off-by: James Almer <jamr...@gmail.com>
---
 libavformat/oggenc.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/libavformat/oggenc.c b/libavformat/oggenc.c
index f998af3..a27e3a7 100644
--- a/libavformat/oggenc.c
+++ b/libavformat/oggenc.c
@@ -193,7 +193,7 @@ static int ogg_buffer_page(AVFormatContext *s, OGGStreamContext *oggstream)
         return AVERROR(ENOMEM);
     l->page = oggstream->page;
 
-    oggstream->page.start_granule = oggstream->page.granule;
+    oggstream->page.start_granule = ogg_granule_to_timestamp(oggstream, oggstream->page.granule);
     oggstream->page_count++;
     ogg_reset_cur_page(oggstream);
 
@@ -265,8 +265,8 @@ static int ogg_buffer_data(AVFormatContext *s, AVStream *st,
 
             int64_t start = av_rescale_q(page->start_granule, st->time_base,
                                          AV_TIME_BASE_Q);
-            int64_t next  = av_rescale_q(page->granule, st->time_base,
-                                         AV_TIME_BASE_Q);
+            int64_t next  = av_rescale_q(ogg_granule_to_timestamp(oggstream, page->granule),
+                                         st->time_base, AV_TIME_BASE_Q);
 
             if (page->segments_count == 255) {
                 ogg_buffer_page(s, oggstream);
-- 
2.9.0

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel

Reply via email to