Skip to content

Instantly share code, notes, and snippets.

@rlaphoenix
Last active January 31, 2023 05:07
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rlaphoenix/c2547539f6b35aa7dd33714c43813150 to your computer and use it in GitHub Desktop.
Save rlaphoenix/c2547539f6b35aa7dd33714c43813150 to your computer and use it in GitHub Desktop.
Script to REMUX UMD Video Streams. Needs to have demuxed the MPS using VGMToolbox before running this script
import os
import re
import glob
import subprocess
# ==== #
# Important:
# For this script to work, you need to demux the MPS files FIRST
# How?
# Download the header.bin file (see top first comment below).
# Prepend it to all MPS files with the result being a PMF file
# - windows: `copy /b header.bin+file.MPS out.PMF`
# - linux/mac: `cat header.bin file.MPS > out.PMF`
# Now, get vgmtoolbox, Misc -> Stream Tools -> Video Demultiplexer
# Change the format dropdown to PMF, ensure it extracts Audio and Video and that "Add Header to Output" is ticked.
# Drag and drop all your prepared PMF files into this Demultiplexer
# Finally, run the code below with "Input" variable being the folder path where the demultiplexed PMF is located
Input = "/run/media/phoenix/emby-4-sea/discs/umd/Family Guy/Family.Guy.Volume.One.USA.NTSC.5xUMD.AVC.AT3.2.0/Disc 2/UMD_VIDEO/STREAM/"
# --- #
for sub_file in glob.glob(os.path.join(Input, "*.subs")):
Output = os.path.join(os.path.dirname(sub_file), os.path.splitext(os.path.basename(sub_file))[0])
os.makedirs(Output, exist_ok=True)
store = None
data_stream = None
with open(sub_file, "rb") as f:
data_stream = f.read()
matches = re.findall(b"\x89\x50\x4E\x47.+?\x49\x45\x4E\x44", data_stream, re.DOTALL)
for i, match in enumerate(matches):
print("PNG found, saving...")
with open(os.path.join(Output, "%s.png" % i), "wb") as f:
f.write(match)
print("Done %s" % os.path.basename(sub_file))
for oma_file in glob.glob(os.path.join(Input, "*.oma")):
subprocess.call([
"ffmpeg", "-i", oma_file, os.path.join(os.path.dirname(oma_file), os.path.splitext(os.path.basename(oma_file))[0] + ".ac3")
])
for h264_file in glob.glob(os.path.join(Input, "*.264")):
args = [
"mkvmerge",
"-o", os.path.join(os.path.dirname(h264_file), os.path.splitext(os.path.basename(h264_file))[0] + ".mkv"),
h264_file
]
args.extend(glob.glob(os.path.join(Input, "%s_*.ac3" % os.path.basename(h264_file).split("_")[0])))
subprocess.call(args)
@rlaphoenix
Copy link
Author

rlaphoenix commented Jan 6, 2021

header.bin download:
header.bin (right click me -> save as -> filename of header.bin, no .png)

Original source of this header bin file links back as far as MPSTOPMF tool from Quickjump forums.

@rlaphoenix
Copy link
Author

rlaphoenix commented Jan 31, 2021

TODO:

  • Proper Subtitles extraction and remuxing to MKV. The files tend to return slightly corrupted here and there. They are image-based seemingly VobSub or at least like it.
  • Figure out where chapters/scenes are stored.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment