From be8d1b123de2e2cd44d3c18da6b42eb62ba24b32 Mon Sep 17 00:00:00 2001 From: Charles Poitras Date: Wed, 27 Jul 2022 16:27:44 -0700 Subject: [PATCH] experimental 21:9 support (#44) --- PATCHNOTES.md | 10 +++++-- README.md | 18 ++++-------- data/translations/chi_tra.json | 5 ++-- data/translations/eng.json | 3 +- data/translations/fra.json | 3 +- data/versions.json | 6 ++-- src/frame_extraction.py | 52 +++++++++++++++++++++++++++++----- src/resources.py | 2 +- src/updater/SimpleSemVer.py | 3 +- 9 files changed, 71 insertions(+), 31 deletions(-) diff --git a/PATCHNOTES.md b/PATCHNOTES.md index 629e11e..8983fe6 100644 --- a/PATCHNOTES.md +++ b/PATCHNOTES.md @@ -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) @@ -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` diff --git a/README.md b/README.md index 5299b9c..117a688 100644 --- a/README.md +++ b/README.md @@ -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) @@ -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 diff --git a/data/translations/chi_tra.json b/data/translations/chi_tra.json index 00b371f..e7c6098 100644 --- a/data/translations/chi_tra.json +++ b/data/translations/chi_tra.json @@ -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" +} \ No newline at end of file diff --git a/data/translations/eng.json b/data/translations/eng.json index f8d412e..109c0fb 100644 --- a/data/translations/eng.json +++ b/data/translations/eng.json @@ -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" } \ No newline at end of file diff --git a/data/translations/fra.json b/data/translations/fra.json index 1265ca9..cac9b99 100644 --- a/data/translations/fra.json +++ b/data/translations/fra.json @@ -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..." } \ No newline at end of file diff --git a/data/versions.json b/data/versions.json index 9395ef0..5601e1c 100644 --- a/data/versions.json +++ b/data/versions.json @@ -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": { diff --git a/src/frame_extraction.py b/src/frame_extraction.py index 202b20c..5bd2dc0 100644 --- a/src/frame_extraction.py +++ b/src/frame_extraction.py @@ -24,6 +24,35 @@ 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: @@ -31,8 +60,8 @@ def resize_frame(frame): 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) @@ -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 @@ -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 @@ -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: diff --git a/src/resources.py b/src/resources.py index 6c5dc63..5a81e7d 100644 --- a/src/resources.py +++ b/src/resources.py @@ -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") diff --git a/src/updater/SimpleSemVer.py b/src/updater/SimpleSemVer.py index fda1985..40d40a0 100644 --- a/src/updater/SimpleSemVer.py +++ b/src/updater/SimpleSemVer.py @@ -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" )