Author Topic: Help needed for time-lapse on RPi2  (Read 1794 times)

0 Members and 1 Guest are viewing this topic.

Offline plex

  • Senior Member
  • **
  • Posts: 83
Help needed for time-lapse on RPi2
« on: January 17, 2016, 09:51:46 AM »
Hello

I'm a beginner with Raspberry Pi2, and I thought I easily could create time lapse, but I really could use some hints, or a recipe :)

Want I want to do:
Create a nice timelapse everyday - from sunrise to sunset. At sunset file video should be created, and uploaded to my website. I'm won't use a raspberry camera module, but an ip-camera.

The camera can do stills with the following format trough ftp: (here it's 1 min interval)
192.168.1.140_01_20160117100249271_TIMING.jpg
192.168.1.140_01_20160117100349274_TIMING.jpg
192.168.1.140_01_20160117100449277_TIMING.jpg

Also I can grab stills:
http://user:password@192.168.1.140/Stre ... /1/picture

Should I let the camera do the job taking stills, or is't more clever to use the pi?

What applications do I need for the job? list please :)

As far as I can google, the only encoder with gpu support is openmax - is that correct?

I recently migrated from WD to MB, so no more easy time lapse, or stills with overlay.

Thanks in advance

Offline Bushman

  • Forecaster
  • *****
  • Posts: 6682
    • Eagle Bay Weather
Re: Help needed for time-lapse on RPi2
« Reply #1 on: January 17, 2016, 10:52:36 AM »
First of all,Meteobridge does a wonderful job of overlaying text (wx vars etc.) onto stills.  Uses Imagemagick CONVERT to do it. (Which runs on the Pi BTW).

While you could use the IP cam within the Pi since it  has its own  FTP server I'd use  that to put the files into a dir.   Why complicate it using the Pi?  You need mencoder if you want a AVI file.  Get that and use this:

$mencoder -nosound -ovc lavc -lavcopts vcodec=mpeg4:aspect=16/9:vbitrate=8000000 -vf scale=1920:1080 -o tlcam.avi -mf type=jpeg:fps=24 mf://@stills.txt

Offline plex

  • Senior Member
  • **
  • Posts: 83
Re: Help needed for time-lapse on RPi2
« Reply #2 on: January 17, 2016, 03:12:58 PM »
First of all,Meteobridge does a wonderful job of overlaying text (wx vars etc.) onto stills.  Uses Imagemagick CONVERT to do it. (Which runs on the Pi BTW).

While you could use the IP cam within the Pi since it  has its own  FTP server I'd use  that to put the files into a dir.   Why complicate it using the Pi?  You need mencoder if you want a AVI file.  Get that and use this:

$mencoder -nosound -ovc lavc -lavcopts vcodec=mpeg4:aspect=16/9:vbitrate=8000000 -vf scale=1920:1080 -o tlcam.avi -mf type=jpeg:fps=24 mf://@stills.txt

Hi Bushman

I think you are leading me in the right direction. However I have some issues getting the FTP running.

Thanks for advise

Offline Bushman

  • Forecaster
  • *****
  • Posts: 6682
    • Eagle Bay Weather
Re: Help needed for time-lapse on RPi2
« Reply #3 on: January 17, 2016, 03:47:48 PM »
Run Pure-FTP on your Pi.  The camera needs some place to send its files.

Offline plex

  • Senior Member
  • **
  • Posts: 83
Re: Help needed for time-lapse on RPi2
« Reply #4 on: January 18, 2016, 12:43:46 PM »
Run Pure-FTP on your Pi.  The camera needs some place to send its files.

Got it running with proftpd - straight forward.

Now I just need to do the scripts, to automate the process :)

Good fun to play a Pi, and very learning - at least for me.

Offline Bushman

  • Forecaster
  • *****
  • Posts: 6682
    • Eagle Bay Weather
Re: Help needed for time-lapse on RPi2
« Reply #5 on: January 18, 2016, 01:56:02 PM »
Great!  I should take a look at proftpd.  Be sure to post a link to a timelapse when you get it done.

Offline plex

  • Senior Member
  • **
  • Posts: 83
Re: Help needed for time-lapse on RPi2
« Reply #6 on: January 19, 2016, 01:33:14 PM »
Great!  I should take a look at proftpd.  Be sure to post a link to a timelapse when you get it done.

I'm pretty much stucked, as I can't figure out, how to rename a bunch of files in a shell command, so I can use them for encoding the timelapse.

This is what my ip camera is giving me:
192.168.1.140_01_20160118205122254_TIMING.jpg
192.168.1.140_01_20160118205222260_TIMING.jpg
192.168.1.140_01_20160118205322262_TIMING.jpg

I want to rename them to timelapse0000.jpg, timelapse0001.jpg and so on?

HELP :oops:

I've done it moving them to my Mac, and used nameChanger, but I need to figure out a way on the Pi.

Then I use gstreamer to encode, and I'm very impresses how fast the RPI2 is with use of it's GPU. 891 files in 111 seconds into a 1920x1080 183 Mb file - yes I don't need that high resolution for a webpage ;)

Offline Bushman

  • Forecaster
  • *****
  • Posts: 6682
    • Eagle Bay Weather
Re: Help needed for time-lapse on RPi2
« Reply #7 on: January 19, 2016, 03:31:12 PM »
(Aside:  the GPU in the RPi2 is unchanged from the previous version, but if you want faster processing allocate more memory to it)

There are a couple ways to do the renaming you want (although I am not sure why you want/need to).  You can put the RENAME command  in a loop that increments the files as TIMELAPSE0001, 0002, 0003, etc.  You'll have to cron the process to fit inside the write timing.

Or you can watch the directory using the inotify-tool (sudo apt-get install inotify-tools) which contains wait and watch functions.  Then process using code of your choice (REGEX, perlexpr etc.)

Offline plex

  • Senior Member
  • **
  • Posts: 83
Re: Help needed for time-lapse on RPi2
« Reply #8 on: January 20, 2016, 01:06:37 AM »
(Aside:  the GPU in the RPi2 is unchanged from the previous version, but if you want faster processing allocate more memory to it)

There are a couple ways to do the renaming you want (although I am not sure why you want/need to).  You can put the RENAME command  in a loop that increments the files as TIMELAPSE0001, 0002, 0003, etc.  You'll have to cron the process to fit inside the write timing.

Or you can watch the directory using the inotify-tool (sudo apt-get install inotify-tools) which contains wait and watch functions.  Then process using code of your choice (REGEX, perlexpr etc.)

I've already allocated 256 Mb for the GPU.

Yes I know there´re several command to do it, but as I have 0 experience with linux, so it's not that easy.

The reason I want to rename the 1000 files everyday is simple because, I don't know how to feed the encoder with the output from my camera. It just need to start from lowest number ;)

location="timelapse%04d.jpg"

I've tried to make a list with the files, but that didn't work neither.

ls *.jpg > stills.txt
location="stills.txt"

Offline Bushman

  • Forecaster
  • *****
  • Posts: 6682
    • Eagle Bay Weather
Re: Help needed for time-lapse on RPi2
« Reply #9 on: January 20, 2016, 10:04:45 AM »
This has ZERO to do with Linux - it all logic and your choice of method:  OS, scripts, Python etc.  Here's how to do it.  :)  Execute the command below in the directory where the  JPGs are located.  Note that you need to change "$n" if you want the file names to say TIMELAPSE or whatever as this renames them 1.jpg, 2.jpg

ls | cat -n | while read n f; do mv "$f" "$n.jpg"; done

See these results from my Pi as a the full demo.

pi@raspberrypi ~/data $ ls
192.168.1.140_01_20160118205122254_TIMING.jpg
192.168.1.140_01_20160118205122255_TIMING.jpg
192.168.1.140_01_20160118205122256_TIMING.jpg
192.168.1.140_01_20160118205122259_TIMING.jpg
pi@raspberrypi ~/data $ ls | cat -n | while read n f; do mv "$f" "$n.jpg"; done
pi@raspberrypi ~/data $ ls
1.jpg  2.jpg  3.jpg  4.jpg

Offline plex

  • Senior Member
  • **
  • Posts: 83
Re: Help needed for time-lapse on RPi2
« Reply #10 on: January 20, 2016, 03:13:33 PM »
This has ZERO to do with Linux - it all logic and your choice of method:  OS, scripts, Python etc.  Here's how to do it.  :)  Execute the command below in the directory where the  JPGs are located.  Note that you need to change "$n" if you want the file names to say TIMELAPSE or whatever as this renames them 1.jpg, 2.jpg

ls | cat -n | while read n f; do mv "$f" "$n.jpg"; done

See these results from my Pi as a the full demo.

pi@raspberrypi ~/data $ ls
192.168.1.140_01_20160118205122254_TIMING.jpg
192.168.1.140_01_20160118205122255_TIMING.jpg
192.168.1.140_01_20160118205122256_TIMING.jpg
192.168.1.140_01_20160118205122259_TIMING.jpg
pi@raspberrypi ~/data $ ls | cat -n | while read n f; do mv "$f" "$n.jpg"; done
pi@raspberrypi ~/data $ ls
1.jpg  2.jpg  3.jpg  4.jpg

Thank you so much Bushman - it works perfectly. \:D/

However I don't know how to specify location with gstreamer.

If I do : location="timelapse%04d.jpg
GStreamer expect a 4 digit number starting with timelapse0000.jpg

How can I specify the right prefix?

Or can I modify your code, to adapt?

Offline Bushman

  • Forecaster
  • *****
  • Posts: 6682
    • Eagle Bay Weather
Re: Help needed for time-lapse on RPi2
« Reply #11 on: January 20, 2016, 03:37:34 PM »
I am not familiar with Gstreamer but from what little I found via Google, you can change the name of the input file.  My code would work as well, but with some minor modification to create a "mask" that fits what GS requires.  Sorry.

Offline plex

  • Senior Member
  • **
  • Posts: 83
Re: Help needed for time-lapse on RPi2
« Reply #12 on: January 23, 2016, 09:22:37 AM »
I managed to find way, and now it's running with a cron job on the pi. Video is updated every hour, and after midnight the video is becoming a yesterday movie. Video is made from 30 sec stills, from my Hikvision DS-2CD2032-I.

The only little issue I have, is some greenish in the bottom of the video - something with the encoder :???:

Here is the result - be aware my host apparently have server problems, so page can load slowly:
http://www.vejrstationen.dk/weather28/index.php?p=303&wp=MB&lang=en

The only wish I have now, is weather data and clock overlay, but I guess in not that easy.

Offline Bushman

  • Forecaster
  • *****
  • Posts: 6682
    • Eagle Bay Weather
Re: Help needed for time-lapse on RPi2
« Reply #13 on: January 23, 2016, 02:20:19 PM »
Not bad!  http://kwlug.org/node/854 for overlay example.

Offline plex

  • Senior Member
  • **
  • Posts: 83
Re: Help needed for time-lapse on RPi2
« Reply #14 on: January 25, 2016, 01:01:39 PM »
The green bar, is a problem with H264 if resolution is not dividable with 16 - if anyone should have the same problem.

I'm so impressed with the Pi doing the time lapse - about 1450 stills @ 175 Mb copied to another folder, renamed and encoded in less than 2 min - video is 122 Mb.

With my old WD display setup, it took far more time, and the CPU was stressed, on my virtual PC.

 

anything