Last active
August 14, 2024 18:17
-
-
Save troutcolor/370a49898124413c78d17a5c86c42a2e to your computer and use it in GitHub Desktop.
#script to download pile of flickr images and make a montage #needs montage command which comes with imagemagick I install that with homebrew #some notes at the end of the file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
#ToDOs | |
# find how how many photos and work out pages automatically | |
# use parameters in terminal rather than in script | |
#2024 additions | |
# Added Morning audio choice, gentler added a fade to the audio | |
# only use sox if the audio is not long enough | |
#2018 additions | |
#needs jhead which I installed with homebrew | |
#jhead auto rotates images according to the exif Orientation which ffmpeg does not respect | |
#if the photos do not need rotated then you could remove the jhead line below | |
#sox to loop audio. I installed with homebrew | |
#my video was longer than the audio, I just create a loop of 3 with sox and use that. Could up the number iif you have more photos than me | |
# set -ex bail if something fails and print lines as they are executed | |
set -ex | |
#script to download pile of flickr images and make a movie like the pummelvision service | |
# example https://vimeo.com/196182638 | |
#needs ffmpeg | |
#needs sips so a mac I think | |
#Fill in the param any except the APIKEY can be empty | |
# this will take some time! | |
APIKEY='FILL-IN_API_KEY' | |
#MY USER ID | |
USERID='71428177%40N00' | |
SINCEDATE='2024-06-27' | |
#unix timestamp or mysql datetime | |
TAGS='' | |
NUMPHOTOS='500' | |
#max photos 500 | |
#Need to know how many pages there are if you want more that the first 500 images | |
PAGES='1' | |
PHOTOSORT='date-taken-desc' | |
#date-posted-desc | |
#date-posted-asc | |
#date-posted-desc | |
#date-taken-asc | |
#date-taken-desc | |
#interestingness-desc | |
#interestingness-asc | |
#relevance | |
FRAMESPERSECOND=2 | |
#### END OF SETTINGS #### | |
#Make a temp directory to work in | |
TEMPDIR=$(mktemp -d -t 'mytmpdir') | |
open $TEMPDIR | |
HERE=$( pwd ) | |
trap "{ cd $HERE ; rm -rf $TEMPDIR; exit 255; }" SIGINT | |
cd $TEMPDIR | |
ALLFILELIST="" | |
for counter in `seq 1 $PAGES`; | |
do | |
searchurl="https://api.flickr.com/services/rest/?method=flickr.photos.search&api_key=${APIKEY}&user_id=${USERID}&media=photos&min_taken_date=${SINCEDATE}&text=${TAGS}&extras=url_o&sort=${PHOTOSORT}&per_page=${NUMPHOTOS}&page=${counter}&format=rest" | |
FILELIST=$(curl "$searchurl" | sed -ne 's/.*\(http[^"]*\).*/\1/p') | |
ALLFILELIST="$ALLFILELIST $FILELIST" | |
done | |
echo $ALLFILELIST | |
a=`echo $ALLFILELIST | wc -w` | |
let a=a+1 | |
new=$(printf "%04d.jpg" "$a") | |
#Get the credits for audio | |
curl -o $new https://farm9.staticflickr.com/8718/16191965623_9dacf5c640_o_d.jpg > $new | |
for i in $ALLFILELIST ; | |
do | |
let a=a-1 | |
new=$(printf "%04d.jpg" "$a") | |
curl -o $new $i | |
done; | |
sips --resampleHeight 1536 *.jpg | |
sips --padToHeightWidth 1536 2048 *.jpg | |
jhead -autorot *.jpg | |
#ffmpeg -framerate 5 -i %04d.jpg -c:v libx264 flickr.mp4 | |
ffmpeg -framerate ${FRAMESPERSECOND} -i %04d.jpg -c:v libx264 flickr.mp4 | |
PS3='Please enter your choice: ' | |
options=("Rolling at 5" "Lagoa v2" "Off to Osaka" "Hyper Fun" "Scattershot" "Morning") | |
select opt in "${options[@]}" | |
do | |
case $opt in | |
"Rolling at 5") | |
echo "downloading." | |
curl -L http://incompetech.com/music/royalty-free/mp3-royaltyfree/Rollin%20at%205.mp3 > background.mp3 | |
break | |
;; | |
"Lagoa v2") | |
echo "downloading Lagoa v2" | |
curl -L http://incompetech.com/music/royalty-free/mp3-royaltyfree/Lagoa%20v2.mp3 > background.mp3 | |
break | |
;; | |
"Off to Osaka") | |
echo "downloading Off to Osaka" | |
curl -L http://incompetech.com/music/royalty-free/mp3-royaltyfree/Off%20to%20Osaka.mp3 > background.mp3 | |
break | |
;; | |
"Hyper Fun") | |
echo "downloading Hyper Fun" | |
curl -L http://incompetech.com/music/royalty-free/mp3-royaltyfree/Hyperfun.mp3 > background.mp3 | |
break | |
;; | |
"Scattershot") | |
echo "downloading Scattershot" | |
curl -L http://incompetech.com/music/royalty-free/mp3-royaltyfree/Scattershot.mp3 > background.mp3 | |
break | |
;; | |
"Morning") | |
echo "downloading Morning" | |
curl -L https://incompetech.com/music/royalty-free/mp3-royaltyfree/Morning.mp3 > background.mp3 | |
break | |
;; | |
*) echo invalid option;; | |
esac | |
done | |
# Get the duration of the video file | |
VIDEO_DURATION=$(ffprobe -i flickr.mp4 -show_entries format=duration -v quiet -of csv="p=0") | |
# Get the duration of the audio file | |
AUDIO_DURATION=$(ffprobe -i background.mp3 -show_entries format=duration -v quiet -of csv="p=0") | |
# Round up the duration to the next integer | |
AUDIO_DURATION=${AUDIO_DURATION%.*} | |
# Check if the audio duration is shorter than the video duration | |
if (( AUDIO_DURATION < VIDEO_DURATION )); then | |
# Calculate the number of times the audio needs to be looped | |
LOOP_COUNT=$(( (VIDEO_DURATION / AUDIO_DURATION) + 1 )) | |
# Use sox to loop the audio | |
sox background.mp3 background_looped.mp3 repeat $LOOP_COUNT trim 0 $VIDEO_DURATION | |
else | |
# Copy the audio as is if it's already longer than the video | |
cp background.mp3 background_looped.mp3 | |
fi | |
echo "Audio file has been processed and saved as background_looped.mp3" | |
# Calculate the start time for the fade-out effect (video duration - 5 seconds) | |
FADE_START=$(echo "$VIDEO_DURATION - 5" | bc) | |
# Apply the fade-out effect and combine the audio with the video | |
ffmpeg -i flickr.mp4 -i background_looped.mp3 -filter_complex "[1:a]afade=t=out:st=$FADE_START:d=5[audio]" -map 0:v -map "[audio]" -codec:v copy -codec:a aac -strict experimental -b:a 192k -shortest flickr-audio.mp4 | |
mv "$TEMPDIR/flickr-audio.mp4" "$HERE" | |
cd "$HERE" | |
#rm -rf $TEMPDIR | |
open $TEMPDIR | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment