Opened 19 months ago

Closed 18 months ago

Last modified 18 months ago

#11454 closed defect (fixed)

Ogg/Theora: Bad granulepos when GOP higher than 64

Reported by: Bernat Owned by:
Priority: normal Component: avcodec
Version: git-master Keywords: libtheoraenc
Cc: Bernat, MasterQuestionable Blocked By:
Blocking: Reproduced by developer: yes
Analyzed by developer: yes

Description (last modified by Bernat)

When encoding Theora video streams in an Ogg container with GOP size higher than 64, granulepos is wrong. The encoding is done with the right GOP size but the granulepos reported when decoding is wrong.

Here's an example from a file encoded with the following command:

ffmpeg -i input.mp4 -c:v libtheora -c:a libvorbis -g:v 300 output.ogv

The output plays fine but when analyzing the frames we can find this:

frame 64:

granulepos: 575
key-frame: 1
offset: 63
Theora API function th_packet_iskeyframe() returns false.

frame 65:

granulepos: 33280
key-frame: 65
offset: 0
Theora API function th_packet_iskeyframe() returns false.

So in both cases the decoder thinks these aren't key-frames and it should be right. But the granulepos of the second frame is constructed as if it was a key-frame.

It should be like this instead:

frame 65:

granulepos: 576
key-frame: 1
offset: 64

It looks like the encoder knows the GOP size is 300 but the code writing the granulepos thinks that the GOP size is 64.

If there's any way I can help, please ask me.

Thanks for your time.
Cheers.

Change History (9)

comment:1 by Bernat, 19 months ago

Description: modified (diff)

comment:2 by Bernat, 19 months ago

Description: modified (diff)

comment:3 by MasterQuestionable, 19 months ago

Cc: MasterQuestionable added
Component: undeterminedavcodec
Keywords: theora added

͏    Briefly, it's only some decoded frame metadata wrong:
͏    But no impact on actual playback?

comment:4 by Bernat, 19 months ago

No impact on playback but it has an impact on seeking. Granulepos is supposed to let you know how many frames back the previous key-frame is without decoding the video stream.

comment:5 by MasterQuestionable, 19 months ago

Analyzed by developer: set
Component: avcodecavformat
Keywords: oggparsetheora added; theora removed

͏    Is it alike the native "speex" decoder problems?
͏    https://trac.ffmpeg.org/ticket/11078#comment:12
͏    (using "-c:v libtheora" before "-i" may workaround?)
[ ^
͏    Probably not, as "libtheora" decoding support seems not implemented:
͏    https://github.com/search?type=code&q=repo:FFmpeg/FFmpeg+path:/^libav(?:codec|format)%5C/.*theora/
͏    .
͏    Yet found only:
͏    ͏"libavcodec/libtheoraenc.c"
͏    ͏"libavformat/oggparsetheora.c" ]

comment:6 by James, 19 months ago

Component: avformatavcodec
Reproduced by developer: set
Status: newopen

Probably not, as "libtheora" decoding support seems not implemented:

The theora decoder is in vp3.c

Patch for this issue sent to the mailing list.

comment:7 by Bernat, 18 months ago

I've tried the patch and it seems to work well. The keyframes are where the granulepos say they should be. Thank you!

comment:8 by James, 18 months ago

Resolution: fixed
Status: openclosed

comment:9 by MasterQuestionable, 18 months ago

Keywords: libtheoraenc added; oggparsetheora removed

͏    Per the description looks like encoder problem:
͏    https://github.com/FFmpeg/FFmpeg/commit/22aa71d4da37a4ad2b0d28deeace64b57aa2ef50

͏    Theora decoder is in ͏"vp3.c":
͏    Rough search gave no hint what VP3 is... (too obscure)

͏    Is ͏"oggparsetheora.c" specifically only for extracting the Theora stream in Ogg?

Note: See TracTickets for help on using tickets.