29 lines
931 B
TypeScript
29 lines
931 B
TypeScript
import { readdir, stat } from 'fs/promises';
|
|
import path from 'path';
|
|
import { exec } from 'child_process';
|
|
|
|
const videoExtensions = ['mp4', 'avi', 'mov', 'mkv', 'flv', 'wmv', 'mpeg', 'mpg'];
|
|
|
|
(async () => {
|
|
try {
|
|
const files = await readdir('.');
|
|
for (const file of files) {
|
|
const stats = await stat(file);
|
|
if (!stats.isFile()) continue;
|
|
|
|
const ext = path.extname(file).slice(1).toLowerCase();
|
|
if (videoExtensions.includes(ext) && !file.startsWith('HEVC_')) {
|
|
const newFileName = 'HEVC_' + file;
|
|
const command = `ffmpeg -i "${file}" -c:v hevc_nvenc -preset slow -crf 23 -c:a aac "${newFileName}"`;
|
|
|
|
exec(command, (err) => {
|
|
if (err) console.error(`Conversion failed for ${file}: ${err}`);
|
|
else console.log(`Converted ${file} → ${newFileName}`);
|
|
});
|
|
}
|
|
}
|
|
} catch (err) {
|
|
console.error('Error processing files:', err);
|
|
}
|
|
})();
|