How to create a timelapse (both timed pictures and post-processed video) live viewable

edit: Note that physically, the set-up is that I have an extra desktop which is always on and connect to the internet which is running Ubuntu (16.04).  I have an external webcam. This also requires a dropbox account.

I’ve often wanted to monitor something remotely, but have had issues in the past trying to set up a video stream. For monitoring experiments remotely (or for instance a 3d printer), I really don’t need 30 frames per second.

I suppose nowadays, in theory I could set up a youtube live stream, especially since I could just disable audio. But for more control over the end result, my solution is a one-liner bash command, combined with a dropbox account.

I was having a terrible time with all my search results describing ways to create a timelapse animation, instead of detailing how to take the pictures for the timelapse in the first place.

 

use streamer

streamer -c /dev/video1 -t 10 -r 1 -o 0000.jpeg &

The settings for the above command are as follows:

  • Using the “second” camera (ince my desktop has a built-in webcam mapped to /dev/video0, whereas I wanted to take pictures with a USB webcam)
  • 10 frames total
  • 1 frame a second (rate)
  • Name starts at 0000.jpeg (it will automatically count up)
streamer -c /dev/video1 -t 300 -r 0.0033 -s 640x480 -o 0000.jpeg &

i used the first command to test whether the command is working.

  • For the actual timelapse, I wanted to take a picture every 5 minutes, or in other words every (1/360 = 0.0033) seconds. (I don’t think there’s an option to define the rate in anything other than seconds).
  • I wanted about 24 hours of timelapse. At every 5 minutes, I take 12 an hour or 12*24 a day, so around 300 frames
  • Streamer was defaulting to 320×240 pixel images, so I asked streamer to instead take 640×480 pictures, which are what my webcam supports.

timelapse

Note: I did not really play around with this, but I think you can also create video with streamer, e.g.

streamer -c /dev/video1 -t 0:30 -o movie.avi -f jpeg

installing headless dropbox

Following the online instructions from the dropbox site

cd ~ && wget -O - "https://www.dropbox.com/download?plat=lnx.x86_64" | tar xzf -
Run the synchronizer
~/.dropbox-dist/dropbox

making the timelapse persistent

screen allows our session (within which we are running streamer) to persist, even if someone closes the terminal window.

Screen Basic commands:
screen -r (reattach)
screen -d (inside screen session, to detach)
ctrl-shift-w

ctrl-a w (list windows)
ctrl-a 1 (switch to window #1)
ctrl-a c (new window)
exit (close window) — after last window is closed, screen terminates.

Commands to handle background process

For instance, if you messed up your settings and streamer is now taking 300 frames at a rapid rate,
$ ps x | grep streamer
$ sudo killall streamer

Putting it all together

$ nohup ~/.dropbox-dist/dropboxd&
$ screen
> cd ~/Dropbox
> streamer -c /dev/video1 -t 300 -r 0.0033 -s 640x480 -o 0000.jpeg &

Now, I can access my setup online at dropbox.com. I can also use the “share folder using link” option on dropbox to share with multiple people.

Make a QR code

This was purely for fun, but I turned the dropbox link into a QR code which I printed out and stuck next to the experiment

ducky_screenshot

Protips

I find it really handy to include labeling information not just in the filenames but also physically in the image. Below you can see I labeled the image with the date of the timelapse.0233

Making a timelapse (animation / video of the resulting images) using ffmpeg

Use ffmpeg.

 cat *.jpg | ffmpeg -r 20 -f image2pipe -i - output.mp4

Takes all jpg files and turns it into an mp4 with 20 frames per second.

I was having a lot of issues following the instructions online, but somehow using the image2pipe solved everything. (I was getting errors like “would you like to overwrite this .jpeg file y/n”).

[~/Downloads/buse/rotate]$ ffmpeg -framerate 1/2 -i *.JPG -c:v libx2^C -r 30 out.mp~4
File '0010_rotated.JPG' already exists. Overwrite ? [y/N] nNot overwriting - exiting

https://en.wikibooks.org/wiki/FFMPEG_An_Intermediate_Guide/image_sequence

One thing that surprised me on this page, is that a common command such as “all images in this folder” is a little trickier than I’d expect. (I was working with another set of images that used timestamps as filenames, instead of an orderly 0001.jpeg like other examples onlin).
1) You must use “glob option”
2) You must surround your search pattern in quotes

 ffmpeg -pattern_type glob -i "image-*.png" video.webm

note to self: to rotate all images in a directory 90 degrees clockwise:

for file in ./*.jpg do
 convert "$file" -rotate 90 "${file%.JPG}"_rotated.JPG
done

There you have it!

Thanks to the one-liner “streamer” command, and by using dropbox as a syncing service. you can accomplish a real-time viewable timelapse with just 4 or 5 lines of code, and then use just one more line to create a video of the resulting images.

$ nohup ~/.dropbox-dist/dropboxd&
$ screen
> cd ~/Dropbox
> streamer -c /dev/video1 -t 300 -r 0.0033 -s 640x480 -o 0000.jpeg &
 cat *.jpg | ffmpeg -r 20 -f image2pipe -i - output.mp4

Drawing Automata and the History of Computer Science

Note: This is mostly for me to remind myself of the name of the drawing automata that I still love to look at videos of and wonder at how amazing it is.

https://www.youtube.com/watch?v=bY_wfKVjuJM

 

Currently I’m taking this Computer Science 191: Classics of Computer Science, where we read a bunch of famous papers tracing the evolution of computer science.

Today we talked about the Analytical Engine. (Lovelace wrote the lengthy “Notes” part which takes up the bottom 2/3). Some people at my table thought it was crazy to go from an abacus to this complicated setup. Due to my interest in mechanical engineering and robot art, I knew of this mechanical writing machine where you could slot letters in and out. I thought this was Maillardet’s (so 40 years before Babbage), but I think the letter-selecting device is actually from Jaquet-Droz automata.

The video I remember is the BBC one.

jacquardbbcdetail

Anyhow, these were made to sell more watches (at least according to wikipeida)! Just some bored watchmakers, making crazy intense automata.

Here is another documentary which explains in the first 5 minutes or so how Jaquet made little dioramas with mechanically spinning and quacking birds (really, reminds me of the Fabergé eggs!), traveled and got a bunch of money after waiting months to see a king, and then got to go make complicated things like this automata.

jacquard

Maillardet’s is at the Franklin Institute in Philadelphia. Here is some more about it from FI. Here’s a CBS show about it. Apparently it is possible it has the most “read-only memory”, about 300 kb.

Also apparently the drawing automata in Hugo was created in real life! This pleases me immensely.

Oh yea they also passed around some Jacquard’s loom punchcards. I don’t know much about weaving and so the complexity of programmable looms goes over my head, but I think the drawing automata makes it really easy to comprehend how complicated these things can get. At least, it really impressed the folks at my table 🙂

jacquardpunchcard jacquardpunchcarddetail

 

What else… oh I learned what squaring the circle means, since Hilbert talks about it in his “Mathematical Problems” lecture.

I also love how the wikipedia article talks about “debunking illogical circle-squaring theories“. I guess we have perpetual motion theories still! Apparently “squaring the circle” is also an idiom for “trying to do the impossible.”

Oh, and there’s a lady mathematician who formed an integral part of the 10th problem, which is the one people go gaga about trying to figure out if Hilbert would have approved of (the solution to). That’s the one where we learned that we cannot know the solution

I also thought it was cool how the work to solve this problem built up over two decades. (and one of the four contributors was Julia Robinson, who had a J.R. hypothesis that wasn’t proven until 20 years later).

Oh, and then we read Turing’s paper, the one with That Word. Entscheidungsproblem. Anyhow, I started browsing briefly and decided I really still have no idea what it means for something to be computable. The wikipedia article states “Computability is the ability to solve a problem in an effective manner”. Really, wikipedia? It’s probably similar to the question of what counts as a robot, I suppose. Anyhow, that article briefly mentions both automata (heh, sounds like automaton) and also hypercomputability. Such a fun word.

Okay, now back to fixing the problem of why my alarm clock app, Timely, no longer goes off reliably :((((((((((( I thought Timely might have updated, but it says the last update was in September of 2017. So maybe it’s some Tmobile or Android or Samsung update that borked my alarm clock 🙁 I’ll try the only other version of Timely, a 2015 update, and report back.

 

connecting to eduroam & harvard wireless without having to install sketchy things

UPDATE 27 SEPT 2019 (checked current as of 27 Dec 2019 as well) – Ubuntu 19.04 / Android version 9

It appears eduroam settings have changed (CA certificate *must* be installed)

On my laptop (Ubuntu 19.04)

Where the CA file comes from

 /etc/ssl/certs/AddTrust_External_Root.pem

(thanks old blog post)

Note: Eduroam appears to be the same settings as Harvard Secure

Android

I also had to install the certs on my phone

  1. Put above file onto phone (I transferred using bluetooth> send files, but usb would work too I’m sure)
  2. Install on phone
  3. And then type some sensible name
  4. Then, connect to Harvard Secure wifi with similar settings as in the desktop case. Select the CA certificate we just installed.

And hopefully it will work.

  PROTIP: You have to be fully disconnect from the network (not attempting to connect to it) in order to edit the settings.

I’m still working out how to reconnect to eduroam… sigh

Legitimately, when I have friends co-work, it’s so annoying for them to connect to the internet that I end up just giving them my password. Which is wrong and bad for all kinds of reasons, but that’s life as an end-user…

Troubleshooting / via CLI for the nerds

 

rui@chaiX1YG2:/ $ nmcli con 
NAME UUID TYPE DEVICE 
eduroam 9196d2be-df9e-4f92-8781-c5c47c60e90d wifi wlp4s0
rui@chaiX1YG2:/etc/NetworkManager/system-connections$ $ sudo cat eduroam
[sudo] password for rui: 
[connection]
id=eduroam
uuid=9196d2be-df9e-4f92-8781-c5c47c60e90d
type=wifi
permissions=
timestamp=1548391592

[wifi]
mac-address=A0:AF:BD:E9:F4:18
mac-address-blacklist=
mode=infrastructure
seen-bssids=A4:6C:3B:3F:AA:FB;70:3A:0E:88:80:50
ssid=eduroam

[wifi-security]
key-mgmt=wpa-eap

[802-1x]
ca-cert=/etc/ssl/certs/AddTrust_External_Root.pem
eap=ttls;
identity=CHANGETHIS@g.harvard.edu
password=CHANGETHIS
phase2-auth=pap

[ipv4]
dns-search=
method=auto

[ipv6]
addr-gen-mode=stable-privacy
dns-search=
method=auto


OUTDATED – Old post below:

Harvard is very insistent about me downloading random software in order to connect to their wireless network, even though I have Harvard credentials (and eduroam credentials).

I have no idea why they do this. Why do I need to download software to connect to a wifi network? Anyhow, the solution is to just ignore it and figure out the settings on my own.

I just use eduroam. Here is what the internet told me:

https://superuser.com/questions/34198/securew2-equivalent-on-linux#472303

  • Security : WPA & WPA2 Enterprise
  • Authentication : Tunnelled TLS
  • Anonymous Identity : (I left this blank,but I think they have configured the network that way so it won’t ask for this kind of Identity)
  • CA certificate : (I left this blank as well,but again this has to do with the configuration of the wireless network,so it might be different in other educational institutes)
  • Inner Authentication : PAP
  • Username : (the one given from your school)
  • Password : (the one given from your school)

android

wifi3

Identity & password = my harvard credentials.

windows

Right now I am using Windows 10, and I have discovered that the wireless situation is not really better and maybe somewhat worse than on Ubuntu. *sigh*

Anyhow, I had expired MIT credentials. I finally figured out how to change my password: Go to settings -> Wifi -> Manage known networks (this option is kind of hard to see) -> eduroam -> Forget.

wifi1

(Jeebus knows why “properties” doesn’t tell me / let me do anything useful)

Then, the next time I click on “eduroam” and “Connect”, it will prompt me for a username and password. Enter in my harvard credentials and voila.

wifi2

projects blog (nouyang)