let
ffmpeg = plugins.load(
'org.autojs.plugin.ffmpeg'
);
console.show()
var
lock = threads.lock();
path_o =
"/storage/emulated/0/VideoFactory/"
const regex = /.*?mp4$/i;
arrpat = sz(path_o, regex)
arr_mp3 = []
for
(i
in
arrpat) {
arr_mp3.push(path_o + arrpat[i]);
}
arr_fz = z指定分组(arr_mp3, 5)
arr_fz2 = z指定分组(arr_fz, 3)
log(arr_fz.length)
log(arr_fz2.length)
xr(jcht(arr_fz2),
"./123.js"
)
for
(f2
in
arr_fz2) {
processWithThreads(arr_fz2[f2], arr_fz2[f2].length)
console.warn(
"一组线程执行完毕"
)
}
function
processWithThreads(arr_fz, threadCount) {
var
arrLength = arr_fz.length;
if
(threadCount > arrLength) {
threadCount = arrLength;
}
var
threadsArray = [];
for
(
var
i = 0; i < threadCount; i++) {
(
function
(index) {
var
thread = threads.start(
function
() {
var
path_out =
"/storage/emulated/0/VideoFactory/11/"
+ (index + 1) +
".mp4"
;
lock.lock();
mn = index
nx:
while
(1) {
if
(files.exists(path_out)) {
mn++
path_out =
"/storage/emulated/0/VideoFactory/11/"
+ mn +
".mp4"
;
}
else
{
break
nx;
}
}
var
m = FFmpeg命令构建(arr_fz[index], path_out);
files.createWithDirs(path_out)
log(path_out)
lock.unlock();
let
result = ffmpeg.inProcess.exec(m);
});
threadsArray.push(thread);
})(i);
}
for
(
var
j = 0; j < threadsArray.length; j++) {
try
{
console.error(
"线程等待: "
+ j);
threadsArray[j].join();
}
catch
(e) {
console.error(
"线程等待出现异常: "
+ e);
}
}
}
function
sz(path, regex) {
return
files.listDir(path,
function
(name) {
return
regex.test(name);
});
}
function
z指定分组(arr, groupSize) {
result = [];
for
(
let
i = 0; i < arr.length; i += groupSize) {
endIndex = Math.min(i + groupSize, arr.length);
result.push(arr.slice(i, endIndex););
}
return
result;
}
function
FFmpeg命令构建(videoPaths, outputPath) {
let
command = `-y `;
videoPaths.forEach(path => {
command += `-i
"${path}"
`;
});
let
filterComplex =
''
;
for
(
let
i = 0; i < videoPaths.length; i++) {
filterComplex += `[${i}:v][${i}:a]`;
}
filterComplex += `concat=n=${videoPaths.length}:v=1:a=1[outv][outa]`;
command += `-filter_complex
"${filterComplex}"
`;
command += `-map
"[outv]"
-map
"[outa]"
`;
command += `-vsync 2 `;
command += `-r 30 `;
command += `-b:v 5M `;
command += `
"${outputPath}"
`;
return
command;
}
log(
"end"
)