You Are Here:

Community: Developer Discussion Boards

#1 Old Unhappy How to continuosly capture the display? - 2005-08-12, 02:56

Join Date: Aug 2005
Posts: 6
iccananea
Offline
Registered User
pyS60 version: 1.1.6 (FAST sis)
using graphics module for screenshot

I´m writing an app that takes screenshots of current display and save the imagens as a jpg in a given directory. I´ve tried 3 aproaches:

1) Append each screenshot to a list and save everything in the end

2) Save each screenshot as soon as it is captured

3) Spawn a new thread to save the new screenshot

solution 1 works fairly well, but only for a few seconds (depends on the desired FPS) before it fills up the phone memory, leading to a system crash

solution 2 works but is VERY slow (< 1FPS) because writing the jpg is slow.

solution 3 crashes every time. Wasn´t able to discover why because I´m using the emulator and it aborts.

I may be able to get more information using the bt_console, but I´m still waiting for my bluetooth dongle to arrive

Anyway, has anybody run into a problem using threads to perform any tasks? Is there another way to acomplish this?

Thanks in advance!
Reply With Quote

#2 Old Re: How to continuosly capture the display? - 2005-08-12, 10:38

Join Date: Dec 2004
Posts: 646
jplauril's Avatar
jplauril
Offline
Forum Nokia Expert
Quote:
Originally posted by iccananea
pyS60 version: 1.1.6 (FAST sis)
using graphics module for screenshot

I´m writing an app that takes screenshots of current display and save the imagens as a jpg in a given directory. I´ve tried 3 aproaches:

1) Append each screenshot to a list and save everything in the end

2) Save each screenshot as soon as it is captured

3) Spawn a new thread to save the new screenshot

solution 1 works fairly well, but only for a few seconds (depends on the desired FPS) before it fills up the phone memory, leading to a system crash

solution 2 works but is VERY slow (< 1FPS) because writing the jpg is slow.

solution 3 crashes every time. Wasn´t able to discover why because I´m using the emulator and it aborts.
Could you post your code for solution 3? If there's a bug in the graphics module, we'd like to know about it.
Quote:

Anyway, has anybody run into a problem using threads to perform any tasks?
The most common mistake is to use native resources from the wrong thread.
Quote:

Is there another way to acomplish this?
Have you tried saving the screenshots as PNG files with the fastest compression mode?
Reply With Quote

#3 Old 2005-08-12, 14:28

Join Date: Aug 2005
Posts: 6
iccananea
Offline
Registered User
Quote:
Could you post your code for solution 3? If there's a bug in the graphics module, we'd like to know about it.
Sure:

Code:
def saveimage(img, frame, basedir, basename):
    name = '%s\\%s%.5d.jpg' % (basedir, basename, frame))
    img.save(name, quality=40)

while not stop:
    img = graphics.screenshot()
    thread.start_new_thread(saveimage, (frame, basedir, basename))
This is the basic loop; there is more code to control FPS using a Ao_lock, but I think that will do. I also didn't include the variables and imports

Quote:
The most common mistake is to use native resources from the wrong thread
Yeah, I read about that but I'm actually having problems with threads in large. There is a code snippet in the docs showing how to import modules in parallel using threads. I've tried it on the emulator (importing modules that I wasn't going to use) and sometimes (almost always) it crashes. I havn't tried it on my phone (nokia 6600) but I'll give it a shot

Quote:
Have you tried saving the screenshots as PNG files with the fastest compression mode?
No. I'll try it then

Thanks!
Igor
Reply With Quote

#4 Old 2005-08-12, 14:43

Join Date: Dec 2004
Posts: 646
jplauril's Avatar
jplauril
Offline
Forum Nokia Expert
Actually, the Ao_lock code is a very crucial part of the code, so posting that would be useful.
Reply With Quote

#5 Old 2005-08-17, 22:11

Join Date: Aug 2005
Posts: 6
iccananea
Offline
Registered User
Quote:
Actually, the Ao_lock code is a very crucial part of the code, so posting that would be useful.
I agree, but I still think the problem is with the thread library. For example, there is this code snippet in the Programming with Python for Series 60 pdf suplied with the sdk:

Code:
import thread

def import_modules():
    import bt_console
    import time
thread.start_new_thread(import_modules, ())
...
The code goes on but the fact is I copied the code and tested it on the emulator and my phone (nokia 6600). The emulator crashes and on the phone the script crashes and after a while the python app.

As for the the Ao_lock code, I will post it as soon as get home (I'm currently at work).

Just for the record, I'm using Python 1.1.6 pre-alpha and the Python SDK 2ed.

Thanks.
Reply With Quote

#6 Old 2005-08-17, 22:13

Join Date: Aug 2005
Posts: 6
iccananea
Offline
Registered User
Quote:
I´m writing an app that takes screenshots of current display and save the imagens as a jpg in a given directory. I´ve tried 3 aproaches:

1) Append each screenshot to a list and save everything in the end

2) Save each screenshot as soon as it is captured

3) Spawn a new thread to save the new screenshot

solution 1 works fairly well, but only for a few seconds (depends on the desired FPS) before it fills up the phone memory, leading to a system crash

solution 2 works but is VERY slow (< 1FPS) because writing the jpg is slow.

solution 3 crashes every time. Wasn´t able to discover why because I´m using the emulator and it aborts.
By the way, I did change my code to save using png and fast compression for solution 2. I did speed things up a bit but it is still too slow (jumped from 0.1 FPS to 0.5 FPS).
Reply With Quote

#7 Old 2005-08-18, 09:27

Join Date: Dec 2004
Posts: 646
jplauril's Avatar
jplauril
Offline
Forum Nokia Expert
I verified that there is a bug in the graphics module w.r.t thread support: at least Image.new fails when done in a non-UI thread. We'll look into it.
Reply With Quote

#8 Old 2005-08-19, 02:02

Join Date: Aug 2005
Posts: 6
iccananea
Offline
Registered User
Quote:
I verified that there is a bug in the graphics module w.r.t thread support: at least Image.new fails when done in a non-UI thread. We'll look into it.
Thank you I'm looking forward to it.
Reply With Quote

#9 Old Re: How to continuosly capture the display? - 2007-01-08, 10:11

Join Date: Jan 2007
Posts: 1
gbhavani
Offline
Registered User
Hi,

I also would like to write a script that could capture the screenshots for every few milli seconds. I tried the first two options. But its still slow. Is it possible to capture more frames per second(more than five) if threads are used. I have tried using the threads. But I could not get it working. Can anyone give me some hints on writing this script by using threads.

br,
Bhavani
Reply With Quote
Reply « Previous Thread | Next Thread »
Display Modes
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules

You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

Rate This

 
Bookmark this page: DeliciousDiggFacebookGoogleYahooStumbleUponRedditDiigoTechnocratiTwitter  Share this page Share this page Print this Page Print this page Invite a friend Invite a friend
京ICP备05048969号    Email Newsletters Press Terms & Conditions Privacy Policy Sitemap Contact Us © 2009 Nokia