×
Namespaces

Variants
Actions
Revision as of 16:26, 25 September 2009 by nayan_trivedi (Talk | contribs)

Archived:How to record video with PySymbian

From Nokia Developer Wiki
Jump to: navigation, search
{{{width}}}


Article Metadata
Tested with
Devices(s): Nokia N95, Nokia E90
CompatibilityArticle
Keywords: camera
Created: (21 Mar 2008)
Last edited: nayan_trivedi (25 Sep 2009)

Contents

Overview

This snippet shows how to record video in Python.

Preconditions

Note: The camera module is not available for S60 1st Edition.

Valid file formats must be used. Their availability may vary from one device generation to another and they tipically include 3GP, MP4.

Source code

import appuifw, e32, camera
 
 
app_lock = e32.Ao_lock()
#Define the exit function
def quit():
#Cancel the timer when the user exits, if it has not expired
t.cancel()
#Close the viewfinder
camera.stop_finder()
#Release the camera so that other programs can use it
camera.release()
app_lock.signal()
appuifw.app.exit_key_handler = quit
 
#Function for displaying the viewfinder
def vf(im):
appuifw.app.body.blit(im)
 
def video_callback(err, current_state):
global control_light
if current_state == camera.EPrepareComplete:
control_light=1
else:
pass
 
video_savepath = u"C:\\vid.mp4"
#This is the path and name of the video to be recorded
 
appuifw.app.body = appuifw.Canvas()
 
#Start the viewfinder
camera.start_finder(vf)
#Start recording
vid = camera.start_record(video_savepath, video_callback)
#Instantiate a timer
t = e32.Ao_timer()
#Record for 10 seconds, then stop
t.after(10, lambda:camera.stop_record())
 
#Wait for the user to request the exit
app_lock.wait()

Postconditions

The viewfinder will be displayed on the device's screen and a video clip will be recorded to the specified path for the specified duration (note that due to hardware capabilities and processes executed, the actual duration of the recorded clip may vary). Recording will automatically stop after that duration and the script will wait for the user to exit.

78 page views in the last 30 days.