Mark
/
celeste-ai
Archived
1
0
Fork 0
This repository has been archived on 2023-11-28. You can view files and clone it, but cannot push or open issues/pull-requests.
celeste-ai/celeste/ffmpeg.sh

91 lines
1.6 KiB
Bash
Raw Normal View History

2023-02-17 22:28:41 -08:00
#!/bin/bash
2023-02-24 14:11:56 -08:00
2023-02-26 15:12:56 -08:00
# Where screenshots are saved.
# SC_ROOT/SC_DIR should contain episode screenshot directories
2023-02-24 14:11:56 -08:00
SC_ROOT="model_data/current"
2023-02-26 15:12:56 -08:00
SC_DIR="screenshots"
2023-02-18 19:50:31 -08:00
2023-02-24 14:11:56 -08:00
2023-02-26 15:12:56 -08:00
# Select a temporary working directory
# if false, uses ramdisk.
# set to true if ramdisk overflows.
if false; then
OUTPUT_DIR="model_data/video_output"
2023-02-24 14:11:56 -08:00
2023-02-26 15:12:56 -08:00
# This directory will be deleted.
# Make sure it doesn't already exist.
if [ -e "$OUTPUT_DIR" ]; then
echo "$OUTPUT_DIR exists, exiting. Please delete it manually."
exit 1
fi
mkdir -p $OUTPUT_DIR
else
OUTPUT_DIR=$(mktemp -d)
fi
2023-02-17 22:28:41 -08:00
2023-02-26 15:12:56 -08:00
# Usage:
# render_episode <src_dir> <output_name>
#
# Turns a directory of frame screenshots into a video.
# Applies upscaling. We do it early, because upscaling
# after encoding will exaggerate artifacts.
render_episode () {
2023-02-17 22:28:41 -08:00
ffmpeg \
-y \
-loglevel quiet \
-framerate 30 \
2023-02-26 15:12:56 -08:00
-i "$1/hackcel_%003d.png" \
2023-02-17 22:28:41 -08:00
-c:v libx264 \
2023-02-26 15:12:56 -08:00
-crf 20 \
-preset slow \
-tune animation \
-vf "scale=1024x1024:flags=neighbor" \
"$2.mp4"
2023-02-17 22:28:41 -08:00
}
2023-02-18 21:09:53 -08:00
2023-02-17 22:28:41 -08:00
echo "Making episode files..."
2023-02-26 15:12:56 -08:00
for D in "$SC_ROOT/$SC_DIR"/*; do
2023-02-17 22:28:41 -08:00
if [ -d "${D}" ]; then
2023-02-26 15:12:56 -08:00
render_episode "$D" "$OUTPUT_DIR/${D##*/}"
2023-02-17 22:28:41 -08:00
fi
done
2023-02-26 15:12:56 -08:00
echo "Merging..."
for f in "$OUTPUT_DIR"/*.mp4; do
echo file \'$f\' >> "$OUTPUT_DIR/video_merge_list"
2023-02-17 22:28:41 -08:00
done
2023-02-26 15:12:56 -08:00
2023-02-17 22:28:41 -08:00
# Merge videos
ffmpeg \
2023-02-18 21:09:53 -08:00
-loglevel error -stats -y \
2023-02-17 22:28:41 -08:00
-f concat \
-safe 0 \
2023-02-26 15:12:56 -08:00
-i "$OUTPUT_DIR/video_merge_list" \
"$SC_ROOT/1x.mp4"
echo ""
echo "Making accelerated video..."
2023-02-17 22:28:41 -08:00
# Make accelerated video
ffmpeg \
2023-02-18 21:09:53 -08:00
-loglevel error -stats -y \
2023-02-26 15:12:56 -08:00
-i "$SC_ROOT/1x.mp4" \
2023-02-18 21:09:53 -08:00
-framerate 60 \
2023-02-17 22:28:41 -08:00
-filter:v "setpts=0.125*PTS" \
2023-02-26 15:12:56 -08:00
"$SC_ROOT/8x.mp4"
2023-02-17 22:28:41 -08:00
2023-02-24 17:46:33 -08:00
2023-02-26 15:12:56 -08:00
echo "Cleaning up...."
2023-02-18 19:50:31 -08:00
rm -dr $OUTPUT_DIR