Skip to content

Writing back to MKV file. #2

Open
@lukefrasera

Description

@lukefrasera

I am trying to attach a file to the ebml using the examples you have posted in your README.md, but each time it seems to corrupt the file after writing is complete. I am attaching a javascript file to the ebml and then attempting to write this back to the file. After processing the file becomes corrupt.

File: stream=<_io.BufferedReader name='test.mkv'>, size=4343950, 2 children
ElementSegment Segment (12+1590 @40): 6 children
    Segment UID: 34:FC:54:CF:06:CA:E0:BA:F7:6D:2E:13:37:E9:45:F3
    Title:       None
    Duration:    19.00 seconds
    Time scale:  1000000 nanoseconds
    Muxing app:  'Lavf56.40.101'
    Writing app: 'Lavf56.40.101'
    Seek entries:
        Attachments:  1485
        Tracks:       139
        Cues:         1406
        Info:         1411
        Tags:         1273
    Attachments:
        ElementAttachedFile: 'simbe_data' (text/javascript), 57 bytes: 'simbe meta data'
            UID: B4:6E:A5:BA:4A:BD:E0:46
    Tracks:
        ElementTrackEntry: video lang=und codec=V_MPEGH/ISO/HEVC num=1 uid=1
            Flags: enabled default !forced !lacing
            ElementVideo: dims=4912x3684, display=4912x3684, aspect='free resizing'
                Stereo:     mono
                Interlaced: False
    Tags:
        ElementTag: None (50), 1 tags
            ElementSimpleTag lang=und def=True: 'ENCODER' => 'Lavf56.40.101'
        ElementTag: None (50), 1 tags
            ElementSimpleTag lang=und def=True: 'ENCODER' => 'Lavc56.60.100 libx265'
        ElementTag: None (50), 1 tags
            ElementSimpleTag lang=und def=True: 'DURATION' => '00:00:19.000000000'
    Chapters:
In [4]: ebml_file = File('test.mkv')
---------------------------------------------------------------------------
DecodeError                               Traceback (most recent call last)
<ipython-input-4-85ca9046a476> in <module>()
----> 1 ebml_file = File('test.mkv')

/home/luke/Documents/t457_image_compression/python_ebml/container.py in __init__(self, f, summary)
    868 
    869         if summary:
--> 870             self.read_summary()
    871 
    872     def __enter__(self):

/home/luke/Documents/t457_image_compression/python_ebml/container.py in read_summary(self)
    940         start_time = datetime.now()
    941         self.read(self.stream, 0, self.stream_size,
--> 942                   summary=True, seekfirst=True)
    943         read_time = datetime.now() - start_time
    944         #pylint: disable=maybe-no-member

/home/luke/Documents/t457_image_compression/python_ebml/container.py in read(self, stream, start, length, summary, seekfirst)
    719         while cur_pos < end:
    720             child = self.read_element(stream, cur_pos, summary=summary,
--> 721                                       seekfirst=False)
    722             cur_pos += child.total_size
    723 

/home/luke/Documents/t457_image_compression/python_ebml/container.py in read_element(self, stream, start, summary, seekfirst)
    805 
    806         # New child
--> 807         header = Header(stream)
    808         tag = MATROSKA_TAGS[header.ebml_id]
    809         child = tag(header)

/home/luke/Documents/t457_image_compression/python_ebml/header.py in __init__(self, stream, ebml_id, size)
     58         self._size = None
     59         if stream:
---> 60             self.decode(stream)
     61         else:
     62             self._ebml_id = ebml_id

/home/luke/Documents/t457_image_compression/python_ebml/header.py in decode(self, stream)
    151          + EOFError, for an unexpected end of stream.
    152         """
--> 153         ebml_id, raw = read_var_int(stream, 4)
    154         numbytes_id = len(raw)
    155         if ebml_id is None:

/home/luke/Documents/t457_image_compression/python_ebml/utility.py in read_var_int(stream, max_bytes)
    140                 return (None, first_byte + rest)
    141             return (val, first_byte + rest)
--> 142     raise DecodeError("Invalid value more than {} bytes".format(max_bytes))
    143 
    144 def fmt_time(nsecs, precision=9, sep='.'):

DecodeError: Invalid value more than 4 bytes

Do I need to manually skip the header in the stream prior to writing? I feel like there must be something simple I am doing wrong.

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions