@scrypted/libav 1.0.3 → 1.0.5

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/darwin.md ADDED
@@ -0,0 +1,24 @@
1
+ Mimimum macOS configuration for RTSP, h264, h265, jpg, and videotoolbox.
2
+
3
+ ```sh
4
+ ./configure \
5
+ --disable-everything \
6
+ --enable-hwaccels \
7
+ --enable-videotoolbox \
8
+ --enable-decoder=h264 \
9
+ --enable-decoder=hevc \
10
+ --enable-demuxer=rtsp \
11
+ --enable-muxer=mjpeg \
12
+ --enable-encoder=mjpeg \
13
+ --enable-parser=mjpeg \
14
+ --enable-protocol=tcp \
15
+ --enable-protocol=udp \
16
+ --enable-filter=crop \
17
+ --enable-filter=scale \
18
+ --enable-filter=scale_vt \
19
+ --enable-filter=format \
20
+ --enable-filter=hwdownload \
21
+ --enable-filter=hwupload \
22
+ --enable-parser=h264 \
23
+ --enable-parser=hevc
24
+ ```
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.5",
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,17 +119,17 @@ 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
123
- av_opt_set_int(c, "qscale", quality, 0); // Set the quality scale (1-31, lower is better quality)
124
- av_opt_set_int(c, "qmin", quality, 0); // Set the minimum quality
125
- av_opt_set_int(c, "qmax", quality, 0); // Set the maximum quality
129
+ int quality = info[0].As<Napi::Number>().Int32Value(); // 1-31, lower is better quality
130
+ av_opt_set_int(c, "qscale", quality, 0); // Set the quality scale (1-31, lower is better quality)
131
+ av_opt_set_int(c, "qmin", quality, 0); // Set the minimum quality
132
+ av_opt_set_int(c, "qmax", quality, 0); // Set the maximum quality
126
133
 
127
134
  if (avcodec_open2(c, codec, NULL) < 0)
128
135
  {
@@ -152,7 +159,7 @@ Napi::Value AVFrameObject::ToJPEG(const Napi::CallbackInfo &info)
152
159
  return env.Null();
153
160
  }
154
161
 
155
- Napi::Buffer<uint8_t> buffer = Napi::Buffer<uint8_t>::New(env, pkt.data, pkt.size);
162
+ Napi::Buffer<uint8_t> buffer = Napi::Buffer<uint8_t>::Copy(env, pkt.data, pkt.size);
156
163
  av_packet_unref(&pkt);
157
164
  avcodec_free_context(&c);
158
165
 
@@ -173,22 +180,27 @@ Napi::Value AVFrameObject::ToBuffer(const Napi::CallbackInfo &info)
173
180
  int height = frame_->height;
174
181
  int buffer_size = av_image_get_buffer_size((enum AVPixelFormat)frame_->format, width, height, 1);
175
182
 
176
- // Allocate memory for the byte array
177
- uint8_t *byte_array = (uint8_t *)malloc(buffer_size);
183
+ Napi::Buffer<uint8_t> buffer = Napi::Buffer<uint8_t>::New(env, buffer_size);
184
+
185
+ uint8_t *byte_array = buffer.Data();
178
186
  if (!byte_array)
179
187
  {
180
- fprintf(stderr, "Failed to allocate memory for byte array\n");
188
+ Napi::Error::New(env, "Failed to allocate memory for byte array").ThrowAsJavaScriptException();
181
189
  return env.Null();
182
190
  }
183
191
 
184
- // Copy the frame data to the byte array
185
- int plane_size = width * 3; // Width * 3 bytes per pixel
186
- for (int y = 0; y < height; y++)
192
+ int frame_size = frame_->linesize[0] * height;
193
+ if (frame_size != buffer_size)
187
194
  {
188
- memcpy(byte_array + y * plane_size, frame_->data[0] + y * frame_->linesize[0], plane_size);
195
+ int stride = buffer_size / height;
196
+ for (int y = 0; y < height; y++)
197
+ {
198
+ memcpy(byte_array + y * stride, frame_->data[0] + y * frame_->linesize[0], stride);
199
+ }
200
+ }
201
+ else {
202
+ memcpy(byte_array, frame_->data[0], buffer_size);
189
203
  }
190
-
191
- Napi::Buffer<uint8_t> buffer = Napi::Buffer<uint8_t>::New(env, byte_array, buffer_size);
192
204
 
193
205
  return buffer;
194
206
  }
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 {