This repository has been archived on 2024-02-26. You can view files and clone it, but cannot push or open issues or pull requests.
MiraiNikkiBot/render/render_mirai_nikki_script.sh

52 lines
1.7 KiB
Bash
Executable File

#! /usr/bin/env sh
# Mirai Nikki Bot a video frame posting bot for Pleroma
# Copyright (C) 2022 Anon
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
# ISSUES:
# - https://github.com/mpv-player/mpv/issues/5498
# MPV has an issue when outputting to jpg.
# Colors look washed out and faded compared to png screenshots.
# As a workaround this script will output to png then convert to jpg.
#
# - https://trac.ffmpeg.org/ticket/2391
# I want to just use ffmpeg for this script, however it
# does not support dvd subtitles. For now, I have to
# rely on mpv to render dvdsubs correctly :(
# TODO:
# - Tidy up this script and add some safety checks
# - Add some logic to the bot to detect if this script failed
# - Research more mpv options to avoid having to use mpv + convert
# Requiered args supplied by the bot
INPUT_PATH="$1"
OUTPUT_PATH="$2"
PICKED_FRAME="$3"
PNG_PATH="${OUTPUT_PATH%.*}.png"
echo "$INPUT_PATH"
echo "$OUTPUT_PATH"
echo "$PICKED_FRAME"
mkdir -p "$(dirname "$OUTPUT_PATH")"
mpv "$INPUT_PATH" --sid=1 "--start=${PICKED_FRAME}" --frames=1 -o "$PNG_PATH"
convert -quality 95 "$PNG_PATH" "$OUTPUT_PATH"
rm -fv "$PNG_PATH"