Free fall physics simulation capture as a video
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