diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..fe0a2e4 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2023 Samuel Lord + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/image-finder.sh b/image-finder.sh new file mode 100644 index 0000000..97d149a --- /dev/null +++ b/image-finder.sh @@ -0,0 +1,3 @@ +url=$(curl -sS "https://unsplash.com/s/photos/$1?license=free" | grep -o 'href="[^"]*' | grep 'download' | head -n 1 | sed 's/href="//') +wget -O "img/$1.$(wget --spider --server-response -O - 'YOUR_URL' 2>&1 | grep -E -o -i 'Content-Type:.*' | cut -d ' ' -f 2 | cut -d ';' -f 1)" "$url" + diff --git a/install-depends-ubuntu.sh b/install-depends-ubuntu.sh new file mode 100644 index 0000000..cb683a3 --- /dev/null +++ b/install-depends-ubuntu.sh @@ -0,0 +1,2 @@ +curl https://ollama.ai/install.sh | sh +sudo apt install imagemagick curl wget diff --git a/keywords2images.sh b/keywords2images.sh new file mode 100644 index 0000000..da7064a --- /dev/null +++ b/keywords2images.sh @@ -0,0 +1,14 @@ +while IFS= read -r line; do + ./image-finder.sh "$line" +done < script-keywords.txt + +# Navigate to the img/ directory +cd img/ + +# Find and delete images not divisible by 2 +find . -type f -exec bash -c 'if [ $(identify -format "%h" "{}")%2 -ne 0 ]; then rm "{}"; fi' \; + +# Return to the original directory (optional) +cd .. + +find img -type f -size 0 -delete diff --git a/make_video.sh b/make_video.sh new file mode 100644 index 0000000..fa73d6d --- /dev/null +++ b/make_video.sh @@ -0,0 +1,9 @@ +./scripter.sh "$1" +./keywords2images.sh +espeak -f script.txt -w voice.wav +ls -1v img/* | while IFS= read -r file; do + echo "file '$(echo "$file" | sed "s/'/\\\'/g")'" +done > concat.txt +sed -i '/\\/d' concat.txt + +./renderer.sh diff --git a/make_video_premade_script.sh b/make_video_premade_script.sh new file mode 100644 index 0000000..c57e1a3 --- /dev/null +++ b/make_video_premade_script.sh @@ -0,0 +1,9 @@ +./scripter_premade.sh "$1" +./keywords2images.sh +espeak -f script.txt -w voice.wav +ls -1v img/* | while IFS= read -r file; do + echo "file '$(echo "$file" | sed "s/'/\\\'/g")'" +done > concat.txt +sed -i '/\\/d' concat.txt + +./renderer.sh diff --git a/renderer.sh b/renderer.sh new file mode 100644 index 0000000..fbe1fa7 --- /dev/null +++ b/renderer.sh @@ -0,0 +1,11 @@ +total_frames=$(wc -l < concat.txt) # Count the total number of frames in concat.txt +voice_length=$(ffprobe -i voice.wav -show_entries format=duration -v quiet -of csv="p=0") # Get the length of voice.wav + +# Calculate the correct duration of each frame +duration=$(echo "$voice_length / $total_frames" | bc) + +fps=$(echo "scale=2; $total_frames / $voice_length" | bc) + +# Use the corrected duration in the FFmpeg command +ffmpeg -r $fps -f concat -safe 0 -i concat.txt -i voice.wav -c:v libx264 -c:a aac -vf "setpts=PTS/1" -pix_fmt yuv420p -shortest output_video.mp4 + diff --git a/scripter.sh b/scripter.sh new file mode 100644 index 0000000..582b8b6 --- /dev/null +++ b/scripter.sh @@ -0,0 +1,11 @@ +ollama run sparksammy/samantha "Write a video script about $1. Do NOT include title or description. Do not include scene transitions, either. Make yourself anonymous. Do not state your name. Also, do not ask for replies, and do not specify that you are an assistant." > script.txt +awk '{ print $2 }' script.txt > script-keywords.txt +awk '{ print $4 }' script.txt >> script-keywords.txt +awk '{ print $6 }' script.txt >> script-keywords.txt + +mkdir img +rm img/* +while IFS= read -r line; do + ./image-finder.sh "$line" +done < script-keywords.txt +find img -type f -size 0 -delete diff --git a/scripter_premade.sh b/scripter_premade.sh new file mode 100644 index 0000000..c87942e --- /dev/null +++ b/scripter_premade.sh @@ -0,0 +1,11 @@ +echo "$1" > script.txt +awk '{ print $2 }' script.txt > script-keywords.txt +awk '{ print $4 }' script.txt >> script-keywords.txt +awk '{ print $6 }' script.txt >> script-keywords.txt + +mkdir img +rm img/* +while IFS= read -r line; do + ./image-finder.sh "$line" +done < script-keywords.txt +find img -type f -size 0 -delete