NodeMediaServer MP4 change default video resolution 540p

430 Views Asked by At

I have setup a nginx RTMP server and the purpose is to store videos streamed from mobile devices in MP4 format for later analysis. Although mobile devices are streaming videos in 720p resolution NodeMediaServer always store video in 540p resolution. How can I change this behaviour? Following is NodeMediaServer configuration:

const nodeMediaServerConfig = {
  rtmp: {
    port: 1936,
    chunk_size: 60000,
    gop_cache: true,
    ping: 60,
    ping_timeout: 10,
  },
  http: {
    port: 8000,
    mediaroot: './media',
    allow_origin: '*',
  },
  trans: {
    ffmpeg: '/usr/bin/ffmpeg',
    tasks: [
      {
        app: 'live',
        vcParam: [
          "-c:v",
          "libx264",
          "-vf",
          "scale=720:-1",
          "-b:v",
          "2800k",
          "-bufsize",
          "4200k",
          "-preset",
          "fast",
        ],
        ac: 'aac',
        acParam:["-b:a", "128k", "-ar", 48000],
        mp4: true,
        mp4Flags: '[movflags=faststart]',
      },
    ],
  },
};

Any help in this matter is highly appreciated.

1

There are 1 best solutions below

0
llogan On

Change scale=720:-1 to scale=-2:720

If you use scale=720:-1 with an input of 1920x1080, it will be scaled to 720x405. If you use scale=-2:720 with an input of 1920x1080, it will be scaled to 1280x720.

  • First value is width
  • Second value is height
  • -2 will automatically calculate the appropriate value to preserve aspect (in relation to the other value), and will adjust the value to make it divisible by 2 (needed for libx264).

See scale filter documentation.