1var _outputSizeX = 320;
2var _outputSizeY = 240;
3var _sourceDir = "C:/Test/input/";
4var _sourceFileExt = "*.avi";
5var _destinationDir = "C:/Test/output/";
6
7function processFile(inputPath, outputDirectory)
8{
9    Editor.openVideo(inputPath);
10
11    // Resize filter
12    var targetX = _outputSizeX;
13    var targetY = _outputSizeY;
14    var width = Editor.videoFileProperties[0].width;
15    var height = Editor.videoFileProperties[0].height;
16
17    var rX = width / targetX;
18    var rY = height / targetY;
19    var newX;
20    var newY;
21
22    if (rX > rY)
23    {
24        // resize by X
25        newX = targetX;
26        newY = Math.round(height / rX);
27    }
28    else
29    {
30        // resize by Y
31        newY = targetY;
32        newX = Math.round(width / rY);
33    }
34
35    // resize to multiple of 4
36    newX -= newX % 4;
37    newY -= newY % 4;
38
39    if (newX != width || newY != height)
40    {
41        var videoFilter = new SwscaleVideoFilter();
42
43        videoFilter.configuration.width = newX;
44        videoFilter.configuration.height = newY;
45
46        Editor.appliedVideoFilters.add(videoFilter);
47    }
48
49    // Black bar filter
50    var barX = targetX - newX;
51    var barY = targetY - newY;
52
53    if (barX || barY)
54    {
55        var videoFilter = new AddborderVideoFilter();
56
57        videoFilter.configuration.left = barX >> 1;
58        videoFilter.configuration.right = barX >> 1;
59        videoFilter.configuration.top = barY >> 1;
60        videoFilter.configuration.bottom = barY >> 1;
61
62        Editor.appliedVideoFilters.add(videoFilter);
63    }
64
65    // Video encoder
66    Editor.currentVideoEncoder = Xvid4VideoEncoder;
67
68    // Audio output
69    Editor.audioOutputs.clear();
70
71    audioOutput = new FaacAudioEncoder();
72    Editor.audioOutputs.add(0, audioOutput);
73
74    if (Editor.videoFileProperties[0].audioProperties.channels != 2)
75    {
76        Editor.audioOutputs[0].mixer = AudioOutput.MixerMode.StereoMix;
77    }
78
79    // Muxer
80    Editor.currentMuxer = Mp4v2Muxer;
81
82    // Clip source extension and save to destination with default muxer extension
83    var directory = new Directory(outputDirectory);
84
85    if (!directory.exists)
86    {
87        directory.makePath(outputDirectory);
88    }
89
90    Editor.saveVideo(outputDirectory + new FileInformation(inputPath).baseName + "." + Editor.currentMuxer.defaultFileExtension);
91}
92
93function processDirectory(inputDirectory, inputExt, outputDirectory)
94{
95    var entryInfoList = new Directory(inputDirectory).entryInfoList(
96        [inputExt],
97        Directory.Filter.AllDirectories | Directory.Filter.Files | Directory.Filter.Readable | Directory.Filter.NoDotAndDotDot,
98        Directory.Sort.NoSort);
99
100    for (var index = 0; index < entryInfoList.length; index++)
101    {
102        var fileInfo = entryInfoList[index];
103
104        if (fileInfo.isDirectory())
105        {
106            processDirectory(fileInfo.absoluteFilePath, inputExt, outputDirectory + fileInfo.baseName);
107        }
108        else
109        {
110            processFile(fileInfo.absoluteFilePath, outputDirectory);
111        }
112    }
113}
114
115processDirectory(_sourceDir, _sourceFileExt, _destinationDir);