0

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?

Essem
  • 311
  • 2
  • 11
  • 1
    `t` represents the current time, not the total duration. You have to find out the total duration beforehand, and then use that value. Suppose it is 48 seconds. Then the first enable expr would be `between(t,0,24)` or `between(t,0,48/2)` – Gyan Apr 10 '19 at 15:16

1 Answers1

3

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");
});
Essem
  • 311
  • 2
  • 11