Time lapse movies from still jpegs
Posted: Thu Jan 21, 2016 9:32 pm
I'm posting this because in some situations the easy-to-find web answers don't work.
This is in part because some versions of linux don't do ffmpeg anymore, due to an acrimonious fork to libav, and putting ffmpeg into say, ubuntu 14.04 breaks other things...(I use Mint Mate 17.3 which is ubuntu 14.04 at the base, but I like mint a heck of a lot better as a UI)
And it turns out some things are tweaky in regards filename conventions and so forth. Thus, this post. I'm using one of my Raspberry Pis as a source of images, and they are big - 3-4 MB each, and in timelapse mode, have strange filenames with lots of other numbers (time, date, ??, and timelapse sequence number in there somewhere). I'll have to go and mess with config files there to get something more reasonable. Glad I put 2 tb on this pi!
After a lot of looking, I found this link that gets it done (with mods):
http://techedemic.com/2014/09/18/creati ... th-avconv/
So this guy deserves some credit, as everyone else says just put in ffmpeg, which is kind of off the wall for a distro that is broken by it.
This is blazing fast as these things go, and uses all the cores of the cpu in parallel, and changed around 117 MB of stills (192 of them) into around 17 MB of video at 24 fps - and full resolution. 2592x1944 in this case - a little better than HD.
Here are the commands I wound up with (adapted from the link above).
Rename the files (They're all in a directory I made for this, and the terminal is cd'd to that directory already):
Since the ls sorts alphanumerically, they stay in order, and wind up with just the sequence number as a filename, with .jpg as the extension. This took about 1 second on a haswell NUC - mostly disk time I suspect. So now I have 192 files with reasonable names (a time lapse at 30 seconds per shot for a few hours today).
Then to make a movie:
for 10 fps or
for 24 fps.
His example included cropping, which I didn't want and haven't tried, it looked like this:
avconv -y -r 10 -i %4d.JPG -r 10 -vcodec libx264 -q:v 3 -vf crop=4256:2832,scale=iw:ih tlfullhiqual.mp4;
(note, for the ones I used I changed .jpg to lower case, as that's what I get and like to use anyway - linux is case sensitive)
Normally, I'd have uploaded a vid to youtube - and let them take care of scaling, cropping and bitrates - their computers do it net faster than I can convert and upload the lower bitrate version anyway - and leave super high quality available for those who have the connection bitrate - but my test video so far could be described as "30 second timelapse shots of my yard while it got dark today" and no one really wants to see that. We're supposed to have some "exciting weather" tomorrow, and I plan to timelapse being buried in snow and ice and put that up when I have it - assuming it happens as predicted. That's why I was practicing how to do this today in the first place. I suspect at some point this is going to be pretty cool - maybe I should dedicate a pi to watching my garden grow and so on.
This is in part because some versions of linux don't do ffmpeg anymore, due to an acrimonious fork to libav, and putting ffmpeg into say, ubuntu 14.04 breaks other things...(I use Mint Mate 17.3 which is ubuntu 14.04 at the base, but I like mint a heck of a lot better as a UI)
And it turns out some things are tweaky in regards filename conventions and so forth. Thus, this post. I'm using one of my Raspberry Pis as a source of images, and they are big - 3-4 MB each, and in timelapse mode, have strange filenames with lots of other numbers (time, date, ??, and timelapse sequence number in there somewhere). I'll have to go and mess with config files there to get something more reasonable. Glad I put 2 tb on this pi!
After a lot of looking, I found this link that gets it done (with mods):
http://techedemic.com/2014/09/18/creati ... th-avconv/
So this guy deserves some credit, as everyone else says just put in ffmpeg, which is kind of off the wall for a distro that is broken by it.
This is blazing fast as these things go, and uses all the cores of the cpu in parallel, and changed around 117 MB of stills (192 of them) into around 17 MB of video at 24 fps - and full resolution. 2592x1944 in this case - a little better than HD.
Here are the commands I wound up with (adapted from the link above).
Rename the files (They're all in a directory I made for this, and the terminal is cd'd to that directory already):
- Code: Select all
ls *.jpg| awk 'BEGIN{ a=0 }{ printf "mv %s %04d.jpg\n", $0, a++ }' | bash
Since the ls sorts alphanumerically, they stay in order, and wind up with just the sequence number as a filename, with .jpg as the extension. This took about 1 second on a haswell NUC - mostly disk time I suspect. So now I have 192 files with reasonable names (a time lapse at 30 seconds per shot for a few hours today).
Then to make a movie:
- Code: Select all
avconv -y -r 10 -i %4d.jpg -r 10 -vcodec libx264 -q:v 3 -vf scale=iw:ih tenfps.mp4;
for 10 fps or
- Code: Select all
avconv -y -r 24 -i %4d.jpg -r 24 -vcodec libx264 -q:v 3 -vf scale=iw:ih twofourfps.mp4;
for 24 fps.
His example included cropping, which I didn't want and haven't tried, it looked like this:
avconv -y -r 10 -i %4d.JPG -r 10 -vcodec libx264 -q:v 3 -vf crop=4256:2832,scale=iw:ih tlfullhiqual.mp4;
(note, for the ones I used I changed .jpg to lower case, as that's what I get and like to use anyway - linux is case sensitive)
Normally, I'd have uploaded a vid to youtube - and let them take care of scaling, cropping and bitrates - their computers do it net faster than I can convert and upload the lower bitrate version anyway - and leave super high quality available for those who have the connection bitrate - but my test video so far could be described as "30 second timelapse shots of my yard while it got dark today" and no one really wants to see that. We're supposed to have some "exciting weather" tomorrow, and I plan to timelapse being buried in snow and ice and put that up when I have it - assuming it happens as predicted. That's why I was practicing how to do this today in the first place. I suspect at some point this is going to be pretty cool - maybe I should dedicate a pi to watching my garden grow and so on.