3

This is my typescript code:

import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import { FfmpegCommand } from 'fluent-ffmpeg'

async function bootstrap() {
  const app = await NestFactory.create(AppModule);
  let test

  try {
    test = new FfmpegCommand('./adventure.mkv');
  } catch (error) {
    console.log(error);

  }

  await app.listen(3000);
}

bootstrap();

Generated Javascript code:

"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
Object.defineProperty(exports, "__esModule", { value: true });
const core_1 = require("@nestjs/core");
const app_module_1 = require("./app.module");
const fluent_ffmpeg_1 = require("fluent-ffmpeg");
function bootstrap() {
    return __awaiter(this, void 0, void 0, function* () {
        const app = yield core_1.NestFactory.create(app_module_1.AppModule);
        let test;
        try {
            test = new fluent_ffmpeg_1.FfmpegCommand('./adventure.mkv');
        }
        catch (error) {
            console.log(error);
        }
        yield app.listen(3000);
    });
}
bootstrap();
//# sourceMappingURL=main.js.map

When I run this application I've next error:

main.ts:12 message:"fluent_ffmpeg_1.FfmpegCommand is not a constructor" stack:"TypeError: fluent_ffmpeg_1.FfmpegCommand is not a constructor\n at c:\nest\dist\src\main.js:20:20\n at Generator.next ()\n at fulfilled (c:\nest\dist\src\main.js:5:58)\n at process._tickCallback (internal/process/next_tick.js:68:7)\n at Function.Module.runMain (internal/modules/cjs/loader.js:834:11)\n at startup (internal/bootstrap/node.js:283:19)\n at bootstrapNodeJSCore (internal/bootstrap/node.js:622:3)"

That's beacause this raw test = new fluent_ffmpeg_1.FfmpegCommand('./adventure.mkv'). When I change this on just test = new fluent_ffmpeg_1('./adventure.mkv') I haven't the error. Do you know how to fix it. If you know where are ffmpeg exapmles on typescript please share with me:)

Ronan Quillevere
  • 3,699
  • 1
  • 29
  • 44
Steve Rock
  • 362
  • 1
  • 4
  • 11

2 Answers2

2

This is most likely because of the way that fluent-ffmpeg is exporting its components.

Try importing it like this

import * as FfmpegCommand from 'fluent-ffmpeg

or

import FfmpegCommand from 'fluent-ffmpeg

You could also install the typings and you ll get assitance when working with the module

https://www.npmjs.com/package/@types/fluent-ffmpeg

1

Try installing the types from npm to have some assistance.

npm i --save-dev @types/fluent-ffmpeg

After that you can import it and use it like this:

import Ffmpeg from "fluent-ffmpeg";

Ffmpeg("/path/to/file.mkv")
  .videoCodec("libx264")
  .audioCodec("libopus")
  .size("1280x720")
  .on("progress", function (progress) {
    console.log("Processing: " + progress.percent + "% done");
  })
  .on("error", function (err) {
    console.log("An error occurred: " + err.message);
  })
  .on("end", function () {
    console.log("Processing finished !");
  })
  .save(
    "/path/to/file.mkv"
  );
M. Martins
  • 11
  • 1