home   >   tutorials   >   stereomorph user guide   >   12 additional features   >   12.1 extracting video frames

12.1 Extracting video frames

Since the StereoMorph digitizing application cannot read videos directly, the frames must be extracted from the videos and input to the digitizing application as images. Frames can be extracted in StereoMorph using the function extractFrames(). Before using extractFrames() be sure that you have completed the steps in installing ffmpeg so that R can read the video files. If you'd like to work through the example below, you can download an example video file here (10 MB). Note that in Safari you may have to right-click and select "Download Video" rather than using File/Save As.

1. If you are unsure of how many frames the video has or which frames you would like to extract, you can call extractFrames() without any parameters.

# Extract frames from a video
extractFrames()

The function will prompt you to enter a video file that you want to extract frames from. Either type the video file path or simply click and drag the video file into the R console and the file path will be copied over.

2. Next, the function will prompt you to ask where you want to save the extracted frames. Either type a file path to a folder or simply click and drag a folder into the R console and the file path will be copied over.

3. The function will then tell you the number of total video frames and ask you to enter the frames that you want to extract. Note that the first frame is frame 0. The example video has 100 frames total, so you can enter any frames between 0 and 99. You can specify the frames you want to extract by entering a single number, using the ":" symbol or using the c() or seq() functions:

# To extract a single frame
2

# To extract all frames between 3 and 10 (including 3 and 10)
3:10

# To extract every third frame between 5 and 20 (including 5 and 20)
seq(5, 20, by=3)

# To extract a particular set of frames
c(0, 4, 5, 9)

By default, if the number of frames you set to extract is greater than 100, the function will list all the frames to be extracted and issue a second prompt to ask if you are sure (to avoid extracting thousands of frames by mistake). This warning can be turned off by setting the warn.min parameter to any number larger than the total number of frames in the video (e.g. 1000000).

4. If you already know the input parameters in advance and want to use the function without any prompts, you can just set these parameters in the function call. Create a folder named "Frames" in your current R working directory.

5. Call extractFrames() with all the input parameters.

# Extract the first 20 frames from the example video
extractFrames(file='Example_video.mov', save.to='Frames', frames=0:19)