Code Monkey home page Code Monkey logo

matroska's Introduction

Projects

Matroska

An Ebml based serializer to deserialize a Matroska file (.mkv or .webm).

NuGet

Usage

Deserialize a stream to a MatroskaDocument

var stream = new FileStream("test.webm", FileMode.Open, FileAccess.Read);

var doc = MatroskaSerializer.Deserialize(stream);

Matroska.Muxer

A Matroska demuxer to extract Ogg Opus audio from a .webm file.

NuGet

Usage

Extract

var inputStream = new FileStream("test.webm", FileMode.Open, FileAccess.Read);
var outputStream = File.OpenWrite("test.opus");

MatroskaDemuxer.ExtractOggOpusAudio(inputStream, outputStream);

Credits / References

matroska's People

Contributors

stefh avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

robmikh

matroska's Issues

Incorrect endianness of TimeCode property in (Simple)Block object

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.

Unable to deserialize webm from audio recorded in Chrome

Hi,

At first, I wanna thank you for the time you're putting into this project!

I'm trying to record the audio from Chrome, route the WebM opus stream to .NET, convert to another format and re-route the audio to another system, for capturing the audio i'm using something like this:

        const stream = await navigator.mediaDevices.getUserMedia({ audio: true });

        this.mediaRecorder = new MediaRecorder(stream, {
            mimeType: 'audio/webm; codecs=opus'
        });

        this.mediaRecorder.start();

        this.isRecording = true;

        console.log("Starting media recorder ", this.mediaRecorder);

        this.mediaRecorder.ondataavailable = (e) => {
            //Do things, convert bytes to base64 and send the audio to the .NET back-end
        }

Now, following the examples, I'm using this code in order to extract the opus audio from the WebM stream:

        string b64Audio = audioPkt.Audio;
        byte[] webmBytes = Convert.FromBase64String(b64Audio);
        MemoryStream webmStream = new MemoryStream(webmBytes);

        var oggStream = new MemoryStream();

        MatroskaDemuxer.ExtractOggOpusAudio(webmStream, oggStream);

I confirm the webm bytes are the same recorded from the js, so no change in data, but in the line MatroskaDemuxer.ExtractOggOpusAudio(webmStream, oggStream); I got the following error:

System.ArgumentNullException: 'Value cannot be null. Arg_ParamName_Name'

Stack trace:

in Matroska.Muxer.OggOpus.OggOpusAudioStreamDemuxer.CopyTo(MatroskaDocument doc, Stream outputStream, OggOpusAudioStreamDemuxerSettings settings)
in Matroska.Muxer.MatroskaDemuxer.ExtractOggOpusAudio(MatroskaDocument doc, Stream outputStream, OggOpusAudioStreamDemuxerSettings settings)
in PROJECT_NAME.API.Hubs.LiveDataHub.SendAudio(ReceiveAudioDTO audioPkt) in PATH_TO_PROJECT\PROJECT_NAME.API\Hubs\LiveDataHub.cs: riga 70
in Microsoft.Extensions.Internal.ObjectMethodExecutor.<>c__DisplayClass33_0.b__0(Object target, Object[] parameters)
in Microsoft.AspNetCore.SignalR.Internal.DefaultHubDispatcher`1.d__23.MoveNext()

I'm not able to understand what's the cause of the problem looking into the examples and in the various docs of the repo, Am I missing something? Any idea of what can be the issue?

Convert to ts

Hello,
var doc = MatroskaSerializer.Deserialize(stream);
Can I export .ts from doc?
Or I can extract auto to mp3 or video to mp4.
Best regards,

Unable to correctly deserialize a Matroska file with multiple attachments

I've a Matroska file with multiple attachments and I'm trying to deserialize this file. However, I'm only getting one attachment, instead of all.

Looking into the class (in MatroskaModels.cs), this makes sense. It only exposes one AttachedFile:

public sealed class Attachments : BaseModel
{
	[MatroskaElementDescriptor(MatroskaSpecification.AttachedFile)]
	public AttachedFile AttachedFile { get; set; } = null!;
}

However, according to ebml_matroska.xml, this property has no maxOccurs:

<element name="AttachedFile" path="\Segment\Attachments\AttachedFile" id="0x61A7" type="master" minOccurs="1">
	<documentation lang="en" purpose="definition">An attached file.</documentation>
	<extension type="libmatroska" cppname="Attached"/>
</element>

I'm expecting that the model should contain a collection of AttachedFile. Similar to how multiple tags are handled. If I change manually the model to:

public sealed class Attachments : BaseModel
{
	[MatroskaElementDescriptor(MatroskaSpecification.AttachedFile, typeof(AttachedFile))]
	public List<AttachedFile> AttachedFile { get; set; } = null!;
}

It works as expected. I'm getting a collection of AttachedFile, with the correct information in there. I suspect something is going wrong with the auto-generated class?

Any chance to be able to use this library for writing MKVs ?

My use case is a bit special...

Ideally, I would need to write one or multiple video streams made of individual Jpeg files (a mjpeg stream), plus aditional metadata information per frame.

I don't know how difficult would be to do this, or even if MKV supports this workflow...

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.