forked from cwtv/stuff
				
			Adding into outro generator using images
This commit is contained in:
		
							parent
							
								
									ac0f1b5a4e
								
							
						
					
					
						commit
						6c6222730f
					
				| 
						 | 
				
			
			@ -16,6 +16,7 @@ set -euo pipefail
 | 
			
		|||
# 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.
 | 
			
		||||
# It will also assume, that the intros and outros are pictures...
 | 
			
		||||
 | 
			
		||||
# This script requires you to have ffmpeg and fzf installed.
 | 
			
		||||
which ffmpeg >/dev/null || (echo "Please install ffmpeg" ; exit 1)
 | 
			
		||||
| 
						 | 
				
			
			@ -27,6 +28,13 @@ OUTROS_PATH="$HOME/Dokumente/syncthing/outros"
 | 
			
		|||
CHUNKS_PATH="$HOME/Dokumente/syncthing/"
 | 
			
		||||
OUTPUT_PATH="$HOME/Videos/WK25/rendered"
 | 
			
		||||
 | 
			
		||||
# temp dir
 | 
			
		||||
WORKDIR=$(mktemp -d)
 | 
			
		||||
function finish {
 | 
			
		||||
  rm -r "$WORKDIR"
 | 
			
		||||
}
 | 
			
		||||
trap finish EXIT
 | 
			
		||||
 | 
			
		||||
# 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:")"
 | 
			
		||||
| 
						 | 
				
			
			@ -37,6 +45,20 @@ 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
 | 
			
		||||
 | 
			
		||||
# Function to convert image to video with audio
 | 
			
		||||
convert_image_to_video() {
 | 
			
		||||
    local image_file="$1"
 | 
			
		||||
    local output_video="$2"
 | 
			
		||||
    local duration="$3"
 | 
			
		||||
    local fade_in="$4"
 | 
			
		||||
    local fade_out="$5"
 | 
			
		||||
 | 
			
		||||
    ffmpeg -loop 1 -t "$duration" -i "$image_file" -f lavfi -i anullsrc=r=48000:cl=stereo \
 | 
			
		||||
        -vf "fade=t=in:st=0:d=$fade_in,fade=t=out:st=$(($duration - $fade_out)):d=$fade_out,format=yuv420p" \
 | 
			
		||||
        -r 50 -c:v libx264 -c:a aac -b:a 192k -t "$duration" "$output_video"
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
# 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}"
 | 
			
		||||
| 
						 | 
				
			
			@ -56,6 +78,22 @@ PLAY_LAST_CHUNK="${PLAY_LAST_CHUNK:-n}"
 | 
			
		|||
read -p "Enter the end-offset in seconds for the last chunk ${CHUNKS_ARRAY[0]} [1]: " END_OFFSET
 | 
			
		||||
END_OFFSET="${END_OFFSET:-1}"
 | 
			
		||||
 | 
			
		||||
# Check if intro is an image and convert if necessary
 | 
			
		||||
EXT_INTRO="${SELECTED_INTRO##*.}"
 | 
			
		||||
if [[ "$EXT_INTRO" == "png" || "$EXT_INTRO" == "jpg" || "$EXT_INTRO" == "jpeg" ]]; then
 | 
			
		||||
    INTRO_VIDEO="$WORKDIR/intro_converted.mkv"
 | 
			
		||||
    convert_image_to_video "$SELECTED_INTRO" "$INTRO_VIDEO" 4 1 1
 | 
			
		||||
    SELECTED_INTRO="$INTRO_VIDEO"
 | 
			
		||||
fi
 | 
			
		||||
 | 
			
		||||
# Check if outro is an image and convert if necessary
 | 
			
		||||
EXT_OUTRO="${SELECTED_OUTRO##*.}"
 | 
			
		||||
if [[ "$EXT_OUTRO" == "png" || "$EXT_OUTRO" == "jpg" || "$EXT_OUTRO" == "jpeg" ]]; then
 | 
			
		||||
    OUTRO_VIDEO="$WORKDIR/outro_converted.mkv"
 | 
			
		||||
    convert_image_to_video "$SELECTED_OUTRO" "$OUTRO_VIDEO" 6 1 1
 | 
			
		||||
    SELECTED_OUTRO="$OUTRO_VIDEO"
 | 
			
		||||
fi
 | 
			
		||||
 | 
			
		||||
cat <<EOT
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -74,6 +112,7 @@ for index in "${!CHUNKS_ARRAY[@]}"
 | 
			
		|||
do
 | 
			
		||||
    echo "            + $index: ${CHUNKS_ARRAY[index]}"
 | 
			
		||||
done
 | 
			
		||||
echo "Export: ${OUTPUT_PATH}/${OUTPUT_NAME}.mkv"
 | 
			
		||||
echo ; echo ; echo
 | 
			
		||||
read -p "Do you want to proceed with this configuration? (y/n) [y]" PROCEED
 | 
			
		||||
PROCEED="${PROCEED:-y}"
 | 
			
		||||
| 
						 | 
				
			
			@ -81,6 +120,7 @@ PROCEED="${PROCEED:-y}"
 | 
			
		|||
[[ "$PROCEED" == "y" ]] || (echo "aborting"; exit 1)
 | 
			
		||||
echo "doing ffmpeg things here"
 | 
			
		||||
 | 
			
		||||
# combine the videos...
 | 
			
		||||
ARRAY_LENGTH="${#CHUNKS_ARRAY[@]}"
 | 
			
		||||
if [[ ${ARRAY_LENGTH} -lt 2 ]]
 | 
			
		||||
then
 | 
			
		||||
| 
						 | 
				
			
			@ -154,3 +194,5 @@ ffmpeg \
 | 
			
		|||
    -c:a aac -b:a 192k \
 | 
			
		||||
    -metadata:s:a:0 language=native \
 | 
			
		||||
    "${OUTPUT_PATH}/${OUTPUT_NAME}.mkv"
 | 
			
		||||
 | 
			
		||||
echo "Video Exported to ${OUTPUT_PATH}/${OUTPUT_NAME}.mkv"
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue