Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect endianness of TimeCode property in (Simple)Block object #12

Closed
maurice-camp opened this issue Oct 13, 2021 · 4 comments
Closed
Labels
bug Something isn't working

Comments

@maurice-camp
Copy link

I'm trying to readout the timestamps for each datablock/frame in a matroska file. It seems however that the TimeCode property in the SimpleBlock object returns a value with little endianness while (according to https://matroska-org.github.io/libebml/specs.html) EBML integer datatypes are big-endian.

This leads to incorrect timestamps (when comparing to another tool like MKVToolNix):
image

MKVToolNix output:
image

If I manually revert endianness of the timecode file the values seem to match:

8448 -> 33
16896 -> 66
etc.

@StefH
Copy link
Owner

StefH commented Oct 13, 2021

Hello @maurice-camp,

I think this is an issue related to NEbml, can you post your question there?

--> https://github.com/OlegZee/NEbml

@maurice-camp
Copy link
Author

Hi @StefH

I looked into it a bit further and I dont think the issue is related to NEbml.
The Block.cs class uses the SpanReader class to retrieve the timecode from some binary data:

public virtual void Parse(Span<byte> span)
{
    var spanReader = new SpanReader(span);

    TrackNumber = spanReader.ReadVInt().Value;
    TimeCode = spanReader.ReadShort();
    Flags = spanReader.ReadByte();

The spanreader uses the MemoryMarshal.Read method for converting the byte array to a short:

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public T Read<T>() where T : unmanaged
{
    var newSpan = _currentSpan.Slice(Position);
    var result = MemoryMarshal.Read<T>(newSpan);
    Position += Unsafe.SizeOf<T>();

    return result;
}

I think this method is architecture dependent when it comes to endianness causing the incorrect value.

@StefH
Copy link
Owner

StefH commented Oct 14, 2021

#13

@StefH
Copy link
Owner

StefH commented Oct 14, 2021

@maurice-camp

This will be fixed in new version which will be released shortly.

@StefH StefH closed this as completed Oct 14, 2021
@StefH StefH added the bug Something isn't working label Oct 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants