forked from cwtv/stuff
				
			now with fast codec-copy and output filename selection. not cleaned up, but it works
This commit is contained in:
		
							parent
							
								
									8ddcd251e9
								
							
						
					
					
						commit
						e1d6631e9b
					
				| 
						 | 
				
			
			@ -1,6 +1,12 @@
 | 
			
		|||
#!/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).
 | 
			
		||||
| 
						 | 
				
			
			@ -9,10 +15,7 @@ set -euxo pipefail
 | 
			
		|||
# 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. The final version should
 | 
			
		||||
# try to use -c:v copy in the last step, so that no re-encoding of the chunks
 | 
			
		||||
# in the middle will be done. This does not work yet, so please excuse the slow
 | 
			
		||||
# rendering. Upcoming version hopefully fixes it.
 | 
			
		||||
# 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)
 | 
			
		||||
| 
						 | 
				
			
			@ -30,6 +33,10 @@ SELECTED_OUTRO="$(find  "$OUTROS_PATH" -type f | sort --reverse --human-numeric-
 | 
			
		|||
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}"
 | 
			
		||||
| 
						 | 
				
			
			@ -80,14 +87,15 @@ then
 | 
			
		|||
    echo "Too few chunks, this script can't handle this yet. Please do that on your own."
 | 
			
		||||
    exit 1
 | 
			
		||||
fi
 | 
			
		||||
#ffmpeg -i "$SELECTED_INTRO" \
 | 
			
		||||
#       -i "$SELECTED_OUTRO" \
 | 
			
		||||
#    -ss "$START_OFFSET" -i "${CHUNKS_ARRAY[0]}" \
 | 
			
		||||
echo    "${CHUNKS_ARRAY[@]:1:-2}"
 | 
			
		||||
#    -t "$END_OFFSET" -i "${CHUNKS_ARRAY[-1]}" \
 | 
			
		||||
 | 
			
		||||
# STEP 1
 | 
			
		||||
# temp dir
 | 
			
		||||
WORKDIR=$(mktemp -d)
 | 
			
		||||
function finish {
 | 
			
		||||
  rm -r "$WORKDIR"
 | 
			
		||||
}
 | 
			
		||||
trap finish EXIT
 | 
			
		||||
 | 
			
		||||
# STEP 2
 | 
			
		||||
# introfile with first chunk and crossfade encode
 | 
			
		||||
ffmpeg -i "$SELECTED_INTRO" -ss "$START_OFFSET" -i "${CHUNKS_ARRAY[0]}" \
 | 
			
		||||
| 
						 | 
				
			
			@ -123,26 +131,26 @@ ffmpeg -i "$SELECTED_OUTRO" -t "$END_OFFSET" -i "${CHUNKS_ARRAY[-1]}" \
 | 
			
		|||
# STEP 4
 | 
			
		||||
# encoded intro+outro and all chunks in between with c:v copy and audio dynnorm + encode
 | 
			
		||||
 | 
			
		||||
FFMPEG_CHUNKS=""
 | 
			
		||||
FFMPEG_CONCAT=""
 | 
			
		||||
CHUNKLIST="${WORKDIR}/chunklist.txt"
 | 
			
		||||
 | 
			
		||||
echo "file '${WORKDIR}/introcombined.mkv'" > "$CHUNKLIST"
 | 
			
		||||
 | 
			
		||||
FFMPEG_CONCAT_CHUNKS=""
 | 
			
		||||
if [[ ${ARRAY_LENGTH} -gt 2 ]]
 | 
			
		||||
then
 | 
			
		||||
    for index in $(seq 1 $(( ${ARRAY_LENGTH} - 2 )) )
 | 
			
		||||
    do
 | 
			
		||||
        FFMPEG_CHUNKS="${FFMPEG_CHUNKS} -i ${CHUNKS_ARRAY[index]}"
 | 
			
		||||
        FFMPEG_CONCAT="${FFMPEG_CONCAT} [$((index + 1)):v:0][$((index + 1)):a:0]"
 | 
			
		||||
        FFMPEG_CONCAT_CHUNKS="${FFMPEG_CONCAT_CHUNKS}|${CHUNKS_ARRAY[index]}"
 | 
			
		||||
        echo "file '${CHUNKS_ARRAY[index]}'" >> "$CHUNKLIST"
 | 
			
		||||
    done
 | 
			
		||||
fi
 | 
			
		||||
 | 
			
		||||
ffmpeg -i "${WORKDIR}/introcombined.mkv" -i "${WORKDIR}/outrocombined.mkv" \
 | 
			
		||||
    $FFMPEG_CHUNKS -filter_complex \
 | 
			
		||||
    "[0:v:0][0:a:0]
 | 
			
		||||
    $FFMPEG_CONCAT
 | 
			
		||||
    [1:v:0][1:a:0]
 | 
			
		||||
    concat=n=${ARRAY_LENGTH}:v=1:a=1
 | 
			
		||||
    [v][a];[a]dynaudnorm[ad]" \
 | 
			
		||||
    -map '[v]' -map '[ad]' \
 | 
			
		||||
    -c:v libx264 -threads 0 -pix_fmt yuv420p -crf 18 -profile:v high -level 4.1 -disposition default \
 | 
			
		||||
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}/combinedrender.mkv"
 | 
			
		||||
    "${OUTPUT_PATH}/${OUTPUT_NAME}.mkv"
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue