Thursday, October 25, 2007

Frames

The work of all of the previous code was simply to find the centers of the sprockets. Now that you have them, it is a simple exercise in mathematics to locate the frames.

In general, regular 8mm frames are found between sprockets while super 8 frames are found at the center of the sprockets. With the frame & sprocket dimensions known (see the Background tutorial), the corners of the frames are found at the following coordinates (in x, y format):
R8:
1. Center of sprocket, Lower sprocket edge
2. Center of sprocket + Frame Height, Lower sprocket edge
3. Center of sprocket + Frame Height, Lower sprocket edge + Frame Width
4. Center of sprocket, Lower sprocket edge + Frame Width

S8:
1. Center of sprocket - 1/2 Frame Height, Lower sprocket edge
2. Center of sprocket + 1/2 Frame Height, Lower sprocket edge
3. Center of sprocket - 1/2 Frame Height, Lower sprocket edge + Frame Width
4. Center of sprocket + 1/2 Frame Height, Lower sprocket edge + Frame Width
I wanted to keep my films and frames in a standard aspect ratio (about 1.33:1) for viewing on the TV or computer, so the frame dimensions above were adjusted to give specific pixel dimensions at 4800 dpi:

R8: 960 x 720 pixels
S8: 1104 x 792 pixels

Each frame is saved individually as a BMP file with the name formatted to reflect the sequence of frames in the film as follows: mm.ss.ff.bmp where mm is the minute, ss is the second, and ff is the frame. A typical frame in a large reel could be 23.13.09.bmp which is the 9th frame of the 13th second of the 23 minute of the film. Remember that R8 was filmed at 16 fps and S8 was filmed at 18 fps.

As each camera exposing the film was different, some interesting differences between films developed. One interesting variation from film to film is the position of the frame in relation to the sprocket. Sometimes the relationship between the center of the sprocket and edge of the frame is off from expected by as much as 30 - 40 pixels. In the example below, the frame and sprocket are off by 20 pixels as seen by the blue outline of the frame representing the expected location of the sprocket. (Aren't I cute? Early Summer 1982)

In the next images, the frame location was adjusted 20 pixels.Note that in the second frame shown above, the image fills the entire frame and is not cropped as in the first frame above.

Originally, I was converting all of the *.bmp frames to *.jpg using Adobe Photoshop Elements, but it was time consuming. I found I could save 2/3 of the time if I simply added 6 additional lines of code and converted the images to *.jpg format right after saving them as *.bmp. Since the images are already loaded into memory at this point, it is easy and fast to convert them. The necessary code is:

Imports System.Drawing
Imports System.Drawing.Imaging

Dim fbm as Bitmap
Dim jcinfo As ImageCodecInfo
Dim jqual As EncoderParameter
Dim jparams As EncoderParameters
Dim j As Integer
Dim encoders() As ImageCodecInfo

encoders = ImageCodecInfo.GetImageEncoders()
j = 0
While j <>
If encoders(j).FormatID = ImageFormat.Jpeg.Guid Then jcinfo = encoders(j)
j += 1
End While
jqual = New EncoderParameter(Encoder.Quality, CType(100L, Int32))
jparams = New EncoderParameters(1)
jparams.Param(0) = jqual
fbm = New Bitmap("c:\YourDirectory\YourFileName.bmp")
fbm.Save("c:\YourDirectory\YourFileName.jpg", jcinfo, jparams)

I found that converting these files with Adobe Photoshop Elements 4.0 requires about 30 seconds for the film strip and the individual frames, but only adds about 7 seconds to the overall process when done in the manner described above.
After the frames are captured and saved, they must be compiled into an AVI file.

No comments: