• Andreas Rheinhardt's avatar
    avformat/matroskaenc: Improve calculating EBML ID size · e6ea75a3
    Andreas Rheinhardt authored
    When the Matroska muxer writes an EBML ID, it calculates the length of
    said ID before; and it does this as if this were a number that needs to
    be encoded as EBML number: The formula used is (av_log2(id + 1) - 1) / 7
    + 1. But the constants used already contain the VINT_MARKER (the leading
    bit indicating the length of the EBML number) and therefore the algorithm
    used makes no sense. Instead the position of the most significant byte
    set gives the desired length.
    
    The algorithm used until now worked because EBML numbers are subject to
    restrictions: If the EBML number takes up k bytes, then the bit 1 << (7
    * k) is set and av_log2(id) is 7 * k. So the current algorithm produces
    the correct result unless the EBML ID is of the form 7 * k - 1 because
    of the "id + 1". But contrary to encoding lengths as EBML number (where
    the + 1 exists to avoid the encodings reserved for unknown length),
    such EBML numbers are simply forbidden as EBML IDs and as such none of
    them were ever written.
    Signed-off-by: 's avatarAndreas Rheinhardt <andreas.rheinhardt@gmail.com>
    e6ea75a3
Name
Last commit
Last update
compat Loading commit data...
doc Loading commit data...
ffbuild Loading commit data...
fftools Loading commit data...
libavcodec Loading commit data...
libavdevice Loading commit data...
libavfilter Loading commit data...
libavformat Loading commit data...
libavresample Loading commit data...
libavutil Loading commit data...
libpostproc Loading commit data...
libswresample Loading commit data...
libswscale Loading commit data...
presets Loading commit data...
tests Loading commit data...
tools Loading commit data...
.gitattributes Loading commit data...
.gitignore Loading commit data...
.mailmap Loading commit data...
.travis.yml Loading commit data...
CONTRIBUTING.md Loading commit data...
COPYING.GPLv2 Loading commit data...
COPYING.GPLv3 Loading commit data...
COPYING.LGPLv2.1 Loading commit data...
COPYING.LGPLv3 Loading commit data...
CREDITS Loading commit data...
Changelog Loading commit data...
INSTALL.md Loading commit data...
LICENSE.md Loading commit data...
MAINTAINERS Loading commit data...
Makefile Loading commit data...
README.md Loading commit data...
RELEASE Loading commit data...
configure Loading commit data...