Make other file ops than save/load use different dialog
[jpcrr.git] / scripts / encode.lua
blobe405957730fba9de80557988b40493083b35d31b
1 #!/usr/bin/env lua
2 rate = 44100;
3 aspect = "5:6";
4 speaker = false;
5 pcm = false;
6 fm = false;
7 outputs = 0;
8 crf = nil;
9 finalmode = false;
10 finalmodee = false;
12 for i, value in ipairs(arg) do
13 if string.sub(value, 1, 6) == "width=" then
14 width = tonumber(string.sub(value, 7, #value));
15 end
16 if string.sub(value, 1, 7) == "height=" then
17 height = tonumber(string.sub(value, 8, #value));
18 end
19 if string.sub(value, 1, 5) == "rate=" then
20 rate = tonumber(string.sub(value, 6, #value));
21 end
22 if string.sub(value, 1, 4) == "crf=" then
23 crf = tonumber(string.sub(value, 5, #value));
24 end
25 if string.sub(value, 1, 7) == "aspect=" then
26 aspect = string.sub(value, 8, #value);
27 end
28 if value == "final" then
29 finalmode = true;
30 end
31 if value == "finale" then
32 finalmodee = true;
33 end
34 end
35 if not width or not height or not rate then
36 error("Valid width, height and rate needed (rate has default)");
37 end
39 if not crf then
40 if finalmode or finalmodee then
41 crf = 20
42 else
43 crf = 25
44 end
45 end
47 print("Width: " .. width);
48 print("Height: " .. height);
49 print("Rate: " .. rate);
51 io.stdout:write("Creating src video pipe...");
52 os.execute("rm -f video.src");
53 os.execute("mkfifo video.src");
54 print("Done.");
56 io.stdout:write("Creating src audio pipe...");
57 os.execute("rm -f audio.src");
58 os.execute("mkfifo audio.src");
59 print("Done.");
61 io.stdout:write("Creating RGB video pipe...");
62 os.execute("rm -f video.rgb");
63 os.execute("mkfifo video.rgb");
64 print("Done.");
66 io.stdout:write("Creating YUV video pipe...");
67 os.execute("rm -f video.yuv");
68 os.execute("mkfifo video.yuv");
69 print("Done.");
71 io.stdout:write("Checking if PC speaker output is present...");
72 file = io.open("speaker.dump", "r");
73 if file then
74 print("Yes.");
75 file:close();
76 speaker = true;
77 outputs = outputs + 1;
78 else
79 print("No.");
80 end
83 io.stdout:write("Checking if PCM output is present...");
84 file = io.open("pcm.dump", "r");
85 if file then
86 print("Yes.");
87 file:close();
88 pcm = true;
89 outputs = outputs + 1;
90 else
91 print("No.");
92 end
94 io.stdout:write("Checking if FM output is present...");
95 file = io.open("fm.dump", "r");
96 if file then
97 print("Yes.");
98 file:close();
99 fm = true;
100 outputs = outputs + 1;
101 else
102 print("No.");
105 if speaker then
106 print("Converting PC speaker audio...");
107 if finalmode then
108 os.execute("xterm -e sh -c \"cat logoaudio.dump speaker.dump >audio.src \" &");
109 filename = "audio.src";
110 else
111 filename = "speaker.dump";
114 os.execute("rawtoaudio2.exe --input-file=" .. filename .. " --input-format=pcm --output-file=speaker.wav --output-format=wav --output-attenuation=20 --output-rate=" .. rate);
115 print("Done.");
118 if pcm then
119 print("Converting PCM audio...");
120 if finalmode then
121 os.execute("xterm -e sh -c \"cat logoaudio.dump pcm.dump >audio.src \" &");
122 filename = "audio.src";
123 else
124 filename = "pcm.dump";
127 os.execute("rawtoaudio2.exe --input-file=" .. filename .. " --input-format=pcm --output-file=pcm.wav --output-format=wav --output-rate=" .. rate);
128 print("Done.");
131 if fm then
132 print("Converting FM audio...");
133 if finalmode then
134 os.execute("xterm -e sh -c \"cat logoaudio.dump fm.dump >audio.src \" &");
135 filename = "audio.src";
136 else
137 filename = "fm.dump";
140 os.execute("rawtoaudio2.exe --input-file=" .. filename .. " --input-format=fm --output-file=fm.wav --output-format=wav --output-rate=" .. rate);
141 print("Done.");
144 if outputs > 0 then
145 command = "sox ";
146 if outputs > 1 then command = command .. "-m "; end
147 if speaker then command = command .. "speaker.wav "; end
148 if pcm then command = command .. "pcm.wav "; end
149 if fm then command = command .. "fm.wav "; end
150 command = command .. "soundtrack.ogg";
151 io.stdout:write("Mixing soundtrack...");
152 os.execute(command);
153 print("done.");
156 io.stdout:write("Launching logo insertion...");
157 if finalmode then
158 os.execute("xterm -e sh -c \"cat logovideo.dump video.dump >video.src \" &");
159 else
160 os.execute("xterm -e sh -c \"cat video.dump >video.src \" &");
162 print("done.");
164 io.stdout:write("Launching video conversion...");
165 os.execute("xterm -e rawtorgb.exe video.src video.rgb lanczos2 " .. width .. " " .. height .. " 16666667 &");
166 print("Done.");
168 io.stdout:write("Launching RGB->YUV conversion...");
169 os.execute("xterm -e mencoder -nosound -vf format=i420 -ovc raw -of rawvideo -o video.yuv -demuxer rawvideo -rawvideo w=" .. width .. ":h=" .. height .. ":fps=60:format=rgb32 video.rgb &");
170 print("Done.");
172 for i=1,50000000 do end
174 print("Launching encoder process...");
175 if finalmode or finalmodee then
176 os.execute("x264 --ssim --crf " .. crf .. " --keyint 600 --ref 16 --mixed-refs --no-fast-pskip --bframes 16 --b-adapt 2 --mbtree --weightb --direct auto --subme 10 --trellis 2 --partitions all --me esa --merange 128 --rc-lookahead 250 --fullrange on --threads 6 --8x8dct --no-dct-decimate --sar " .. aspect .. " --fps 60 -o videoonly.mkv video.yuv " .. width .. "x" .. height);
177 else
178 os.execute("x264 --preset slow --threads 8 --crf " .. crf .. " --merange 96 --me umh --sar " .. aspect .. " --fps 60 -o videoonly.mkv video.yuv " .. width .. "x" .. height);
180 print("Done.");
183 print("Muxing the MKV...");
184 if finalmode then
185 os.execute("mkvmerge -o final.mkv videoonly.mkv soundtrack.ogg");
186 else
187 os.execute("mkvmerge -o final-wip.mkv videoonly.mkv soundtrack.ogg");
189 print("Done.");