Skip to content

Instantly share code, notes, and snippets.

@troutcolor troutcolor/pum.sh
Last active Dec 21, 2018

Embed
What would you like to do?
#script to download pile of flickr images and make a movie like the pummelvision service # example https://vimeo.com/196182638 #needs ffmpeg sox & jhead #needs sips so a mac I think
#!/bin/bash
#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='YOUR-API-KEY-HERE'
USERID='71428177%40N00'
SINCEDATE='2018-01-01'
#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='2'
PHOTOSORT='date-posted-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')
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")
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 768 *.jpg
sips --padToHeightWidth 768 1024 *.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")
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 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 http://incompetech.com/music/royalty-free/mp3-royaltyfree/Hyperfun.mp3 > background.mp3
break
;;
"Scattershot")
echo "downloading Scattershot"
curl http://incompetech.com/music/royalty-free/mp3-royaltyfree/Scattershot.mp3 > background.mp3
break
;;
*) echo invalid option;;
esac
done
sox -e ima-adpcm background.mp3 looped_audio.mp3 repeat 3
ffmpeg -i flickr.mp4 -i looped_audio.mp3 -map 0 -map 1 -codec 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
You can’t perform that action at this time.