This article will explain what AviSynth is and its use in field conditions, not without the help of VirtualDub, of course.
AviSynth is a non-linear video editor, controlled by scripting language or, paraphrasing, scripting language for video processing. AviSynth acts as an intermediate between the application and the physical file, allowing you to perform various transformations on the fly. A text file (AVS script), which contains various commands, many programs can open as a regular video file (VirtualDub, Adobe Premiere, Windows Media Player, Media Player Classic, e tc). Technically, AviSynth acts as a VFW (Video For Windows) codec for a text file. AviSynth supports various plugins, of which there is a huge bulk. (besides its also from VirtualDub). Download
here .
What can this give us?
- Expanding the functionality of programs for processing and playback of video. For example, adding support for previously unsupported video (and audio, by the way) formats. The use of various effects and filters;
- Automate video processing. AviSynth scripts, with the help of some other scripting language, can be generated on the fly;
- Simplify and speed up small video processing operations. Instead of crawling on the graphic menu, it is often more convenient and faster to drive a couple of small commands into a text file. In addition, in the future, this text file can be used for other sources, simply by replacing the source file name. You can create a collection of templates for frequently performed operations.
')
What is VirtualDub?
In this article I will not dwell on this wonderful editor, just note that this is a kind of penknife for video processing. Something cut off, change the track, see a small statistic, etc. This program can be done very quickly. The only thing that is insulting is that in the standard delivery the program does not understand new types of containers, but this is corrected by various forks. Download
here .
Example 1. Video compression for weak computers.
Almost all new videos are now being released in HD, but there are many users whose computers do not allow you to enjoy watching. A software solution to this situation will compress video with a lower resolution. There is a whole range of programs for this, but for the most part, they are either inconvenient, overloaded with unnecessary functionality, or convenient, but do not support the desired file formats, or cost money. With AviSynth and VirtualDub, we will learn how to handle any type of file for which DirectShow codec is installed (in other words, your Windows Media Player can play).
As an object for experiments, take Ghost in the Shell, reduce its size and make hardsub (we will embed the subtitles in the video).
Frame from source video:

We indicate AviSynth that we need to open the file using the DirectShow filter. Using the same filters, WMP opens them. Open notepad and write:
DirectShowSource("__")
I managed:
DirectShowSource("e:\Ghost In The Shell Movie 1.mkv")
Save the file with the avs extension and try to open it in VirtualDub. Although it does not support mkv in the standard package - the file will open. VirtualDub will define the content as uncompressed video. Ok, close VirtualDub, open the script and add the following line:
Lanczos4Resize(_, _)
This AviSynth command will change the size of the original video. There are several different ways to resize, some faster, others slower. You can read them in the documentation (available in Russian, by the way).
As a result, I got a script:
DirectShowSource("e:\Ghost In The Shell Movie 1.mkv")
Lanczos4Resize(800,430)
Save it and open it in VirtualDub. You will see that the picture has changed its size, in me it has become like this:

It remains to make hardsub. To do this, use the command:
TextSub(“__”)
As a result, I got the script:
DirectShowSource("e:\Ghost In The Shell Movie 1.mkv")
Lanczos4Resize(800,430)
TextSub("e:\Ghost In The Shell Movie 1.SRT")
and here is such a picture:

Everything, you can compress, for example XviD with a small bitrate and watch. However, the resulting file should not be distributed, we did it solely for personal viewing. :)
Example 2
The next task, which occurs quite often, is sticking together video files that have different bitrates, different resolutions, different formats and even, possibly, different frame rates. With AviSynth, this is done so easily that even a little offensive.
So, we have the following patients:
- Ghost in the Shell - H264, 1280x688, 23.98fps, MKV

- Teenage Mutant Ninja Turtles - XVID, 512x384, 23.98fps, AVI

- From Screw - DivX 5, 720x528, 25.00fps, AVI

In real life, there is no need to connect such a zoo, but I want to emphasize the possibilities of AviSynth.
Open the notebook and write the following:
video1 = DirectShowSource("D:\Video\Games\ \Ot Vinta. 001.avi")
video2 = DirectShowSource("E:\Ghost In The Shell Movie 1.mkv")
video3 = DirectShowSource("D:\Video\Teenage Mutant Ninja Turtles\1x01.avi")
return video1 + video2 + video3
With these commands, we created three variables of the video type, put them into one long piece and returned it for playback. If you try to run the script now, an error message will appear because the parameters of the files are different. To begin with, we will bring them to the same resolution (I will lead to 720x480), in order not to break the aspect, we will add black strips (letterbox), we will bring fps to 25 and we will bring the sample rate of sound to one value (44100).
video1 = DirectShowSource("D:\Video\Games\ \Ot Vinta. 001.avi")
video2 = DirectShowSource("E:\Ghost In The Shell Movie 1.mkv")
video3 = DirectShowSource("D:\Video\Teenage Mutant Ninja Turtles\1x01.avi")
video1 = video1.Trim(100,200)
video1 = video1.Lanczos4Resize(652,480)
video1 = video1.AddBorders(34, 0, 34, 0)
video1 = video1.ResampleAudio(44100)
video2 = video2.Trim(200,300)
video2 = video2.Lanczos4Resize(720, 388)
video2 = video2.AddBorders(0, 46, 0, 46)
video2 = video2.ConvertFPS(25)
video2 = video2.ResampleAudio(44100)
video3 = video3.Trim(400,500)
video3 = video3.Lanczos4Resize(640,480)
video3 = video3.AddBorders(40, 0, 40, 0)
video3 = video3.ConvertFPS(25)
video3 = video3.ResampleAudio(44100)
return video1 + video2 + video3
With the Trim command, I left a hundred frames from each file. Just. :)
That's all. The script is copied in just a few seconds, and time saves a whole bunch. Its execution does not require any temporary files on the disk, or terrifying amounts of RAM.
The results of its execution:



Special thanks to the
drunk user without an invite to whom this publication would not have occurred.