I Love Electricity

Encoding an AVI with field dominance changes at scene cuts

The Problem (Short form): Encoding an AVI with field dominance changes at scene cuts

The Problem (Long Form): An AVI is captured from VHS using an analog video capture card at 29.97 FPS, 720×480 resolution. When played on the computer, it is interlaced and looks like it should. When converted to MPEG2 for DVD, and played back on a TV, the video may be fine, and when the scene changes, the video starts to go jumpy. This is because the capture card duplicated a field. For some reason, when the video camera was turned off on the VHS movie, the video capture card messed up and actually added a redundant field and this causes the field dominance to change for the rest of the movie. It may change back at a scene change down the road. We don’t want to deinterlace it because it will be played back onto an interlaced TV, and deinterlacing cuts the frame rate in half, effectively.

The Solution (Short Form): Use AVISynth to Separate the fields into a 60FPS movie. Delete a frame (which is in actuality a single field now). Then use a Weave command to weave them back together. This effectively deletes the bad field and corrects the field order for the rest of the movie which can be encoded to MPEG2 and displays just right on a TV.

The Solution (Long Form): Obtain AVISynth and TmpegEnc (or VirtualDub), both of which are free. Now, create an AVS script which has the commands to LoadAVI(original_filename.avi), and SeparateFields() immediately following the open command. Save the AVS file and load it into TmpegEnc. Go into Settings and then Advanced, go to Source Range, and go through the movie until you find the bad frame. It will appear squished which is normal since the fields are serial now instead of interlaced. The bad frame will often be a blip back to the previous scene after the second scene has started. Take note of the frame number in the upper left corner. Now go back to your AVS file and add the line DeleteFrame() and put the frame number obtained in the previous step into the parenthesis. After that, add the command Weave(). Save the AVS file and load it back into TmpegEnc. Go back into source range and notice that the bad field has been removed. Use the Deinterlace, Odd/Even option in the Advanced screen to determine the field order. Hold down the right arrow key to “play” the movie back. If it is smooth, the field order is correct, if it is jumpy, change the field order in the Advanced screen. Check random intervals throughout to make sure the field order does not change any more. If it does, repeat the steps to delete the bad field at the scene change. Encode it and all should be well.

Possible Side Effect: For each field removed from the source video, the audio will be de-synced by 1/60th of a second. This will not be noticeable if you only have to remove a couple of fields. If you must remove more, you’ll have to use AVISynth’s Trim command instead of DeleteFrame. The command works like this: Trim(0,N) ++ Trim(N,0) where N is the frame to be removed. You can also edit the audio later on to remove 1/60th of a second of it at the same point where the bad field was located.

It took me weeks of fiddling (a total of over 100 hours) to arrive at this solution. I had tried every possible filter I could find for VirtualDub, and who knows how many experiments and DVD-RW burns until I arrived at the above solution.