Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

extremely inefficient muxing #30

Open
rvbg opened this issue Oct 30, 2024 · 4 comments
Open

extremely inefficient muxing #30

rvbg opened this issue Oct 30, 2024 · 4 comments
Labels
bug Something isn't working

Comments

@rvbg
Copy link

rvbg commented Oct 30, 2024

Describe the bug
When muxing an MKV file with multiple tracks, it appears that each track is loaded individually from the file.
As a result, if a 1GB MKV file contains 10 subtitle tracks, a total of approximately 10GB of data will be read from the drive. This process is highly inefficient and slow.

To Reproduce
Use an MKV file with multiple tracks as the input.

mkv = pymkv.MKVFile(file_path=mkv_input_path, mkvmerge_path=mkvmerge_path)
print(mkv.command(mkv_output_path))

The mux command includes the input file multiple times, which apparently causes the file to be read multiple times.

Open a disk I/O viewer and run the mux process.

mkv.mux(mkv_output_path)

The viewer should display I/O read usage roughly equal to the file size multiplied by the track count.

Expected behavior
Each input file should only be read once. Selecting multiple tracks within a single input file should resolve this issue.

My old implementation for extracting subtitles works this way. However, keep in mind that this code is more of a proof of concept than a well-polished solution.

Screenshots
none

Software (please complete the following information):

  • OS: Arch Linux
  • MKVToolNix version v88.0 Flatpak
  • pymkv2==2.0.3

Additional context
Output of an example mkv file with mkv.command(output_path):

flatpak run org.bunkus.mkvtoolnix-gui mkvmerge -o /home/user/file.mks --title File --language 0:en --default-track 0:0 --forced-track 0:0 --hearing-impaired-flag 0:0 --visual-impaired-flag 0:0 --original-flag 0:0 --commentary-flag 0:0 -d 0 -A -S /home/user/file.mkv --track-name 1:Stereo --language 1:de --default-track 1:1 --forced-track 1:0 --hearing-impaired-flag 1:0 --visual-impaired-flag 1:0 --original-flag 1:0 --commentary-flag 1:0 -D -a 1 -S /home/user/file.mkv --track-name 2:Stereo --language 2:en --default-track 2:0 --forced-track 2:0 --hearing-impaired-flag 2:0 --visual-impaired-flag 2:0 --original-flag 2:0 --commentary-flag 2:0 -D -a 2 -S /home/user/file.mkv --track-name 3:Surround 5.1 --language 3:de --default-track 3:0 --forced-track 3:0 --hearing-impaired-flag 3:0 --visual-impaired-flag 3:0 --original-flag 3:0 --commentary-flag 3:0 -D -a 3 -S /home/user/file.mkv --track-name 4:Surround 5.1 --language 4:de --default-track 4:0 --forced-track 4:0 --hearing-impaired-flag 4:0 --visual-impaired-flag 4:0 --original-flag 4:0 --commentary-flag 4:0 -D -a 4 -S /home/user/file.mkv --track-name 5:Surround 5.1 --language 5:en --default-track 5:0 --forced-track 5:0 --hearing-impaired-flag 5:0 --visual-impaired-flag 5:0 --original-flag 5:0 --commentary-flag 5:0 -D -a 5 -S /home/user/file.mkv --track-name 6:Surround 5.1 --language 6:en --default-track 6:0 --forced-track 6:0 --hearing-impaired-flag 6:0 --visual-impaired-flag 6:0 --original-flag 6:0 --commentary-flag 6:0 -D -a 6 -S /home/user/file.mkv --track-name 7:Stereo --language 7:und --default-track 7:0 --forced-track 7:0 --hearing-impaired-flag 7:0 --visual-impaired-flag 7:0 --original-flag 7:0 --commentary-flag 7:0 -D -a 7 -S /home/user/file.mkv --track-name 8:Stereo --language 8:en --default-track 8:0 --forced-track 8:0 --hearing-impaired-flag 8:0 --visual-impaired-flag 8:0 --original-flag 8:0 --commentary-flag 8:0 -D -a 8 -S /home/user/file.mkv --language 9:de --default-track 9:0 --forced-track 9:0 --hearing-impaired-flag 9:0 --visual-impaired-flag 9:0 --original-flag 9:0 --commentary-flag 9:0 -D -A -s 9 /home/user/file.mkv --language 10:de --default-track 10:0 --forced-track 10:0 --hearing-impaired-flag 10:0 --visual-impaired-flag 10:0 --original-flag 10:0 --commentary-flag 10:0 -D -A -s 10 /home/user/file.mkv --language 11:en --default-track 11:0 --forced-track 11:0 --hearing-impaired-flag 11:0 --visual-impaired-flag 11:0 --original-flag 11:0 --commentary-flag 11:0 -D -A -s 11 /home/user/file.mkv --language 12:de --default-track 12:0 --forced-track 12:0 --hearing-impaired-flag 12:0 --visual-impaired-flag 12:0 --original-flag 12:0 --commentary-flag 12:0 -D -A -s 12 /home/user/file.mkv --track-order 0:0,0:1,0:2,0:3,0:4,0:5,0:6,0:7,0:8,0:9,0:10,0:11,0:12
@rvbg rvbg added the bug Something isn't working label Oct 30, 2024
@GitBib
Copy link
Owner

GitBib commented Oct 31, 2024

You're using an old version of pymkv2—latest is 2.0.8, but you've got 2.0.3. Try installing the newest version and see if that improves performance.

@rvbg
Copy link
Author

rvbg commented Oct 31, 2024

Yeah, I had some problems with a colliding ISO639 package on the newest version, but I will fix that in my project and report back. Thank you for the fast response!

@GitBib
Copy link
Owner

GitBib commented Oct 31, 2024

Can you guys describe the issue with ISO639? I'm noticing some complaints and have some ideas on how to fix them, but I need to gather more feedback.

@rvbg
Copy link
Author

rvbg commented Oct 31, 2024

I’ll work on upgrading my main project and investigate the ISO639 issue.

In the meantime, I created a new project using version 2.0.8 and re-ran the commands above, but I’m still seeing the same mkv.command output, that you can see in additional context.

I restructured the command to function as intended:

flatpak run org.bunkus.mkvtoolnix-gui mkvmerge -o "/home/user/file.mks" --title File \
--language 0:en --default-track 0:0 --forced-track 0:0 --hearing-impaired-flag 0:0 --visual-impaired-flag 0:0 --original-flag 0:0 --commentary-flag 0:0 \
--track-name 1:Stereo --language 1:de --default-track 1:1 --forced-track 1:0 --hearing-impaired-flag 1:0 --visual-impaired-flag 1:0 --original-flag 1:0 --commentary-flag 1:0 \
--track-name 2:Stereo --language 2:en --default-track 2:0 --forced-track 2:0 --hearing-impaired-flag 2:0 --visual-impaired-flag 2:0 --original-flag 2:0 --commentary-flag 2:0 \
--track-name 3:"Surround 5.1" --language 3:de --default-track 3:0 --forced-track 3:0 --hearing-impaired-flag 3:0 --visual-impaired-flag 3:0 --original-flag 3:0 --commentary-flag 3:0 \
--track-name 4:"Surround 5.1" --language 4:de --default-track 4:0 --forced-track 4:0 --hearing-impaired-flag 4:0 --visual-impaired-flag 4:0 --original-flag 4:0 --commentary-flag 4:0 \
--track-name 5:"Surround 5.1" --language 5:en --default-track 5:0 --forced-track 5:0 --hearing-impaired-flag 5:0 --visual-impaired-flag 5:0 --original-flag 5:0 --commentary-flag 5:0 \
--track-name 6:"Surround 5.1" --language 6:en --default-track 6:0 --forced-track 6:0 --hearing-impaired-flag 6:0 --visual-impaired-flag 6:0 --original-flag 6:0 --commentary-flag 6:0 \
--track-name 7:Stereo --language 7:und --default-track 7:0 --forced-track 7:0 --hearing-impaired-flag 7:0 --visual-impaired-flag 7:0 --original-flag 7:0 --commentary-flag 7:0 \
--track-name 8:Stereo --language 8:en --default-track 8:0 --forced-track 8:0 --hearing-impaired-flag 8:0 --visual-impaired-flag 8:0 --original-flag 8:0 --commentary-flag 8:0 \
--language 9:de --default-track 9:0 --forced-track 9:0 --hearing-impaired-flag 9:0 --visual-impaired-flag 9:0 --original-flag 9:0 --commentary-flag 9:0 \
--language 10:de --default-track 10:0 --forced-track 10:0 --hearing-impaired-flag 10:0 --visual-impaired-flag 10:0 --original-flag 10:0 --commentary-flag 10:0 \
--language 11:en --default-track 11:0 --forced-track 11:0 --hearing-impaired-flag 11:0 --visual-impaired-flag 11:0 --original-flag 11:0 --commentary-flag 11:0 \
--language 12:de --default-track 12:0 --forced-track 12:0 --hearing-impaired-flag 12:0 --visual-impaired-flag 12:0 --original-flag 12:0 --commentary-flag 12:0 \
"/home/user/file.mkv" --track-order 0:0,0:1,0:2,0:3,0:4,0:5,0:6,0:7,0:8,0:9,0:10,0:11,0:12

This processes the MKV file in a single pass, making it significantly faster.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants