Envek / obs-studio-node-example

Learn how to use OBS Studio from your Electron app for screen video recording
GNU General Public License v2.0
104 stars 19 forks source link

JavaScript runtime error: parameterSettings is undefined #2

Closed hrueger closed 4 years ago

hrueger commented 4 years ago

Hi, It's working with Electron 6. However, I get the following error after I ran npm start: grafik I could fix it by change the getAvailableValues() function to this:

function getAvailableValues(category, subcategory, parameter) {
  const categorySettings = osn.NodeObs.OBS_settings_getSettings(category).data;
  const subcategorySettings = categorySettings.find(sub => sub.nameSubCategory === subcategory);
  const parameterSettings = subcategorySettings.parameters.find(param => param.name === parameter);
  if (parameterSettings && parameterSettings.values) {
    return parameterSettings.values.map(value => Object.values(value)[0]);
  }
  return [];
}

Then it's working. Just for reference, categorySettings is

[
  { nameSubCategory: 'Untitled', parameters: [ [Object] ] },
  {
    nameSubCategory: 'Streaming',
    parameters: [ [Object], [Object], [Object], [Object] ]
  },
  {
    nameSubCategory: 'Recording',
    parameters: [ [Object], [Object], [Object], [Object], [Object] ]
  },
  {
    nameSubCategory: 'Replay Buffer',
    parameters: [ [Object], [Object] ]
  }
]

subcategorySettings is


  nameSubCategory: 'Recording',
  parameters: [
    {
      name: 'FilePath',
      type: 'OBS_PROPERTY_PATH',
      description: 'Recording Path',
      subType: '',
      currentValue: 'C:\\Users\\Hannes\\Desktop\\Angular\\obs-studio-node-example\\videos',
      values: [],
      visible: true,
      enabled: true,
      masked: false
    },
    {
      name: 'FileNameWithoutSpace',
      type: 'OBS_PROPERTY_BOOL',
      description: 'Generate File Name without Space',
      subType: '',
      currentValue: false,
      values: [],
      visible: true,
      enabled: true,
      masked: false
    },
    {
      name: 'RecQuality',
      type: 'OBS_PROPERTY_LIST',
      description: 'Recording Quality',
      subType: 'OBS_COMBO_FORMAT_STRING',
      currentValue: 'Stream',
      values: [Array],
      visible: true,
      enabled: true,
      masked: false
    },
    {
      name: 'RecFormat',
      type: 'OBS_PROPERTY_LIST',
      description: 'Recording Format',
      subType: 'OBS_COMBO_FORMAT_STRING',
      currentValue: 'mkv',
      values: [Array],
      visible: true,
      enabled: true,
      masked: false
    },
    {
      name: 'MuxerCustom',
      type: 'OBS_PROPERTY_EDIT_TEXT',
      description: 'Custom Muxer Settings',
      subType: '',
      currentValue: '',
      values: [],
      visible: true,
      enabled: true,
      masked: false
    }
  ]
}

and parameterSettings is then undefined.

I also noticed that only about 2/3 of my screen were recorded and in the logs (attached) it says this:

video settings reset:
    base resolution:   1536x960
    output resolution: 1228x768

My screen, however, is 1920x1200. I don't know much about OBS, but I don't think this problem belongs to the RecEncoder settings, does it?

2020-04-13 06-51-24.txt

hrueger commented 4 years ago

After having a closer look at the code, I found that this already returns 1536x960. So no problem with your code, sorry! Probably a Windows scaling issue (my scaling is at 125% because I'm using a convertible). 1920 / 1.25 = 1536

  const { screen } = require('electron');
  const primaryDisplay = screen.getPrimaryDisplay();

Edit: After inspecting the whole code I saw that the scaleFactor is multiplied with the display size values retrieved from the electron screen module and the realDisplayWith and realDisplayHeight variables do have the correct value.

Envek commented 4 years ago

Hmm, that is weird that OBS doesn't return list of available encoders for you.

Try to place x264 here (it is always available, but slower):

https://github.com/Envek/obs-studio-node-example/blob/cc7f096740adcc722a97ea9032bd7bd8aac89805/obsRecorder.js#L57

Usually nvenc or jim_nvenc is preferred here, but they are only available on Nvidia cards.

Envek commented 4 years ago

Also OBS seems to ignore programmatic changes to set output video resolution to 1920x1080. This happened for me too and I'm still don't know why.

For now you can manually edit OBS configuration in osn-data subfolder and set OutputCX and OutputCY parameters under Video section to 1920 and 1080 respectively.

Envek commented 4 years ago

Fixed this JS error in case when OBS Studio doesn't return possible values.

Created separate issue about output video resoultion. I have no time to tackle with it right now, but hope that it is something wrong with setSetting method (which was copied verbatim from obs-studio-node tests) and it just changes resolution in some wrong place.