drawcall / FFCreatorLite

A lightweight and fast short video processing library based on node.js
https://tnfe.github.io/FFCreator
MIT License
283 stars 59 forks source link

outputDir 无效 #35

Open ixqbar opened 1 year ago

ixqbar commented 1 year ago

也没有使用 FFCreatorCenter, 只能通过output设置

const { FFScene, FFImage, FFText, FFCreator } = require('ffcreatorlite');
const path = require('path');
const colors = require('colors');

// create creator instance
const creator = new FFCreator({
    cacheDir:"../cache/",
    // outputDir: path.join(__dirname, "../dist/"),
    output: '../dist/x1.mp4',
    width: 600,
    height: 400,
    log: true,
    upStreaming: false,
});

// create FFScene
const scene1 = new FFScene();
const scene2 = new FFScene();
scene1.setBgColor('#ff0000');
scene2.setBgColor('#b33771');

const bg1 = "./assets/bg1.jpeg"
const img1 = "./assets/06.png"
// scene1
const fbg = new FFImage({ path: bg1 });
scene1.addChild(fbg);

const fimg1 = new FFImage({ path: img1, x: 300, y: 60 });
fimg1.addEffect('moveInRight', 1.5, 1.2);
scene1.addChild(fimg1);

const font = path.join(__dirname, './assets/font/scsf.ttf');

const text = new FFText({ text: '这是第一屏', font, x: 100, y: 100 });
text.setColor('#ffffff');
text.setBackgroundColor('#000000');
text.addEffect('fadeIn', 1, 1);
scene1.addChild(text);

scene1.setDuration(8);
creator.addChild(scene1);

const bg2 = "./assets/bg2.jpeg"
const logo = "./assets/logo.png"
// scene2
const fbg2 = new FFImage({ path: bg2 });
scene2.addChild(fbg2);
// logo
const flogo = new FFImage({ path: logo, x: 100, y: 100 });
flogo.addEffect('moveInUpBack', 1.2, 0.3);
scene2.addChild(flogo);

scene2.setDuration(4);
creator.addChild(scene2);

const audio = path.join(__dirname, './assets/audio/03.wav');

creator.addAudio(audio);
creator.start();

creator.on('progress', e => {
    console.log(colors.yellow(`FFCreatorLite progress: ${(e.percent * 100) >> 0}%`));
});
creator.on('error', e => {
    console.log(`FFCreator error: ${JSON.stringify(e)}`);
});
creator.on('complete', e => {
    console.dir(e)
    console.log(
        colors.magenta(`FFCreatorLite completed: \n USEAGE: ${e.useage} \n PATH: ${e.output} `),
    );
});
liwei511 commented 1 year ago

同问, outputDir无效,output设置文件路径无效。请问楼主解决了吗?

ixqbar commented 1 year ago

同问, outputDir无效,output设置文件路径无效。请问楼主解决了吗?

output: '../dist/x1.mp4',
hurely commented 1 year ago

`utils.removeFileToPath(e.output, ${outputDir}/${videoTitle || e.output})

exports.removeFileToPath = function (sourcePath, destinationPath) { console.log('removeFileToPath:', sourcePath, destinationPath) // const sourcePath = './file.txt'; // const destinationPath = './destination/newfile.txt'; // fs.rename(sourcePath, destinationPath, (err) => { // if (err) throw err; // console.log('File moved and renamed successfully!'); // }); // 创建读取流 const readStream = fs.createReadStream(sourcePath) // 创建写入流 const writeStream = fs.createWriteStream(destinationPath) // 执行复制操作 readStream.pipe(writeStream) // 监听复制完成事件 readStream.on('close', () => { // 删除源文件 fs.unlinkSync(sourcePath) console.log(文件已移动到 ${destinationPath}) }) }`