You can help with this blog by donating a small inspirational fee  

Phase 3 - Detailed processing

This is where we start processing our video materials with AviSynth. I strongly suggest to everyone who wants to get more into the matter to check out this link:
https://forum.doom9.org/showthread.php?t=161493. This is where you can find more detailed information on video restoration. What I am about to show you is a simplified version, and I will not theorize much. I will try to be more practical and show you through examples what I did and how I did it.

Since AviSynth doesn't have a GUI (graphical user interface), I will instruct it what to do through scripts, using the AvsPmod text processor. We will see the effects of our scripts in VirtualDub. As AviSynth is oriented on processing AVI files, and my materials are in MPEG format, I will have to make some extra effort to produce videos that are usable for my plan.

There are two reasons why I'm not using the AVI format. First of all, I chose not to get a telecine to copy the videos myself, frame by frame, to produce AVI files. This would generate materials that are of much better quality, but this would produce very large video files, that are not appropriate for my photo/video album, and so this is the number two reason why I'm not using the AVI format.

At first, while I was still getting acquainted with all the procedures of video processing, I generated AVI files directly from VirtualDub, which only has that one option to save files as AVI. I would load a MPEG file with a script and export it as AVI. I quickly realized this was a bad idea. I got nothing on the quality, because the input material (MPEG) was lower quality than that which enables AVI format, and AVI files also quickly ate through all my free disk space. For each 4 minute film roll I would produce approximately 7 GB of disk space with AVI format.

Thanks to the huge AviSynth internet community I easily found a way to avoid this problem - QuEnc (https://sites.google.com/site/dragongodz2/home), which is also part of the Start package. This is a free and simple to use encoder that will transcode videos using AVS script file into MPEG2 (when the video contains audio as well) or M2V video format (for situations when there is no audio). This is how I avoided producing AVI files and then manually converting them to MPEG2.

Let's see what I found in my video materials, and how I repaired damaged videos using AviSynth. Most of the materials that I gathered were damaged in different ways, so I naturally wanted to fix all that before I archived it all.

Some of the most obvious damages to the video materials were dirt on the film, spots, all kinds of smudges and scratches, but also there was different kinds of shaking. You can see the examples in the video below. Other than that I mostly used some color corrections, dynamic corrections of the brightness (Dynamic Gain Control), removing noise (denoising), sharpening, etc.

Dirt mostly occurs during filming phase, when dust enters the video camera, but also dirt can get stuck on the film during reproduction. Wet cleaning the film before transferring using a telecine can get some of that dirt off, but the dirt that was actually recorded on the film because the camera was dirty in the first place cannot. The only way to "clean" them up is using the computer based video processing. This process will also remove some smaller scratches that occurred on the film emulsion by bad film handling. Here is one example of such video material:

Removing dirt

Once AviSynth is installed, including all the tools and plugins, I had to assemble a script to clean up some dirt and spots from my video clips. Of course, I wasn't the one to make all that cleaning tools, because I have no idea how to do that, but instead I used a ready-made solutions that I found on the link mentioned above. I found many things to be confusing and difficult to understand, but eventually I found a solution that satisfied me, so I didn't bother much with details. Later on I adjusted some parameters to my needs. All that I will share here with you. This is why I created the subfolder "0-Processing" and placed it in the Start package. I created the 0-Processing.zip package and placed the clip above in it, and called it "Master_file.mpg". Once you unpack the zip into your start package folder, you should open a new subfolder. To simplify my video processing I created three batch files, with each of them running the tools we need for each step of the processing. In order for you to see how filtering works according to my model, you can start the processing.

First step is to start the Master_file.bat file (double-click it). It will run DGIndex.exe and index the MPEG file and prepare it for further processing with AviSynth.

Next step is to open the "frame_rate.avs" video and run it in preview mode (Shift+F5). Using right arrow on your keyboard check if the frame rate matches that of the video material you're processing (follow the instructions form the script). Change the "my_frame_rate" variable if necessary. Don't forget to save your changes to the script (Ctrl+S). If the videos you are processing were filmed using the same speed, then this step you need to do only once. Now that I have matched the frame rate of my materials, we don't need to update the frame rate for the test clip.

Now go to the folder "1-remove dirt". There are two batch files here, which you should run in order as indicated by their name.

Run the "1-Encoding.bat", which will open QuEnc. Here you should click the Encode button. Once it's finished you will end up with a cleaned up video that has M2V extension. This is a MPEG2 file but without any audio tracks within.

Since we generated a quasi-25fps file for processing purposes (the real frame rate is identical to the camera shutter speed - 16 fps in my case), we need to convert it into real 25fps which is needed by the MPEG2 format. This is what we'll use DGPulldown for.

Now, run "2-Frame rate correcting.bat", which will start the conversion into real 25fps, but you need to specify which file to convert. First click on "Browse", and then find your M2V file (1-remove dirt\remove_dirt.m2v). Then select "Custom" option. In first field type in your original frame rate (in my case this was 16.6666), and then type in 25 into the second field (for MPEG2, Video PAL 720x576, 4:3, 25fps). Click on Convert. Shortly after that you will end up with cleaned up and valid video file called "Remove_dirt.m2v.pulldown.m2v". By doing this we fixed our speedy video - the Charlie Chaplin effect that we got after our first step - "Remove_dirt.m2v".

Every clip that I wanted to clean up I had to rename into "Master_file.mpg" and copy it over the previous file in the "0-Processing" folder, and repeat the steps all over. Before you do that remember to rename or copy the "Remove_dirt.m2v.pulldown.m2v" somewhere so that later you know what each file is. If you don't do this, next processing will overwrite your file without a warning. Same thing happens with QuEnc as well. In this case we don't lose much by losing it's output file, but later on it will be useful to know this. With QuEnc there is another little trap - the script file name must not be same as the name of the clip we're processing. Having the same name is a bad idea because it will overwrite your clip file and freeze up. And then, if you don't have a backup master file, you're doomed to go back to transferring step. This happened to me a couple of times before I learned my lesson 😊.

In case that you are not planning to add any audio to the file, you can just rename it into a MPG file. However, I add an audio background every time, even if I silence it down to 0. This way I'm pretty sure that all players will be able to play my files.

Now let's take a look at the "remove_dirt.avs" script. If you open it up, you will see that I implemented several levels of video filtering (test clip is set up to 5 passes max). I have done this because not all my materials I worked with were equally damaged, and each level of filtering slows the processing down significantly. I use PassX5 only for very badly damaged videos. Choosing your filtering level is easy - instead of X5 type in X1, 2, 3 or 4. Just as with "film frame_rate.avs"; open the preview mode with Shift+F5 and use your keyboard arrows to scroll through the video and decide which level suits you best. Don't forget to save your changes before you run "1-Encoding.bat".

Video tutorial on how to clean up your video


Popular posts from this blog

Mpg2Cut2 - clipping the mpeg files

Phase 2 - Identifying and clipping