fluent-ffmpeg / node-fluent-ffmpeg

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

After encoding the video, the length of the video is missing in the file's properties #1209

Closed TharNyi13 closed 7 months ago

TharNyi13 commented 1 year ago

Version information

I am new to using node-fluent-ffmpeg. Thanks!

Code to reproduce

      const currentDirectory = process.cwd();
      const inputFilePath = path.join(currentDirectory, "original-video.mp4");
      const outputFilePath = fs.createWriteStream(
        "E:/test-video/output-video.mp4"
      );

      ffmpeg({ source: inputFilePath })
        .format("mp4")
        .videoCodec("libx264")
        .size("1920x1080")
        .aspectRatio("16:9")
        .outputOptions([
          "-movflags",
          "frag_keyframe+empty_moov+faststart",
          "-preset",
          "veryfast",
          "-crf",
          "23",
        ])
        .pipe(outputFilePath, { end: true });

(note: Length of the video is missing!)

image original-video is downloaded from YouTube / outupt-video is encoded with fluent-ffmpeg.

Expected results

I want to encode the video with the correct encoding options, similar to those used for YouTube videos, and set the correct duration for the video length after the encoding process is complete.

Observed results

After encoding a simple video from YouTube, the output video does not have a length or duration.

njoyard commented 7 months ago

This looks like an issue with ffmpeg, not with fluent-ffmpeg. Please ensure first that what you want to achieve works on command line.

You can get the command line that was run by fluent-ffmpeg by adding a 'start' event handler in your chain:

ffmpeg()
  .on('start', function(commandLine) {
    console.log('Spawned Ffmpeg with command: ' + commandLine)
  })
  ...

Run the command line manually, and determine if the same issue happens on command line. Be careful of properly escaping the command line contents for your shell. If your code is using streams, you will have to adapt the command line in order to pass the same inputs to ffmpeg.