tnfe / FFCreator

A fast video processing library based on node.js (一个基于node.js的高速视频制作库)
http://tnfe.github.io/FFCreator/
MIT License
2.77k stars 391 forks source link

Audio is silent in the beginning and becomes louder at the end #283

Open forhku opened 1 year ago

forhku commented 1 year ago

Below is a screenshot of the waveform of the final video output (software used: wavepad). How do I fix this?

image
drawcall commented 1 year ago

Can provide your code

forhku commented 1 year ago

Can provide your code


const creator = new FFCreator({
    cacheDir: "vid_cache",
    outputDir: chosen_folder,
    width: 720,
    height: 1280,
    parallel: 5
});

const scene = new FFScene();

const image = new FFImage({
    path: __dirname + "/" + images[0],
    scale: 0.40,
    x: 360,
    y: 640
});

const bgv = new FFVideo({
    path: "background.mp4",
    height: 1280,
    width: 720,
    x: 360,
    y: 640
})

bgv.setAudio(false)

var ff_scenes = []

scene.addChild(bgv)
scene.addChild(image)
scene.addAudio("bgm.mp3")
var audio = fs.readFileSync("vocals_1.mp3")
scene.addAudio("vocals_1.mp3")

var post_duration = (getMp3Duration(audio) / 1000) + 0.2
post_duration = parseFloat(post_duration.toFixed(2))
scene.setDuration(post_duration)
creator.addChild(scene);

var last_duration = post_duration
var total_durations = post_duration

images.forEach((image, index) => {
    if (index != 0) {
        console.log(image)
        var audio = fs.readFileSync(image +  "_audio.mp3")
        var temp_image = new FFImage({
            path: __dirname + "/" + image,
            scale: 0.40,
            x: 360,
            y: 640
        });

        var current_duration = 0

        var temp_scene = new FFScene();
        temp_scene.setDuration((getMP3Duration(audio) / 1000) + 1);
        current_duration = (getMP3Duration(audio) / 1000) + 1

        var temp_current_duration = current_duration

        console.log(total_durations)
        console.log(total_durations + current_duration)

        var temp_bgv = new FFVideo({
            path: "background.mp4",
            height: 1280,
            width: 720,
            x: 360,
            y: 640
        })
        temp_bgv.setAudio(false)

        temp_scene.addChild(temp_bgv)
        temp_scene.addChild(temp_image)

        total_durations = current_duration + total_durations

        temp_scene.addAudio(__dirname + "/" + image +  "_audio.mp3")

        ff_scenes.push(temp_scene)
    }
})

ff_scenes.forEach(ff_scene => {
    creator.addChild(ff_scene);
})

creator.start();

Here's everything that has to do with ffcreator. Changed sensitive information to generic filenames

lczpln commented 1 year ago

Were you able to fix it?

Lnoorlander commented 10 months ago

Has any of you been able to fix this? I have the same problem.

lczpln commented 10 months ago

@Lnoorlander https://github.com/tnfe/FFCreator/issues/314

Lnoorlander commented 10 months ago

@lczpln Thanks a lot! Is there some secret documentation i missed?

lczpln commented 10 months ago

Idk, I’ve spent a half hour to find it lol, glad to help!