12.2 Extracting synchronized frames
If you are extracting frames from two or more videos that are not synchronized you might want to make sure that the extracted frames have the same names. By default, extractFrames() will name the extracted frames the name of the corresponding frame (i.e. frame 50 of a video will be named "000050.jpeg"). extractFrames() adds enough zeros to the start of the name to maintain the same filename length for all frames.
However, if two videos are not synchronized but you know the time offset (e.g. 30 frames) you might want to extract frames 0-49 from one video and frames 30-79 from the second video. If you were to do this, the names of the extracted images from the first video would be "000000.jpeg" to "000049.jpeg" and those from the second video would be "000030.jpeg" to "000079.jpeg". In order to "synchronize" the video frames we can name both sets "000000.jpeg" to "000049.jpeg". To override the default names created by extractFrames(), you can use the names parameter.
For example, the following command will extract frames 30-79 and name them "000000.jpeg" to "000049.jpeg". The formatC() function is used to add leading zeros to the numbers 0:49 to create a string of width, width.
# Extract the first 50 frames from the example video extractFrames(file='Example_video.mov', save.to='Frames', frames=30:79, names=formatC(0:49, width=6, format='d', flag='0'))
StereoMorph currently does not contain any special tools to determine the time/frame offset between two videos. However, one simple way to determine this offset is to turn on and off a light in view of the cameras. You can then use the extractFrames() function to narrow down and identify the on/off frame in each view and thereby determine the offset.