@scrypted/libav 1.0.3 → 1.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.d.ts CHANGED
@@ -5,7 +5,11 @@ export interface AVFrame {
5
5
  height: number;
6
6
  format: string;
7
7
  toBuffer(): Buffer;
8
- toJpeg(): Buffer;
8
+ /**
9
+ *
10
+ * @param quality 1-31. Lower is better quality.
11
+ */
12
+ toJpeg(quality: number): Buffer;
9
13
  }
10
14
  export interface AVFilter {
11
15
  destroy(): void;
package/lib/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;AAOA,kCAEC;AAwBD,4CAEC;AAED,sDAEC;AAvCD,IAAI,KAAU,CAAC;AACf,IAAI,CAAC;IACD,KAAK,GAAG,OAAO,CAAC,wBAAwB,CAAC,CAAC;AAC9C,CAAC;AACD,OAAO,CAAC,EAAE,CAAC;AACX,CAAC;AAED,SAAgB,WAAW;IACvB,OAAO,CAAC,CAAC,KAAK,CAAC;AACnB,CAAC;AAwBD,SAAgB,gBAAgB,CAAC,QAA+B;IAC5D,KAAK,CAAC,oBAAoB,CAAC,QAAQ,CAAC,CAAC;AACzC,CAAC;AAED,SAAgB,qBAAqB;IACjC,OAAO,IAAI,KAAK,CAAC,eAAe,EAAE,CAAC;AACvC,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;AAOA,kCAEC;AA4BD,4CAEC;AAED,sDAEC;AA3CD,IAAI,KAAU,CAAC;AACf,IAAI,CAAC;IACD,KAAK,GAAG,OAAO,CAAC,wBAAwB,CAAC,CAAC;AAC9C,CAAC;AACD,OAAO,CAAC,EAAE,CAAC;AACX,CAAC;AAED,SAAgB,WAAW;IACvB,OAAO,CAAC,CAAC,KAAK,CAAC;AACnB,CAAC;AA4BD,SAAgB,gBAAgB,CAAC,QAA+B;IAC5D,KAAK,CAAC,oBAAoB,CAAC,QAAQ,CAAC,CAAC;AACzC,CAAC;AAED,SAAgB,qBAAqB;IACjC,OAAO,IAAI,KAAK,CAAC,eAAe,EAAE,CAAC;AACvC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@scrypted/libav",
3
- "version": "1.0.3",
3
+ "version": "1.0.4",
4
4
  "dependencies": {
5
5
  "node-addon-api": "^8.1.0",
6
6
  "prebuild-install": "npm:@scrypted/prebuild-install@^7.1.8"
package/src/frame.cpp CHANGED
@@ -92,6 +92,13 @@ AVFrameObject::~AVFrameObject()
92
92
  Napi::Value AVFrameObject::ToJPEG(const Napi::CallbackInfo &info)
93
93
  {
94
94
  Napi::Env env = info.Env();
95
+
96
+ if (info.Length() < 1 || !info[0].IsNumber())
97
+ {
98
+ Napi::TypeError::New(env, "String expected").ThrowAsJavaScriptException();
99
+ return env.Null();
100
+ }
101
+
95
102
  if (!frame_)
96
103
  {
97
104
  Napi::Error::New(env, "Frame object is null").ThrowAsJavaScriptException();
@@ -112,14 +119,14 @@ Napi::Value AVFrameObject::ToJPEG(const Napi::CallbackInfo &info)
112
119
  return env.Null();
113
120
  }
114
121
 
115
- c->bit_rate = 400000; // This is generally less relevant for single images
122
+ c->bit_rate = 2000000; // This is generally less relevant for single images
116
123
  c->width = frame_->width;
117
124
  c->height = frame_->height;
118
125
  c->pix_fmt = (enum AVPixelFormat)frame_->format;
119
126
  c->time_base = (AVRational){1, 25};
120
127
 
121
128
  // Set the JPEG quality
122
- int quality = 2; // 1-31, lower is better quality
129
+ int quality = info[0].As<Napi::Number>().Int32Value(); // 1-31, lower is better quality
123
130
  av_opt_set_int(c, "qscale", quality, 0); // Set the quality scale (1-31, lower is better quality)
124
131
  av_opt_set_int(c, "qmin", quality, 0); // Set the minimum quality
125
132
  av_opt_set_int(c, "qmax", quality, 0); // Set the maximum quality
@@ -177,7 +184,7 @@ Napi::Value AVFrameObject::ToBuffer(const Napi::CallbackInfo &info)
177
184
  uint8_t *byte_array = (uint8_t *)malloc(buffer_size);
178
185
  if (!byte_array)
179
186
  {
180
- fprintf(stderr, "Failed to allocate memory for byte array\n");
187
+ Napi::Error::New(env, "Failed to allocate memory for byte array").ThrowAsJavaScriptException();
181
188
  return env.Null();
182
189
  }
183
190
 
package/src/index.ts CHANGED
@@ -15,7 +15,11 @@ export interface AVFrame {
15
15
  height: number;
16
16
  format: string;
17
17
  toBuffer(): Buffer;
18
- toJpeg(): Buffer;
18
+ /**
19
+ *
20
+ * @param quality 1-31. Lower is better quality.
21
+ */
22
+ toJpeg(quality: number): Buffer;
19
23
  }
20
24
 
21
25
  export interface AVFilter {