Skip to content

Commit

Permalink
experimental 21:9 support (#44)
Browse files Browse the repository at this point in the history
  • Loading branch information
chpoit authored Jul 27, 2022
1 parent 2f271b0 commit be8d1b1
Show file tree
Hide file tree
Showing 9 changed files with 71 additions and 31 deletions.
10 changes: 8 additions & 2 deletions PATCHNOTES.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
# Patch Notes
- 1.8 (July 27th 2022)
- Added experimental non 16:9 support
- Only tested with 21:9

# Older patch notes
- 1.7.1 (July 25th 2022)
- The updater now displays information from the latest update
- Fixed the download of new app language files not present in the executable, but present online.
- 1.7 (July 8th 2022)
- Added level 4 slot support (#35)
- Fixed restarting the app after setting a different game language (#34)
Expand All @@ -8,8 +16,6 @@
- You can now let the app remove black bars from videos
- It is experimental. You should fix your recordings first if it doesn't work
- Black bars can be caused by not setting your TV size to 100% in the switch settings.

# Older patch notes
- 1.6.2 (July 5th 2022)
- Fixed an issue with the creation of the config file
- `--reset` commandline option now takes into account `-a` and `-l`
Expand Down
18 changes: 5 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,10 @@ This repo contains code that will allow you to extract all of your charms in Mon

It's called Utsushi's charm because I thought it would be funny to make a complementary "Utsushi's Armor Search System", but [this armor set searcher](https://mhrise.wiki-db.com/sim/?hl=en) exists. I might still try to port Athena's ASS for MHW to MHR, but for now this works for me.

# Patch Notes (Updated July 25th 2022)
- 1.7.1
- The updater now displays information from the latest update
- Fixed the download of new app language files not present in the executable, but present online.
- 1.7 (July 8th 2022)
- Added level 4 slot support (#35)
- Fixed restarting the app after setting a different game language (#34)
- You can now ignore an update
- You can now add invalid skills (or skills that are not in the list, don't come to me if the builder doesn't work)
- You can record in windowed mode (See next point)
- You can now let the app remove black bars from videos
- It is experimental. You should fix your recordings first if it doesn't work
- Black bars can be caused by not setting your TV size to 100% in the switch settings.
# Patch Notes (Updated July 27th 2022)
- 1.8 (July 27th 2022)
- Added experimental non 16:9 support
- Only tested with 21:9

The rest of the patch notes can be found [here](PATCHNOTES.md)

Expand Down Expand Up @@ -125,6 +116,7 @@ Having translations for the instructions for other languages might be useful, bu
- Q: Does this Work for the PC version
- Yes. As long as your resolution is 720p or above, and has a 16:9 ratio, it should
- Basically, 1080p, 1440p, 4k and above should work without issues, albeit, the higher the resolution, the slower.
- Experimental non-16:9 support has been added in 1.8 (only tested with 21:9)
- Q: I'm trying to enter a skill in the Skill Correction thing and it doesn't work
- This might be because the PC version has a different name for the skill, add it to the corrections.lang.csv file, or tell me to do it.
- An example of this would be `Quick Sheath`, which is named `Quick Sheathe` on PC
Expand Down
5 changes: 3 additions & 2 deletions data/translations/chi_tra.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,5 +72,6 @@
"remove-black-bars": "刪除黑邊\n適用於視窗擷取",
"remove-black-bars-info": "應用程式會嘗試刪除黑邊。如果你在視窗模式下錄製影片,這也許會有幫助(此為實驗性功能)在你抱怨問題之前請請嘗試修復你的影片 :)",
"upd-ignore": "略過",
"add-as-is": "添加技能為"
}
"add-as-is": "添加技能為",
"non-16:9": "Non-16:9 video detected, attempting to crop"
}
3 changes: 2 additions & 1 deletion data/translations/eng.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,5 +72,6 @@
"remove-black-bars": "Remove black bars\nMay work with windowed capture",
"remove-black-bars-info": "The app will attempt to remove black bars.\nIt should work if you are recording in windowed mode.\nThis should be useful if your switch isn't properly scaled (TV Size setting).\nThis is 100% experimental (and somewhat random). Fix your videos before you complain :)",
"upd-ignore": "Ignore",
"add-as-is": "Add skill as-is"
"add-as-is": "Add skill as-is",
"non-16:9": "Non-16:9 video detected, attempting to crop"
}
3 changes: 2 additions & 1 deletion data/translations/fra.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,5 +72,6 @@
"remove-black-bars": "Retirer les barres noires\nDevrait marcher avec le mode fenêtre",
"remove-black-bars-info": "L'application va essayer d'enlever les barres noires autour du vidéo.\n¨Ça devrait aussi fonctionner si vous enregistrer le jeu en mode fenêtre.\nC'est utile lorsque vous n'avez pas configuré la taille de la TV pour la switch.\nC'est 100% expérimental et un peu aléatoire.\nEnregistrez les vidéos comme il faut avant de vous plaindre :)",
"upd-ignore": "Ignorer",
"add-as-is": "Ajouter tel quel"
"add-as-is": "Ajouter tel quel",
"non-16:9": "Vidéo n'ayant pas un format 16:9 détecté, tentative de correction..."
}
6 changes: 3 additions & 3 deletions data/versions.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@
"app": "1.7",
"skills": "3.1.1",
"languages": {
"eng": "1.2.1",
"eng": "1.4",
"jpn": 0,
"fra": "1.2.1",
"fra": "1.4",
"ita": 0,
"deu": 0,
"spa": 0,
"rus": 0,
"pol": 0,
"kor": 0,
"chi_tra": 1,
"chi_tra": "1.4",
"chi_sim": 0
},
"corrections": {
Expand Down
52 changes: 45 additions & 7 deletions src/frame_extraction.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,44 @@ def crop_frame(frame):
return cropped, charm_only


def resize_to_16_9(frame):
known_drops = [(1280, 720), (1920, 1080), (2560, 1440), (3840, 2160)]
height, width = frame.shape[:2]

ratio = round(width / height, 1)
if ratio != 1.7 and ratio != 1.8:
valid_drops = list(
filter(lambda x: x[0] <= width and x[1] <= height, known_drops)
)
best_drop = valid_drops[-1]

if height > best_drop[1]:
odd_ratio = height / best_drop[1]
tW = width / odd_ratio
frame = cv2.resize(frame, [round(tW), best_drop[1]])

height, width = frame.shape[:2]
wCrop = floor((width - best_drop[0]) / 2)
hCrop = floor((height - best_drop[1]) / 2)

x = wCrop
x2 = width - wCrop
y = hCrop
y2 = height - hCrop
frame = frame[y:y2, x:x2]

return frame


def resize_frame(frame):
height, width = frame.shape[:2]
if height != 720 or width != 1280:
frame = cv2.resize(frame, (1280, 720))
return frame


def crop_frames(capture_device, remove_black_bars):
for i, f in read_frames(capture_device, remove_black_bars):
def crop_frames(capture_device, remove_black_bars, _=lambda x: x):
for i, f in read_frames(capture_device, remove_black_bars, _):
yield i, crop_frame(f)


Expand All @@ -48,7 +77,6 @@ def detect_black_bars(frame):
y_pos_base = floor(height / 2)
prev_pixel = None

i = 0
top = 5
left = 5
right = 5
Expand Down Expand Up @@ -120,23 +148,33 @@ def crop_black_bars(frame, black_bars):
return frame[y:y2, x:x2]


def read_frames(capture_device, remove_black_bars=False):
def read_frames(capture_device, remove_black_bars=False, _=lambda x: x):
i = 0
fps = capture_device.get(cv2.CAP_PROP_FPS)
black_bars = None

while True:
ret, frame = capture_device.read()
if i == 0:
black_bars = detect_black_bars(frame)

if not ret:
break

height, width = frame.shape[:2]
ratio = round(width / height, 1)

if ratio != 1.7 and ratio != 1.8:
if i == 0:
print(_("non-16:9"))
frame = resize_to_16_9(frame)
if i == 0:
black_bars = detect_black_bars(frame)
if fps == 60 and (i % 2):
pass
else:
if remove_black_bars:
frame = crop_black_bars(frame, black_bars)
yield i, resize_frame(frame)

i += 1


Expand Down Expand Up @@ -194,7 +232,7 @@ def extract_unique_frames(

previous_charm_marker = None
with iter_wrapper(
crop_frames(cap, remove_black_bars),
crop_frames(cap, remove_black_bars, _),
total=frame_count,
desc=_("fn-total-charm").format(f_name, frame_count),
) as frame_pbar:
Expand Down
2 changes: 1 addition & 1 deletion src/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ def get_translation_location(language="eng", for_creation=False):
get_resource_path("LOCAL_TRANSLATIONS"), f"{language}.json"
)
os.makedirs(get_resource_path("LOCAL_TRANSLATIONS"), exist_ok=True)

if not os.path.isfile(local_file) and not for_creation:
lang_dir = get_resource_path("INTERNAL_TRANSLATIONS")
lang_file = os.path.join(lang_dir, f"{language}.json")
Expand Down
3 changes: 2 additions & 1 deletion src/updater/SimpleSemVer.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ class SimpleSemVer:
def __init__(self, version=None):
if not version:
version = 0
if type(version) not in (str, float, int):

if type(version) not in (str, float, int) and version is not SimpleSemVer:
raise TypeError(
"Invalid type used for SimpleSemVer, must be str, int or float"
)
Expand Down

0 comments on commit be8d1b1

Please sign in to comment.