Thread: [Fremantle Maemo5] Share your code
View Single Post
Posts: 391 | Thanked: 908 times | Joined on Aug 2011 @ suncity
#1
Hi Community!

I had some time to learn programming on my own; I like it, and I made a little script that I wanted to share. Please keep in mind, that I’m not a programmer at all, this is just my hobby.

I thought maybe we could share some of our little apps, codes, experiences to ease our and each others life a bit.

So here is mine.

I know that there are time lapse apps for n900, but I wanted to make my own, so I wrote a little script in python. Keep in mind, that this app represents my personal needs; but hey, you can modify the source code in any level, in any detail! I know that the code is probably not that beautiful, but this is my first bigger app with UI.

The program itself:
1. It has a capturing window where you can take pictures with the desired settings; and
2. a converter window, where you can make the time lapse movie. It is working with any jpg pictures in any directory, so if you copy that part of the code to another file, you can make a standalone converter app.

1. The capturing window:

On the left side you can specify the capturing, on the right side there is the viewfinder.
The buttons from left to right, top to bottom:
- “Select device”: you can specify whether you would like to use the front camera or the back camera.
- “Counter”: you can specify the number of picture you would like to be taken. If this is not set, the capturing goes “forever”. When capturing, it is also counting the number of pictures that were taken, eg. if 3 is set as max, then 3 / 1, 3 / 2, etc. If max reached, it stops.
- “Viewfinder”: you can turn the viewfinder on or off.
- “Automatic”: this captures the images within the predefined time intervals you specified with “Select framerate” button. If a maximum number was set with counter, then it stops when that number is reached; if not, then it goes “forever”. Of course you can stop it with hitting the button again; then it stops capturing.
The pictures are taken with the resolution of 640x480 (front camera) and 800x480 (back camera). You can edit this in the source code or make another button for it to be able to specify any other resolution. But keep in mind that taking pictures in higher resolutions is taking more time.
To make the viewing and capturing possible, the viewfinder is turning off when picture is taken, and then it turns on again.
First I added a countdown button to know when it is taking the pictures, but it is efficient only when the pictures are taken with another method, but for that method the viewfinder had to be off all the time, so I removed it.
Now the countdown button is not set, because I found that there is sometimes a +- 1 second difference to the time interval, maybe because of the tracker.
- “Select framerate”: you can specify the time interval (seconds) of picture-taking. Minimum is 4, maximum is 30 seconds, but you can extend it in the source code, or simply replace the picker button with entry widget.
Due to the capturing method you won’t be able to set the minimum lower, because the commands have to be executed (turn the viewfinder off, take the picture, and turn the viewfinder on) and this needs time…
There is the other capturing method I wrote first though; in that way you would be able to capture pictures in every 1, 2, or 3 seconds too, but in that way the viewfinder have to be off completely.
- “Manual”: you can capture pictures by hand, just click the button. The counting of taken pictures is working too.
- “Save as…”: you can specify the folder and the filename of the pictures. The pictures are saved in time format, so the specified filename will be showed before the time tag. Eg. If the filename is “test”, then the name of the saved file will be “test20141217_101543.jpg”
- “PyTimelapseMaker”: opens another window with the video maker.

2. Converter window:

The buttons from left to right, top to bottom:
- “Select folder”: you can specify the folder where the jpg files are. Keep in mind that all of the jpg files will be in the movie. If the folder doesn’t contain any jpg files, a message will be shown.
- “Save as”: you can specify folder and filename. The saved movie will be in avi format, no matter of the name you specify (eg. test.mp4). If you would like to use another format, you have to edit the source code (the converter command).
- “Select framerate”: you can specify the frame rate of the movie; 1 picture is the minimum, 30 pictures are the maximum (per second of course).
- “Select scale”: you can specify whether you would like to use 400x240 or 800x480. You can edit this too in the source code if you would like to extend it. But keep in mind that if the pictures are in low resolution, they won’t be better if you choose higher resolution…
- “Convert”: when everything is set, it creates the movie. There is no progress bar, the button will be “on” during the conversion. When its “light” turns off, the conversion is done.
- “Playback”: you can watch the last movie made. There is no option to select any movie, you have to use a player for that, but the last movie can be watched. If you would like to be able to choose any movie, you have to edit the source code and connect that option to the button.

As you can see, this is quite simple; I just wanted to have a user interface for the commands, so I wouldn’t have to write everything in the terminal every time.

To use the app, you have to install a mplayer that contains mencoder; so you have to compile one yourself, or use the one I’m using. Also you have to install gstreamer-tools to have gst-launch.

Please test it and feel free to tell me your impressions about it.

Cheers,

jm

EDIT: There was a little bug I found - capturing didn't work if you set the counter or the framerate (or both) above 9. Now it works.

EDIT: You can now turn the viewfinder on and off simply hitting the button (no need to the previous "press q in the terminal" option. Note that hitting the button will kill every mplayer that is opened.); and both of the cameras use the v4l2 driver so the picture of the front camera is not greenish and creepy anymore.
Attached Images
  
Attached Files
File Type: zip pytimelapse.zip (2.9 KB, 173 views)

Last edited by justmemory; 2015-02-24 at 11:03.
 

The Following 22 Users Say Thank You to justmemory For This Useful Post: