Describe the bug
When adding a track to an MKVFile by passing a file path as a str, MKVFile.add_track internally builds the new MKVTrack like this:
new_track = MKVTrack(
track,
mkvmerge_path=self.mkvmerge_path,
existing_info=self._info_json,
)
self._info_json is the mkvmerge -J JSON output of the original file the MKVFile was constructed from, not the file being added. Since existing_info causes MKVTrack to read metadata from that JSON instead of running mkvmerge -J on the new file, and the new track defaults to track_id=0, the resulting MKVTrack ends up with metadata belonging to track 0 of the original file (typically the video track), completely unrelated to the file actually being added.
Creating an MKVTrack directly from the same path (without going through MKVFile.add_track) produces the correct metadata, confirming the bug is isolated to the existing_info=self._info_json reuse in MKVFile.add_track.
To Reproduce
from pymkv import MKVTrack, MKVFile
mkv = MKVFile("./source.mkv")
for track in mkv.tracks:
print(track.track_name, track.track_codec)
# Japanese [Uncut] HEVC/H.265/MPEG-H
# Japanese AAC
# Arabic (Saudi Arabia) SubStationAlpha
mkv.add_track("./subtitle.ass")
for track in mkv.tracks:
print(track.track_name, track.track_codec)
# ... (original 3 tracks unchanged)
# None HEVC/H.265/MPEG-H <-- wrong: should be a subtitle track
# Compare with a direct MKVTrack construction:
track = MKVTrack("./subtitle.ass")
print(track.track_codec, track.track_type)
# SubStationAlpha subtitles <-- correct
Expected behavior
N/A
Screenshots
N/A
Software (please complete the following information):
- OS: Arch Linux
- MKVToolNix version mkvtoolnix-100.0-1
Additional context
N/A
Describe the bug
When adding a track to an
MKVFileby passing a file path as astr,MKVFile.add_trackinternally builds the newMKVTracklike this:self._info_jsonis themkvmerge -JJSON output of the original file theMKVFilewas constructed from, not the file being added. Sinceexisting_infocausesMKVTrackto read metadata from that JSON instead of runningmkvmerge -Jon the new file, and the new track defaults totrack_id=0, the resultingMKVTrackends up with metadata belonging to track 0 of the original file (typically the video track), completely unrelated to the file actually being added.Creating an
MKVTrackdirectly from the same path (without going throughMKVFile.add_track) produces the correct metadata, confirming the bug is isolated to theexisting_info=self._info_jsonreuse inMKVFile.add_track.To Reproduce
Expected behavior
N/A
Screenshots
N/A
Software (please complete the following information):
Additional context
N/A