You can do this using the compositor.
All you need is to prepare a simple node setup where you have a
Movie Clip (Input) Node connected to the
Composite (Output) Node. Load your video into the movie clip node, set a few small params in the script below (namely the output folder where you'd like to save the extracted frames and the frame range), and run the script.
The script will copy the video dimensions and set up your render settings accordingly (but will not alter the output file format).
from os.path import join
S = bpy.context.scene
n = S.node_tree
vidNode = n.nodes['Movie Clip']
# Set Render Settings dimensions according to video
S.render.resolution_percentage = 100
S.render.resolution_y = vidNode.clip.size
S.render.resolution_x = vidNode.clip.size
# Render desired frame numbers ( UPDATE THESE AS NEEDED )
start = 5
end = 200
step = 3
frame_numbers = range(start, end, step)
outputFolder = "C:/tmp/test" # <=== Update this
for f in frame_numbers:
S.frame_set( f )
fileName = str(f) + S.render.file_extension
S.render.filepath = join( outputFolder, fileName )
bpy.ops.render.render( write_still = True )
Copy this to a new text file in the text editor, change the values in the
outputFolder variable and the
step for generating frame_numbers, and press "Run Script".
If you'd like, you can also automate the creation of the node setup and load the video to the movie clip node; there are several nice answers here in StackExchange showing how to create and manipulate nodes via python.