Cleaned up ffmpeg.sh
parent
072867a7a3
commit
05d745cc07
|
@ -1,65 +1,90 @@
|
|||
#!/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_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"
|
||||
|
||||
# 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:
|
||||
# ffmpeg -framerate 30 -i %03d.png -vf "scale=1024x1024:flags=neighbor,fade=in:0:45,fade=out:1040:45" out.webm
|
||||
else
|
||||
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 \
|
||||
-y \
|
||||
-loglevel quiet \
|
||||
-framerate 30 \
|
||||
-i $1/hackcel_%003d.png \
|
||||
-i "$1/hackcel_%003d.png" \
|
||||
-c:v libx264 \
|
||||
-pix_fmt yuv420p \
|
||||
$OUTPUT_DIR/${1##*/}.mp4
|
||||
-crf 20 \
|
||||
-preset slow \
|
||||
-tune animation \
|
||||
-vf "scale=1024x1024:flags=neighbor" \
|
||||
"$2.mp4"
|
||||
}
|
||||
|
||||
# Todo: error out if exists
|
||||
mkdir -p $OUTPUT_DIR
|
||||
|
||||
|
||||
echo "Making episode files..."
|
||||
for D in $SC_ROOT/screenshots/*; do
|
||||
for D in "$SC_ROOT/$SC_DIR"/*; do
|
||||
if [ -d "${D}" ]; then
|
||||
render_dir $D
|
||||
render_episode "$D" "$OUTPUT_DIR/${D##*/}"
|
||||
fi
|
||||
done
|
||||
|
||||
echo "Done."
|
||||
|
||||
|
||||
# Generate video for each run
|
||||
for f in $OUTPUT_DIR/*.mp4; do
|
||||
echo file \'$f\' >> video_merge_list
|
||||
echo "Merging..."
|
||||
for f in "$OUTPUT_DIR"/*.mp4; do
|
||||
echo file \'$f\' >> "$OUTPUT_DIR/video_merge_list"
|
||||
done
|
||||
|
||||
|
||||
|
||||
# Merge videos
|
||||
ffmpeg \
|
||||
-loglevel error -stats -y \
|
||||
-f concat \
|
||||
-safe 0 \
|
||||
-i video_merge_list \
|
||||
-vf "scale=1024x1024:flags=neighbor" \
|
||||
$SC_ROOT/1x.mp4
|
||||
-i "$OUTPUT_DIR/video_merge_list" \
|
||||
"$SC_ROOT/1x.mp4"
|
||||
echo ""
|
||||
echo "Making accelerated video..."
|
||||
|
||||
|
||||
rm video_merge_list
|
||||
|
||||
# Make accelerated video
|
||||
ffmpeg \
|
||||
-loglevel error -stats -y \
|
||||
-i $SC_ROOT/1x.mp4 \
|
||||
-i "$SC_ROOT/1x.mp4" \
|
||||
-framerate 60 \
|
||||
-filter:v "setpts=0.125*PTS" \
|
||||
$SC_ROOT/8x.mp4
|
||||
"$SC_ROOT/8x.mp4"
|
||||
|
||||
echo "Cleaning up..."
|
||||
|
||||
|
||||
echo "Cleaning up...."
|
||||
rm -dr $OUTPUT_DIR
|
||||
|
|
Reference in New Issue