AliceClass/script/script.sh

163 lines
4.5 KiB
Bash
Raw Normal View History

2024-05-23 01:23:48 -03:00
#!/bin/sh
SRC=collections/_aulas
2024-08-01 17:19:19 -03:00
# SCRIPT=script/
SCRIPT=/var/www/src/AliceClass/script/
# TMP=tmp
TMP=$(mktemp -d)
ASSETS="$TMP/assets"
2024-07-10 14:19:15 -03:00
PARAM="scale=1920:1080: force_original_aspect_ratio=decrease: eval=frame,pad=1920:1080: -1:-1:color=black"
2024-12-18 15:27:54 -03:00
VIDEOS_PATH=/var/www/html/aliceclass_videos
create_thumb () {
THUMB_PATH=$1
SRC_FILE=$2
if test ! -f "${THUMB_PATH}" ; then
ffmpeg -y -i "${SRC_FILE}" -vframes 1 -an -s 400x222 -ss 30 "${THUMB_PATH}"
fi
}
create_intro_clip () {
AUTHOR=$1
VIDEO_TITLE=$2
# sed "s/nomenome/$AUTHOR/g" ${SCRIPT}/intro.svg | sed "s/curso/${VIDEO_TITLE}/g" > ${TMP}/tmp-intro.svg
sed "s/nomenome/$AUTHOR/g; s/curso/${VIDEO_TITLE}/g" ${SCRIPT}/intro.svg > ${TMP}/tmp-intro.svg
ffmpeg -y -loop 1 -i ${TMP}/tmp-intro.svg -i ${SCRIPT}/intro.wav -shortest ${TMP}/tmp-intro.mkv
}
2024-07-10 14:19:15 -03:00
2024-08-01 17:19:19 -03:00
process_video () {
2024-12-18 15:27:54 -03:00
# VIDEO_TITLE=$1
# USERNAME=$2
# SRC_FILE=$3
# AULA=$4
# DEST_FILE=$5
VIDEO_TITLE=$1
2024-08-01 17:19:19 -03:00
AUTHOR=$2
2024-12-18 15:27:54 -03:00
SRC_FILE=$3
2024-08-01 17:19:19 -03:00
AULA=$4
2024-12-18 15:27:54 -03:00
DEST_FILE=$5
2024-05-23 01:23:48 -03:00
2024-08-01 17:19:19 -03:00
# no output path
2024-12-18 15:27:54 -03:00
if [ -z "$DEST_FILE" ]; then
DEST_FILE="$ASSETS/videos/${VIDEO_TITLE}.mp4"
2024-08-01 17:19:19 -03:00
fi
2024-05-23 01:23:48 -03:00
2024-12-18 15:27:54 -03:00
THUMB_PATH="${VIDEOS_PATH}/$AUTHOR/thumbs/${VIDEO_TITLE}.jpg"
# THUMB_PATH=$(dirname $(dirname $DEST_FILE))/thumbs/${VIDEO_TITLE}.jpg
2024-05-23 01:23:48 -03:00
echo "########################################"
2024-08-01 17:19:19 -03:00
echo "# Aula: ${AULA}"
2024-12-18 15:27:54 -03:00
echo "# Thumb Path: $THUMB_PATH"
2024-05-23 01:23:48 -03:00
echo "# Author: ${AUTHOR}"
2024-12-18 15:27:54 -03:00
echo "# Input: ${SRC_FILE}"
2024-05-23 01:23:48 -03:00
echo "# Src: ${SRC}"
2024-12-18 15:27:54 -03:00
echo "# Dest: ${DEST_FILE}"
echo "# Name: ${VIDEO_TITLE}"
2024-05-23 01:23:48 -03:00
echo "# Script Path: ${SCRIPT}"
echo "########################################"
2024-08-01 17:19:19 -03:00
# exit
2024-05-23 01:23:48 -03:00
2024-12-18 15:27:54 -03:00
2024-05-23 01:23:48 -03:00
# ####################################
# Creating the thumbnail if does not exist
# ####################################
2024-12-18 15:27:54 -03:00
create_thumb "${THUMB_PATH}" "${SRC_FILE}"
2024-05-23 01:23:48 -03:00
# ####################################
# if output exist, continue
# ####################################
2024-12-18 15:27:54 -03:00
if test -f "$ASSETS/videos/${VIDEO_TITLE}.mp4" ; then
2024-05-23 01:23:48 -03:00
continue
fi
# ####################################
# Creating the intro clip
# ####################################
2024-12-18 15:27:54 -03:00
create_intro_clip "${AUTHOR}" "${VIDEO_TITLE}"
2024-05-23 01:23:48 -03:00
# ###################################################
# Audio adjustment
# ###################################################
# Some possible options
# -af loudnorm
# -af dynaudnorm=p=1
# -af speechnorm=e=12.5:r=0.0001:l=1
# -af acompressor=threshold=0.089:ratio=9:attack=200:release=1000:makeup=2
2024-12-18 15:27:54 -03:00
ffmpeg -y -i "${SRC_FILE}" -af dynaudnorm=p=1 ${TMP}/tmp-normalized.mkv
2024-05-23 01:23:48 -03:00
# ####################################################
# Wartermarking the video file
# ####################################################
2024-12-18 15:27:54 -03:00
sed "s/nomenome/$AUTHOR/g" ${SCRIPT}/watermark.svg | sed "s/curso/${VIDEO_TITLE}/g" > ${TMP}/tmp-watermark.svg
2024-05-23 01:23:48 -03:00
# add watermark to video
2024-07-10 14:19:15 -03:00
ffmpeg -y -i ${TMP}/tmp-normalized.mkv -i ${TMP}/tmp-watermark.svg -i ${SCRIPT}/logo.png \
-filter_complex "[0][1]overlay=5:H-h-5:format=auto[bg];[bg][2]overlay=W-w-5:5:format=auto" -c:a copy ${TMP}/tmp-video.mkv
2024-05-23 01:23:48 -03:00
# ####################################################
# Concatenating videos
# ####################################################
2024-07-10 17:27:31 -03:00
echo "Concatenando videos..."
2024-05-23 01:23:48 -03:00
ffmpeg -y \
2024-07-10 14:19:15 -03:00
-i ${TMP}/tmp-intro.mkv \
-i ${TMP}/tmp-video.mkv \
-i ${TMP}/tmp-credits.mkv \
2024-05-23 01:23:48 -03:00
-filter_complex \
"[0:v]$PARAM[v0]; [1:v]$PARAM[v1]; [2:v]$PARAM[v2]; [v0][0:a][v1][1:a][v2][2:a] concat=n=3:v=1:a=1 [v] [a]" \
-map [v] -map [a] \
-s hd720 \
-vcodec libx264 \
-pix_fmt yuv420p \
-vsync 2 \
2024-12-18 15:27:54 -03:00
"$DEST_FILE"
2024-08-01 17:19:19 -03:00
}
# mkdir -p ./${TMP}
# ####################################
# Creating the credits clip
# ####################################
2024-12-18 15:27:54 -03:00
if test ${TMP}/tmp-credits.mkv -ot ${SCRIPT}/credits.svg ; then
2024-08-01 17:19:19 -03:00
echo "########################################"
echo "# Gerando o tmp-credits.mkv"
echo "########################################"
ffmpeg -y -loop 1 -i ${SCRIPT}/credits.svg -i ${SCRIPT}/credits.wav -shortest ${TMP}/tmp-credits.mkv
2024-12-18 15:27:54 -03:00
fi
2024-08-01 17:19:19 -03:00
# ####################################
# Creating dest dir
# ####################################
mkdir -p $ASSETS/thumbs
mkdir -p $ASSETS/videos
if [ $# -gt 1 ]; then
2024-12-18 15:27:54 -03:00
VIDEO_TITLE=$1
2024-08-01 17:19:19 -03:00
AUTHOR=$2
2024-12-18 15:27:54 -03:00
SRC_FILE=$3
2024-08-01 17:19:19 -03:00
AULA=$4
2024-12-18 15:27:54 -03:00
DEST_FILE=$5
process_video "$VIDEO_TITLE" "$AUTHOR" "$SRC_FILE" "$AULA" "$DEST_FILE"
2024-08-01 17:19:19 -03:00
exit
fi
# for aula in ./${SRC}/*.md; do
# # ####################################
# # Getting parameters from aulas
# # ####################################
2024-12-18 15:27:54 -03:00
# VIDEO_TITLE="$(basename "${aula}" .md)"
2024-08-01 17:19:19 -03:00
# AUTHOR=$(grep "^author: " "${aula}" | sed -e 's/author: //g')
2024-12-18 15:27:54 -03:00
# SRC_FILE="${SRC}/${VIDEO_TITLE}.mkv"
2024-08-01 17:19:19 -03:00
#
2024-12-18 15:27:54 -03:00
# process_video "$VIDEO_TITLE" "$AUTHOR" "$SRC_FILE"
2024-08-01 17:19:19 -03:00
# done
2024-05-23 01:23:48 -03:00
2024-08-01 17:19:19 -03:00
# rm -f ${TMP}