[FFmpeg-devel] [PATCH] avformat/oggenc: fix page duration calculation when granule differs from timestamp
James Almer
jamrial at gmail.com
Fri Jul 8 05:38:47 EEST 2016
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 <jamrial at 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.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-avformat-oggenc-fix-page-duration-calculation-when-g.patch
Type: text/x-patch
Size: 1543 bytes
Desc: not available
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20160707/b79761d3/attachment.bin>
More information about the ffmpeg-devel
mailing list