#!/usr/bin/env bash set -euxo pipefail # License MIT # Authors 2024 # thunfisch # iiidefix # l3d # This script is designed to help you automatically select the correct intro # and outro files (prerendered with built-in fades) and the correct chunks # of a chunked recording (e.g. OBS with automatic split every 5 minutes). # It will open the first and last chunk in mpv if you want, so that you # can find the start and end points (in seconds), you manually need to transfer # them into the script for now (no idea how to convince mpv to output it). # After that the script will render the introfile with the first chunk and the # last chunk with the outrofile, and then in the last step assemble everything # into the final recording with audio normalization. # This script requires you to have ffmpeg and fzf installed. which ffmpeg >/dev/null || (echo "Please install ffmpeg" ; exit 1) which fzf >/dev/null || (echo "Please install fzf" ; exit 1) which mpv >/dev/null || (echo "Please install mpv" ; exit 1) INTROS_PATH="/Users/j/dhcp24_voc_files/intros" OUTROS_PATH="/Users/j/dhcp24_voc_files/outros" CHUNKS_PATH="/Users/j/voc_obs/obs_record" OUTPUT_PATH="/Users/j/voc_obs/obs_record/rendered" # Select the appropriate files SELECTED_INTRO="$(find "$INTROS_PATH" -type f | sort --reverse --human-numeric-sort | fzf --delimiter / --with-nth -1 --prompt "Intro File:")" SELECTED_OUTRO="$(find "$OUTROS_PATH" -type f | sort --reverse --human-numeric-sort | fzf --delimiter / --with-nth -1 --prompt "Outro File:")" SELECTED_CHUNKS="$(find "$CHUNKS_PATH" -type f | sort --reverse | fzf --delimiter / --with-nth -1 -m --prompt "Video Chunks (use tab to select multiple):" | sort )" readarray -t CHUNKS_ARRAY < <(echo "$SELECTED_CHUNKS") FOOBARWTF="$(basename "$SELECTED_INTRO")" DEFAULT_OUTPUT_NAME="${FOOBARWTF%.*}" read -p "Please enter a name for the outputfile (path and extension will be added automatically): " -i "$DEFAULT_OUTPUT_NAME" -e OUTPUT_NAME # find the start-offset for the first chunk read -p "Do you want to play the first chunk ${CHUNKS_ARRAY[0]} to find the start-offset? (y/n) [n]: " PLAY_FIRST_CHUNK PLAY_FIRST_CHUNK="${PLAY_FIRST_CHUNK:-n}" [[ "$PLAY_FIRST_CHUNK" == "y" ]] && mpv "${CHUNKS_ARRAY[0]}" --osd-level=3 --osd-status-msg='${=time-pos}' --really-quiet read -p "Enter the start-offset in seconds for the first chunk ${CHUNKS_ARRAY[0]} [0]: " START_OFFSET START_OFFSET="${START_OFFSET:-0}" # find the end-offset for the last chunk read -p "Do you want to play the last chunk ${CHUNKS_ARRAY[-1]} to find the end-offset? (y/n) [n]: " PLAY_LAST_CHUNK PLAY_LAST_CHUNK="${PLAY_LAST_CHUNK:-n}" [[ "$PLAY_LAST_CHUNK" == "y" ]] && mpv "${CHUNKS_ARRAY[-1]}" --osd-level=3 --osd-status-msg='${=time-pos}' --really-quiet read -p "Enter the end-offset in seconds for the last chunk ${CHUNKS_ARRAY[0]} [1]: " END_OFFSET END_OFFSET="${END_OFFSET:-1}" cat < "$CHUNKLIST" FFMPEG_CONCAT_CHUNKS="" if [[ ${ARRAY_LENGTH} -gt 2 ]] then for index in $(seq 1 $(( ${ARRAY_LENGTH} - 2 )) ) do FFMPEG_CONCAT_CHUNKS="${FFMPEG_CONCAT_CHUNKS}|${CHUNKS_ARRAY[index]}" echo "file '${CHUNKS_ARRAY[index]}'" >> "$CHUNKLIST" done fi echo "file '${WORKDIR}/outrocombined.mkv'" >> "$CHUNKLIST" ffmpeg \ -f concat -safe 0 -i "$CHUNKLIST" \ -af dynaudnorm \ -c:v copy \ -c:a aac -b:a 192k \ -metadata:s:a:0 language=native \ "${OUTPUT_PATH}/${OUTPUT_NAME}.mkv"