sheldonkwoodward/pymkv

Removing multiple track at once doesn't produce the expected result

Opened this issue · 2 comments

azsde commented

Hello,

I have an MKV with a total of 8 tracks, I'm trying to remove 2 of them:

mkv = MKVFile('/path/to/file.mkv')
mkv.remove_track(5)
mkv.remove_track(7)
mkv.mux('/path/to/output.mkv')

The produced file has the track 5 successfully removed (it seems?) but the track 7 is still there and the track 8 has been removed but I wanted to keep it ...

Removing a single track seems to work however.

Is the removal of multiple tracks at once supposed to be working ?

azsde commented

After a quick debugging session, I found out why it is not behaving properly.

The removal of the tracks is done by calling:

del self.tracks[track_num]

This causes the indexes to be updated, thus when calling again mkv.remove_track, the index is not valid anymore.

IMO, the code should be updated not only to be resilient to this use case, but also to avoid removing tracks using their indexes but rather their ID.

azsde commented

I made PR that fixes the issue, I'll let you decide if you want to merge it or not.