@scrypted/libav 1.0.4 → 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.
Files changed (3) hide show
  1. package/darwin.md +24 -0
  2. package/package.json +1 -1
  3. package/src/frame.cpp +17 -12
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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@scrypted/libav",
3
- "version": "1.0.4",
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
@@ -127,9 +127,9 @@ Napi::Value AVFrameObject::ToJPEG(const Napi::CallbackInfo &info)
127
127
 
128
128
  // Set the JPEG quality
129
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
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
133
133
 
134
134
  if (avcodec_open2(c, codec, NULL) < 0)
135
135
  {
@@ -159,7 +159,7 @@ Napi::Value AVFrameObject::ToJPEG(const Napi::CallbackInfo &info)
159
159
  return env.Null();
160
160
  }
161
161
 
162
- 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);
163
163
  av_packet_unref(&pkt);
164
164
  avcodec_free_context(&c);
165
165
 
@@ -180,22 +180,27 @@ Napi::Value AVFrameObject::ToBuffer(const Napi::CallbackInfo &info)
180
180
  int height = frame_->height;
181
181
  int buffer_size = av_image_get_buffer_size((enum AVPixelFormat)frame_->format, width, height, 1);
182
182
 
183
- // Allocate memory for the byte array
184
- 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();
185
186
  if (!byte_array)
186
187
  {
187
188
  Napi::Error::New(env, "Failed to allocate memory for byte array").ThrowAsJavaScriptException();
188
189
  return env.Null();
189
190
  }
190
191
 
191
- // Copy the frame data to the byte array
192
- int plane_size = width * 3; // Width * 3 bytes per pixel
193
- for (int y = 0; y < height; y++)
192
+ int frame_size = frame_->linesize[0] * height;
193
+ if (frame_size != buffer_size)
194
194
  {
195
- 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);
196
203
  }
197
-
198
- Napi::Buffer<uint8_t> buffer = Napi::Buffer<uint8_t>::New(env, byte_array, buffer_size);
199
204
 
200
205
  return buffer;
201
206
  }