Mark
/
celeste-ai
Archived
1
0
Fork 0

Cleaned up ffmpeg.sh

master
Mark 2023-02-26 15:12:56 -08:00
parent 072867a7a3
commit 05d745cc07
Signed by: Mark
GPG Key ID: AD62BB059C2AAEE4
1 changed files with 50 additions and 25 deletions

View File

@ -1,65 +1,90 @@
#!/bin/bash #!/bin/bash
# Where screenshots are saved # Where screenshots are saved.
# SC_ROOT/SC_DIR should contain episode screenshot directories
SC_ROOT="model_data/current" SC_ROOT="model_data/current"
SC_DIR="screenshots"
# WILL BE DELETED
# Select a temporary working directory
# if false, uses ramdisk.
# set to true if ramdisk overflows.
if false; then
OUTPUT_DIR="model_data/video_output" OUTPUT_DIR="model_data/video_output"
# 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
# To make with fade in and out: else
# ffmpeg -framerate 30 -i %03d.png -vf "scale=1024x1024:flags=neighbor,fade=in:0:45,fade=out:1040:45" out.webm OUTPUT_DIR=$(mktemp -d)
fi
render_dir () {
# 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 () {
ffmpeg \ ffmpeg \
-y \ -y \
-loglevel quiet \ -loglevel quiet \
-framerate 30 \ -framerate 30 \
-i $1/hackcel_%003d.png \ -i "$1/hackcel_%003d.png" \
-c:v libx264 \ -c:v libx264 \
-pix_fmt yuv420p \ -crf 20 \
$OUTPUT_DIR/${1##*/}.mp4 -preset slow \
-tune animation \
-vf "scale=1024x1024:flags=neighbor" \
"$2.mp4"
} }
# Todo: error out if exists
mkdir -p $OUTPUT_DIR
echo "Making episode files..." echo "Making episode files..."
for D in $SC_ROOT/screenshots/*; do for D in "$SC_ROOT/$SC_DIR"/*; do
if [ -d "${D}" ]; then if [ -d "${D}" ]; then
render_dir $D render_episode "$D" "$OUTPUT_DIR/${D##*/}"
fi fi
done done
echo "Done."
# Generate video for each run echo "Merging..."
for f in $OUTPUT_DIR/*.mp4; do for f in "$OUTPUT_DIR"/*.mp4; do
echo file \'$f\' >> video_merge_list echo file \'$f\' >> "$OUTPUT_DIR/video_merge_list"
done done
# Merge videos # Merge videos
ffmpeg \ ffmpeg \
-loglevel error -stats -y \ -loglevel error -stats -y \
-f concat \ -f concat \
-safe 0 \ -safe 0 \
-i video_merge_list \ -i "$OUTPUT_DIR/video_merge_list" \
-vf "scale=1024x1024:flags=neighbor" \ "$SC_ROOT/1x.mp4"
$SC_ROOT/1x.mp4 echo ""
echo "Making accelerated video..."
rm video_merge_list
# Make accelerated video # Make accelerated video
ffmpeg \ ffmpeg \
-loglevel error -stats -y \ -loglevel error -stats -y \
-i $SC_ROOT/1x.mp4 \ -i "$SC_ROOT/1x.mp4" \
-framerate 60 \ -framerate 60 \
-filter:v "setpts=0.125*PTS" \ -filter:v "setpts=0.125*PTS" \
$SC_ROOT/8x.mp4 "$SC_ROOT/8x.mp4"
echo "Cleaning up..."
echo "Cleaning up...."
rm -dr $OUTPUT_DIR rm -dr $OUTPUT_DIR