Added tools for converting to YandereLewdBot
This commit is contained in:
parent
db081f8bb2
commit
418f1bc436
65
tools/convert.py
Executable file
65
tools/convert.py
Executable file
@ -0,0 +1,65 @@
|
|||||||
|
#! /usr/bin/env python3
|
||||||
|
|
||||||
|
import sys
|
||||||
|
import importlib
|
||||||
|
import os
|
||||||
|
import argparse
|
||||||
|
|
||||||
|
def get_modded_range(ranges, endseconds, fps, endframe):
|
||||||
|
d = []
|
||||||
|
multiply_factor = endframe / (fps * endseconds)
|
||||||
|
for i in ranges:
|
||||||
|
begin = int(i[0] * multiply_factor)
|
||||||
|
end = int(i[1] * multiply_factor)
|
||||||
|
d.append((begin, end))
|
||||||
|
return d
|
||||||
|
|
||||||
|
def is_in_range(ranges, frame):
|
||||||
|
for i in ranges:
|
||||||
|
if frame in range(i[0], i[1] + 1):
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
|
def main():
|
||||||
|
DEFAULT_CFG="cfg"
|
||||||
|
DEFAULT_FPS=24
|
||||||
|
|
||||||
|
# Parser
|
||||||
|
parser = argparse.ArgumentParser(
|
||||||
|
description="CLI tool to help convert time to frames. MiraiNikkiFrameBot is being depricated in favor of pre-rendered frames posted using YandereLewdBot",
|
||||||
|
epilog="See YandereLewdBot for examples on how to post frames.",
|
||||||
|
add_help=True)
|
||||||
|
parser.add_argument("-c", "--config", help="Set custom config file (Default: {})".format(DEFAULT_CFG))
|
||||||
|
parser.add_argument("-f", "--fps", help="Set fps manually (Default: {})".format(str(DEFAULT_FPS)), type=int, default=DEFAULT_FPS)
|
||||||
|
parser.add_argument("-r", "--ranges", help="Show time ranges of skip and nsfw converted into frames and exit", action="store_true")
|
||||||
|
parser.add_argument("profile", help="The index of settings_post to operate on", type=int)
|
||||||
|
parser.add_argument("endframe", help="The final frame count of the new pre-rendered frames", type=int)
|
||||||
|
arguments = parser.parse_args()
|
||||||
|
|
||||||
|
cfg = importlib.import_module(arguments.config)
|
||||||
|
|
||||||
|
settings_post = cfg.settings_post[arguments.profile]
|
||||||
|
setting_skip = get_modded_range(settings_post["skip"], settings_post["frames"], arguments.fps, arguments.endframe)
|
||||||
|
setting_nsfw = get_modded_range(settings_post["nsfw"], settings_post["frames"], arguments.fps, arguments.endframe)
|
||||||
|
|
||||||
|
if arguments.ranges:
|
||||||
|
print("Settings Skip:")
|
||||||
|
print(setting_skip)
|
||||||
|
print("Settings NSFW:")
|
||||||
|
print(setting_nsfw)
|
||||||
|
return 0
|
||||||
|
|
||||||
|
print(settings_post["profile_name"])
|
||||||
|
for i in range(1, arguments.endframe + 1):
|
||||||
|
status = "safe"
|
||||||
|
frame_name = os.path.basename(settings_post["output_name"].replace("${frame}", str(i).zfill(5)))
|
||||||
|
if is_in_range(setting_skip, i):
|
||||||
|
status = "skip"
|
||||||
|
elif is_in_range(setting_nsfw, i):
|
||||||
|
status = "nsfw"
|
||||||
|
print("mv -nv '{}' '{}'".format(str(frame_name), "{}/".format(status)))
|
||||||
|
|
||||||
|
return 0
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
sys.exit(main())
|
64
tools/notes.md
Normal file
64
tools/notes.md
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
# Notes
|
||||||
|
These notes will detail how to switch from MiraiNikkiBot to YandereLewdBot.
|
||||||
|
|
||||||
|
This bot is being depreciated because it is largely redundant to YandereLewdBot.
|
||||||
|
|
||||||
|
Pre-rendering the frames using ffmpeg and using cli tools can achieve the same effect.
|
||||||
|
|
||||||
|
[YandereLewdBot can be downloaded here.](https://git.yandere.cc/Anon/YandereLewdBot)
|
||||||
|
|
||||||
|
## Pre-rendering the Frames
|
||||||
|
Pre-render the frames with ffmpeg using the following commands:
|
||||||
|
|
||||||
|
## FFMPEG
|
||||||
|
Use ffprobe -i input.mkv to get the fps. If the video is 60 fps, set -r to 60/1. If it is 24 fps, use 24/1.
|
||||||
|
|
||||||
|
For videos with subtitles
|
||||||
|
```
|
||||||
|
ffmpeg -i 'input.mkv' -q:v 1 -vf subtitles=input.mkv -r 24/1 'jpg/HappySugarLife_EP01_%05d.jpg'
|
||||||
|
```
|
||||||
|
|
||||||
|
For videos without subtitles
|
||||||
|
```
|
||||||
|
ffmpeg -i 'input.mkv' -q:v 1 -r 24/1 'jpg/HappySugarLife_EP01_%05d.jpg'
|
||||||
|
```
|
||||||
|
|
||||||
|
## MPV with Imagemagick
|
||||||
|
For dvdsubs that cannot be rendered with ffmpeg use the following commands that utilize mpv with imagemagick.
|
||||||
|
|
||||||
|
This will render png's with mpv, then convert them to jpg using imagemagick.
|
||||||
|
|
||||||
|
```
|
||||||
|
mkdir {png,jpg}
|
||||||
|
mpv --pause --no-audio --framedrop=no --screenshot-format=png --screenshot-png-compression=0 --screenshot-template=png/Future_Diary_EP"${1}"_%05n --sid=1 --input-ipc-server=${HOME}/.config/mpv/socket input.mkv &
|
||||||
|
echo 'screenshot subtitles+each-frame ; set pause no' | socat - /home/anon/.config/mpv/socket
|
||||||
|
wait
|
||||||
|
while IFS= read -r line;do echo convert -quality 95 "/home/anon/sshfs/${line}" "/media/anon/luks-13058f5c-674c-41da-82b9-2d6d9c1b9787/mov/FutureDiary/jpg/fd${1}/${line%.*}.jpg";done < <(ls -1 png/) | parallel
|
||||||
|
```
|
||||||
|
|
||||||
|
## Converting cfg Files
|
||||||
|
Copy the convert.py into src/convert.py (the same folder with your existing config files).
|
||||||
|
|
||||||
|
You will need to make note of the last frame rendered by the above commands, as well as the fps of each episode.
|
||||||
|
|
||||||
|
Use `./convert.py -h` to see the usage information.
|
||||||
|
|
||||||
|
Typical usage of the command:
|
||||||
|
-c cfg is the config file (minus the .py extension)
|
||||||
|
-f 24 means the video is 24 fps
|
||||||
|
0 means profile index 0
|
||||||
|
32000 is the last frame rendered
|
||||||
|
```
|
||||||
|
./convert -c cfg -f 24 0 32000
|
||||||
|
```
|
||||||
|
This will output sh move commands you can use to sort into safe, nsfw, and skip folders assuming you are in the correct working directory.
|
||||||
|
|
||||||
|
You can also pipe this into the shell of your choice to execute the commands.
|
||||||
|
```
|
||||||
|
./convert -c cfg -f 24 0 32000 | sh
|
||||||
|
```
|
||||||
|
## Generate the Master List
|
||||||
|
Finally, you can generate the master list for usage in YandereLewdBot.
|
||||||
|
```
|
||||||
|
find ./png/ -type f -print | grep -Fv '/skip/' | sort > master_list.txt
|
||||||
|
```
|
Reference in New Issue
Block a user