fluent-ffmpeg / node-fluent-ffmpeg

A fluent API to FFMPEG (http://www.ffmpeg.org)
MIT License
7.64k stars 874 forks source link

Overlay image on top of video disappears when sharing video #1143

Open ya5huk opened 2 years ago

ya5huk commented 2 years ago

Version information

Code to reproduce

// Video editing
    ffmpeg()
      .input(bg.path)
      .input(tweet.path)
      .complexFilter([
        { filter: "format", options: "rgba" },
        {
          filter: "lutrgb",
          options: {
            g: `val * ${tweetSettings.opacity}`,
            b: `val * ${tweetSettings.opacity}`,
            r: `val * ${tweetSettings.opacity}`,
            a: `val * ${tweetSettings.opacity}`,
          },
          inputs: "[1:v]",
          outputs: "lut1",
        },
        {
          filter: "overlay",
          options: { x: tweetSettings.x, y: tweetSettings.y, alpha: 'premultiplied' },
          inputs: ["[0:v]", "lut1"],
        },
      ])
      .duration(`${duration}`)
      .saveToFile("./public/vid.mp4")
      .on("error", (err) => {
        console.log(err);
      })
      .on("end", () => {
        deleteFile(tweet.path);
        deleteFile(bg.path);
        cb("./public/vid.mp4"); // A callback function
      });
  });

(note: if the problem only happens with some inputs, include a link to such an input file)

Expected results

A video with an overlay image on top (at the given x, y, opacity). It works, but only in the windows video player image

Observed results

If I try to upload it to google photos or just display it in the web the tweet will disappear:

image

Maybe the file format does not support alpha channels or something like that?

doverradio commented 2 years ago

Could you please reveal the values you are using to produce this effect?

I have tried adapting a version your code to try and get the same but got errors:

node:events:368
      throw er; // Unhandled 'error' event
      ^

Error: ffmpeg exited with code 1: Error reinitializing filters!
Failed to inject frame into filter network: Invalid argument
Error while processing the decoded data for stream #1:0
Conversion failed!

The code I used:

let command = ffmpeg()
                    .input( filepath )
                    .input( filePathOverlayImage )
                    .complexFilter([
                        { filter: "format", options: "rgba" },
                        {
                            filter: "lutrgb",
                            options: {
                            g: `minval`,
                            b: `minval`,
                            r: `minval`,
                            a: `minval`,
                            },
                            inputs: "[1:v]",
                            outputs: "lut1",
                        },
                        {
                            filter: "overlay",
                            options: { x: '(main_w/2-text_w/2)', y: 200, alpha: 'premultiplied' },
                            inputs: ["[0:v]", "lut1"],
                        },
                    ])
                    .output( outpath )
                    .on( 'end', function() {
                        console.log( 'finished text overlay and opacity' )
                    })