LostBeard / SpawnDev.EBML

An extendable .Net library for reading and writing Extensible Binary Meta Language (aka EBML) documents. Includes schema for Matroska and WebM.
https://lostbeard.github.io/SpawnDev.EBML/
MIT License
9 stars 1 forks source link

Error when trying to save an MKV file with extra elements #2

Closed Zeugma440 closed 2 months ago

Zeugma440 commented 2 months ago

Hi there,

I'm trying to use SpawnDev.EBML to alter the contents of an .mka (Matroska audio) file.

My test code aims at adding an attached picture :

using FileStream outputStream = new FileStream(@"newFile.mka", FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.Write, Settings.FileBufferSize, FileOptions.RandomAccess);
inputStream.Seek(0, SeekOrigin.Begin);
var doc = new WebMDocumentReader(inputStream);

var segment = doc.Segment;
if (segment != null)
{
   // Add a new embedded cover
    var attachments = new MasterElement(MatroskaId.Attachments);
    var file = new MasterElement(MatroskaId.AttachedFile);
    file.Add(new UTF8StringElement(MatroskaId.FileName, "cover.jpg"));

    attachments.Add(file);
    segment.Add(attachments);
}

doc.CopyTo(outputStream);

The app crashes while saving, displaying the following log :

The lazily-initialized type does not have a public, parameterless constructor.
   at System.LazyHelper.CreateViaDefaultConstructor[T]()
   at System.Lazy`1.ExecutionAndPublication(LazyHelper executionAndPublication, Boolean useDefaultConstructor)
   at System.Lazy`1.CreateValue()
   at System.Lazy`1.get_Value()
   at SpawnDev.EBML.BaseElement.get_Stream() in C:\Users\zeugm\source\repos\Zeugma440\atldotnet\SpawnDev.EBML\BaseElement.cs:line 64
   at SpawnDev.EBML.MasterElement.CopyTo(Stream stream, Nullable`1 bufferSize) in C:\Users\zeugm\source\repos\Zeugma440\atldotnet\SpawnDev.EBML\MasterElement.cs:line 126
   at SpawnDev.EBML.MasterElement.CopyTo(Stream stream, Nullable`1 bufferSize) in C:\Users\zeugm\source\repos\Zeugma440\atldotnet\SpawnDev.EBML\MasterElement.cs:line 138
   at SpawnDev.EBML.MasterElement.CopyTo(Stream stream, Nullable`1 bufferSize) in C:\Users\zeugm\source\repos\Zeugma440\atldotnet\SpawnDev.EBML\MasterElement.cs:line 138
   at ATL.AudioData.IO.MKA.Write(Stream s, TagData tag, ProgressToken`1 writeProgress) in C:\Users\zeugm\source\repos\Zeugma440\atldotnet\ATL\obj\Debug\net6.0\Zomp.SyncMethodGenerator\Zomp.SyncMethodGenerator.SyncMethodSourceGenerator\ATL.AudioData.IO.MKA.WriteAsync.g.cs:line 25

and the generated file looks like this

image

Any idea what's going on / what should I be doing?

Thanks in advance~

LostBeard commented 2 months ago

Version 1.0.4 Nuget is up and should work in your example.

LostBeard commented 2 months ago

Sorry. The update seems to fix the error, but the output is missing the segment block in my test. Looking into it...

LostBeard commented 2 months ago

Let me know if 1.0.4 is working for you. My test using your code is working now.

Zeugma440 commented 2 months ago

Looks fine to me now. Thanks for the quick fix, man :)

PS : I might submit other PRs and/or issues in the near future as I'm actively working on MKA write support.