Free fall physics simulation capture as a video I have a project I am working on where I have objects positions randomly in the space and let them fall using rigid body simulation using python scripts and blender as (GUI-less) background. I am able to get the initial position and final position (after 500 frames). Now I would like to also generate video of the free fall of the objects from frame 1-500 into a video file as scene by the camera. 
I am able to generate images using node-editor at the end of the simulation. I am looking for a flag that is like below pseudo code.

start recording
start the free fall
end after 500 frames
stop recording


Any pointers would be of great help!
Thanks in advance.

Edit1:  To clarify more on what I want to do!
Thing to note here is that, I have single python script and I am generating 10 different scenes one after the other, where each scene has objects positions randomly. Currently I am using bake-all method to get the final state of each scene and render the scene out to see whats the final stage. Now instead of getting the final frame for all these scenes, I want to start the animation before baking each scene and render it out to a video. I want to do this for each scene one by one in the loop. 

Edit2: I guess I am in the process of figuring it out. I found out that 

bpy.ops.rigidbody.objects_add(type='ACTIVE')
bpy.ops.ptcache.bake_all(bake=True)


Does do the physics simulation before hand store it in a file. Now all I have to do is to do the below to get the animaton? I will post the results when I find it.

bpy.context.scene.camera = camera
bpy.ops.render.render(write_still=True)
I am posting a part of my code here that I believe will make sense.
After setting up the scene I do the bake_all like the below and call the render_ogl method I wrote

    scene = bpy.context.screen.scene
    scene.frame_end = 150
    scene.rigidbody_world.point_cache.frame_end = 150 #If this is not     written the simulation ends at 250 default
    scene.rigidbody_world.solver_iterations = 60
    scene.rigidbody_world.steps_per_second = 240
    scene.rigidbody_world.time_scale = 10 
    scene.rigidbody_world.use_split_impulse = 1
    bpy.ops.rigidbody.objects_add(type='ACTIVE')
    bpy.ops.ptcache.bake_all(bake=True)

    #Create the camera with respect to which rendering should be done   
    my_camera = createCamera('my_camera', (1, 1, 1), list_ob[0])
    set_camera_params(my_camera, render)

    #Set lamps to see the ogl rendering
    my_lamp = createLights('my_lamp', (15, 0, 50))
    set_lights(my_lamp)    

    #Ogl rendering
    render_ogl(my_camera, scene, fp, ind)   


The render_ogl method is as below.

def render_ogl(camera, scene, fp, ind):
    #Some scene nodes I have for the rendering
    scene.use_nodes = True
    nodes = scene.node_tree.nodes

    #Use the default nodes generated in blender 
    render_layers = nodes['Render Layers']
    output_viewer = nodes['Composite']


    #Add output file node
    output_file = nodes.new('CompositorNodeOutputFile')
    output_file.base_path = "/home/kar/Desktop/Blender_Render_Output/"

    #Link all the nodes 
    scene.node_tree.links.new(
        render_layers.outputs['Image'],
        output_viewer.inputs['Image'] 
    )

    #The settings to save the file as per the given indices
    scene.render.filepath = fp + 'zbuffer' +str(ind)
    scene.render.image_settings.file_format = 'FFMPEG'
    scene.render.image_settings.color_mode = 'BW'
    bpy.context.scene.camera = camera
    bpy.ops.render.render(animation=True)

    return