How to get camera matrix frame by frame in animation?
import bpy
import os

scn = bpy.context.scene

for f in range(scn.frame_start, scn.frame_end + 1, scn.frame_step):

    # go to frame f
    scn.frame_set(f)

    # output the camera matrix on the current frame
    mat = scn.camera.matrix_world
    print(mat)

    # set the filepath
    scn.render.filepath = os.path.join("C:/my/path/to/file/basename", str(f).zfill(4)

    # render the current frame
    bpy.ops.render.render(write_still=True)