Essem
Essem

Reputation: 351

Changing volume halfway through video using FFmpeg?

I'm trying to use the fluent-ffmpeg NPM module in an application to decrease the volume of the audio in the first half of a video, then increase the volume when it reaches the midway point. I've wrote this code to try to do that:

const ffmpeg = require("fluent-ffmpeg");

ffmpeg("test.mp4")
 .audioFilters("volume=enable='between(t,0,t/2)':volume='0.25'", "volume=enable='between(t,t/2,t)':volume='1'")
 .save("output.mp4");

However, whenever I run this code, the volume levels of output.mp4 are exactly the same as test.mp4. What do I do?

Upvotes: 0

Views: 1269

Answers (1)

Essem
Essem

Reputation: 351

With the help of Gyan's comment, I was able to put together the effect I was wanting using ffprobe and JS template literals. Here's the fixed code (with fluent-ffmpeg notation):

const ffmpeg = require("fluent-ffmpeg");

ffmpeg.ffprobe("test.mp4", (error, metadata) => {
  ffmpeg("test.mp4").audioFilters({
    filter: "volume",
    options: {
      enable: `between(t,0,${metadata.format.duration}/2)`,
      volume: "0.25"
    }
  }, {
    filter: "volume",
    options: {
      enable: `between(t,${metadata.format.duration}/2, ${metadata.format.duration})`,
      volume: "1"
    }
  }).save("output.mp4");
});

Upvotes: 4

Related Questions