bare-ffmpeg 1.0.0-14 → 1.0.0-15

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/README.md CHANGED
@@ -573,6 +573,16 @@ Parameters:
573
573
 
574
574
  **Returns**: void
575
575
 
576
+ ##### `Image.read(frame)`
577
+
578
+ Reads image data from a frame into the image buffer.
579
+
580
+ Parameters:
581
+
582
+ - `frame` (`Frame`): The frame to read from
583
+
584
+ **Returns**: `void`
585
+
576
586
  ##### `Image.lineSize([plane])`
577
587
 
578
588
  Gets the line size for a specific plane.
package/binding.cc CHANGED
@@ -16,6 +16,7 @@ extern "C" {
16
16
  #include <libavdevice/avdevice.h>
17
17
  #include <libavformat/avformat.h>
18
18
  #include <libavformat/avio.h>
19
+ #include <libavutil/audio_fifo.h>
19
20
  #include <libavutil/channel_layout.h>
20
21
  #include <libavutil/dict.h>
21
22
  #include <libavutil/error.h>
@@ -26,7 +27,6 @@ extern "C" {
26
27
  #include <libavutil/pixfmt.h>
27
28
  #include <libavutil/rational.h>
28
29
  #include <libavutil/samplefmt.h>
29
- #include <libavutil/audio_fifo.h>
30
30
  #include <libswresample/swresample.h>
31
31
  #include <libswscale/swscale.h>
32
32
  }
@@ -763,6 +763,25 @@ bare_ffmpeg_codec_context_set_sample_rate(
763
763
  context->handle->sample_rate = sample_rate;
764
764
  }
765
765
 
766
+ static int
767
+ bare_ffmpeg_codec_context_get_gop_size(
768
+ js_env_t *env,
769
+ js_receiver_t,
770
+ js_arraybuffer_span_of_t<bare_ffmpeg_codec_context_t, 1> context
771
+ ) {
772
+ return context->handle->gop_size;
773
+ }
774
+
775
+ static void
776
+ bare_ffmpeg_codec_context_set_gop_size(
777
+ js_env_t *env,
778
+ js_receiver_t,
779
+ js_arraybuffer_span_of_t<bare_ffmpeg_codec_context_t, 1> context,
780
+ int32_t gop_size
781
+ ) {
782
+ context->handle->gop_size = gop_size;
783
+ }
784
+
766
785
  static bool
767
786
  bare_ffmpeg_codec_context_send_packet(
768
787
  js_env_t *env,
@@ -1063,6 +1082,15 @@ bare_ffmpeg_frame_set_nb_samples(
1063
1082
  frame->handle->nb_samples = nb_samples;
1064
1083
  }
1065
1084
 
1085
+ static int32_t
1086
+ bare_ffmpeg_frame_get_pict_type(
1087
+ js_env_t *env,
1088
+ js_receiver_t,
1089
+ js_arraybuffer_span_of_t<bare_ffmpeg_frame_t, 1> frame
1090
+ ) {
1091
+ return frame->handle->pict_type;
1092
+ }
1093
+
1066
1094
  static void
1067
1095
  bare_ffmpeg_frame_alloc(
1068
1096
  js_env_t *env,
@@ -1145,6 +1173,43 @@ bare_ffmpeg_image_fill(
1145
1173
  }
1146
1174
  }
1147
1175
 
1176
+ static void
1177
+ bare_ffmpeg_image_read(
1178
+ js_env_t *env,
1179
+ js_receiver_t,
1180
+ int32_t pixel_format,
1181
+ int32_t width,
1182
+ int32_t height,
1183
+ int32_t align,
1184
+ js_arraybuffer_span_t data,
1185
+ uint64_t offset,
1186
+ js_arraybuffer_span_of_t<bare_ffmpeg_frame_t, 1> frame
1187
+ ) {
1188
+ uint8_t *dst_data[4];
1189
+ int dst_linesize[4];
1190
+
1191
+ int err = av_image_fill_arrays(
1192
+ dst_data,
1193
+ dst_linesize,
1194
+ &data[offset],
1195
+ static_cast<AVPixelFormat>(pixel_format),
1196
+ width,
1197
+ height,
1198
+ align
1199
+ );
1200
+ assert(err >= 0);
1201
+
1202
+ av_image_copy(
1203
+ dst_data,
1204
+ dst_linesize,
1205
+ frame->handle->data,
1206
+ frame->handle->linesize,
1207
+ static_cast<AVPixelFormat>(pixel_format),
1208
+ width,
1209
+ height
1210
+ );
1211
+ }
1212
+
1148
1213
  static int
1149
1214
  bare_ffmpeg_image_get_line_size(
1150
1215
  js_env_t *env,
@@ -1309,6 +1374,15 @@ bare_ffmpeg_packet_get_data(
1309
1374
  return handle;
1310
1375
  }
1311
1376
 
1377
+ static bool
1378
+ bare_ffmpeg_packet_is_keyframe(
1379
+ js_env_t *,
1380
+ js_receiver_t,
1381
+ js_arraybuffer_span_of_t<bare_ffmpeg_packet_t, 1> packet
1382
+ ) {
1383
+ return packet->handle->flags & AV_PKT_FLAG_KEY;
1384
+ }
1385
+
1312
1386
  static js_arraybuffer_t
1313
1387
  bare_ffmpeg_scaler_init(
1314
1388
  js_env_t *env,
@@ -1717,7 +1791,7 @@ bare_ffmpeg_audio_fifo_drain(
1717
1791
  int32_t nb_samples
1718
1792
  ) {
1719
1793
  int err;
1720
-
1794
+
1721
1795
  int len = av_audio_fifo_drain(fifo->handle, nb_samples);
1722
1796
 
1723
1797
  if (len < 0) {
@@ -1725,7 +1799,7 @@ bare_ffmpeg_audio_fifo_drain(
1725
1799
  assert(err == 0);
1726
1800
  throw js_pending_exception;
1727
1801
  }
1728
-
1802
+
1729
1803
  return len;
1730
1804
  }
1731
1805
 
@@ -1806,6 +1880,9 @@ bare_ffmpeg_exports(js_env_t *env, js_value_t *exports) {
1806
1880
  V("setCodecContextChannelLayout", bare_ffmpeg_codec_context_set_channel_layout);
1807
1881
  V("getCodecContextSampleRate", bare_ffmpeg_codec_context_get_sample_rate);
1808
1882
  V("setCodecContextSampleRate", bare_ffmpeg_codec_context_set_sample_rate);
1883
+ V("getCodecContextGOPSize", bare_ffmpeg_codec_context_get_gop_size)
1884
+ V("setCodecContextGOPSize", bare_ffmpeg_codec_context_set_gop_size)
1885
+
1809
1886
  V("sendCodecContextPacket", bare_ffmpeg_codec_context_send_packet)
1810
1887
  V("receiveCodecContextPacket", bare_ffmpeg_codec_context_receive_packet)
1811
1888
  V("sendCodecContextFrame", bare_ffmpeg_codec_context_send_frame)
@@ -1836,10 +1913,12 @@ bare_ffmpeg_exports(js_env_t *env, js_value_t *exports) {
1836
1913
  V("setFrameChannelLayout", bare_ffmpeg_frame_set_channel_layout)
1837
1914
  V("getFrameNbSamples", bare_ffmpeg_frame_get_nb_samples)
1838
1915
  V("setFrameNbSamples", bare_ffmpeg_frame_set_nb_samples)
1916
+ V("getFramePictType", bare_ffmpeg_frame_get_pict_type)
1839
1917
  V("allocFrame", bare_ffmpeg_frame_alloc)
1840
1918
 
1841
1919
  V("initImage", bare_ffmpeg_image_init)
1842
1920
  V("fillImage", bare_ffmpeg_image_fill)
1921
+ V("readImage", bare_ffmpeg_image_read)
1843
1922
  V("getImageLineSize", bare_ffmpeg_image_get_line_size)
1844
1923
 
1845
1924
  V("initSamples", bare_ffmpeg_samples_init)
@@ -1850,6 +1929,7 @@ bare_ffmpeg_exports(js_env_t *env, js_value_t *exports) {
1850
1929
  V("unrefPacket", bare_ffmpeg_packet_unref)
1851
1930
  V("getPacketStreamIndex", bare_ffmpeg_packet_get_stream_index)
1852
1931
  V("getPacketData", bare_ffmpeg_packet_get_data)
1932
+ V("isPacketKeyframe", bare_ffmpeg_packet_is_keyframe)
1853
1933
 
1854
1934
  V("initScaler", bare_ffmpeg_scaler_init)
1855
1935
  V("destroyScaler", bare_ffmpeg_scaler_destroy)
@@ -1900,6 +1980,7 @@ bare_ffmpeg_exports(js_env_t *env, js_value_t *exports) {
1900
1980
  V(AV_PIX_FMT_RGB24)
1901
1981
  V(AV_PIX_FMT_YUVJ420P)
1902
1982
  V(AV_PIX_FMT_YUV420P)
1983
+ V(AV_PIX_FMT_UYVY422)
1903
1984
 
1904
1985
  V(AVMEDIA_TYPE_UNKNOWN)
1905
1986
  V(AVMEDIA_TYPE_VIDEO)
@@ -1932,6 +2013,15 @@ bare_ffmpeg_exports(js_env_t *env, js_value_t *exports) {
1932
2013
  V(AV_CH_LAYOUT_5POINT0)
1933
2014
  V(AV_CH_LAYOUT_5POINT1)
1934
2015
  V(AV_CH_LAYOUT_7POINT1)
2016
+
2017
+ V(AV_PICTURE_TYPE_NONE)
2018
+ V(AV_PICTURE_TYPE_I)
2019
+ V(AV_PICTURE_TYPE_P)
2020
+ V(AV_PICTURE_TYPE_B)
2021
+ V(AV_PICTURE_TYPE_S)
2022
+ V(AV_PICTURE_TYPE_SI)
2023
+ V(AV_PICTURE_TYPE_SP)
2024
+ V(AV_PICTURE_TYPE_BI)
1935
2025
  #undef V
1936
2026
 
1937
2027
  return exports;
@@ -11,6 +11,10 @@ set(args
11
11
  -DBUILD_TESTING=OFF
12
12
  )
13
13
 
14
+ if(WIN32)
15
+ list(APPEND args -DOPUS_DISABLE_INTRINSICS=ON)
16
+ endif()
17
+
14
18
  declare_port(
15
19
  "github:xiph/opus@v1.5.2"
16
20
  opus
@@ -78,6 +78,14 @@ module.exports = class FFmpegCodecContext {
78
78
  )
79
79
  }
80
80
 
81
+ get gopSize() {
82
+ return binding.getCodecContextGOPSize(this._handle)
83
+ }
84
+
85
+ set gopSize(value) {
86
+ binding.setCodecContextGOPSize(this._handle, value)
87
+ }
88
+
81
89
  open(options) {
82
90
  if (this._opened) return
83
91
  this._opened = true
package/lib/constants.js CHANGED
@@ -56,6 +56,16 @@ module.exports = exports = {
56
56
  '5.0': binding.AV_CH_LAYOUT_5POINT0,
57
57
  5.1: binding.AV_CH_LAYOUT_5POINT1,
58
58
  7.1: binding.AV_CH_LAYOUT_7POINT1
59
+ },
60
+ pictureType: {
61
+ NONE: binding.AV_PICTURE_TYPE_NONE,
62
+ I: binding.AV_PICTURE_TYPE_I,
63
+ P: binding.AV_PICTURE_TYPE_P,
64
+ B: binding.AV_PICTURE_TYPE_B,
65
+ S: binding.AV_PICTURE_TYPE_S,
66
+ SI: binding.AV_PICTURE_TYPE_SI,
67
+ SP: binding.AV_PICTURE_TYPE_SP,
68
+ BI: binding.AV_PICTURE_TYPE_BI
59
69
  }
60
70
  }
61
71
 
package/lib/frame.js CHANGED
@@ -62,6 +62,10 @@ module.exports = class FFmpegFrame {
62
62
  binding.setFrameNbSamples(this._handle, value)
63
63
  }
64
64
 
65
+ get pictType() {
66
+ return binding.getFramePictType(this._handle)
67
+ }
68
+
65
69
  alloc() {
66
70
  binding.allocFrame(this._handle, 32)
67
71
  }
package/lib/image.js CHANGED
@@ -47,6 +47,18 @@ module.exports = class FFmpegImage {
47
47
  )
48
48
  }
49
49
 
50
+ read(frame) {
51
+ binding.readImage(
52
+ this._pixelFormat,
53
+ this._width,
54
+ this._height,
55
+ this._align,
56
+ this._data.buffer,
57
+ this._data.byteOffset,
58
+ frame._handle
59
+ )
60
+ }
61
+
50
62
  lineSize(plane = 0) {
51
63
  return binding.getImageLineSize(this._pixelFormat, this._width, plane)
52
64
  }
@@ -3,6 +3,9 @@ const binding = require('../binding')
3
3
  let defaultName = null
4
4
 
5
5
  switch (Bare.platform) {
6
+ case 'android':
7
+ defaultName = 'android_camera'
8
+ break
6
9
  case 'darwin':
7
10
  case 'ios':
8
11
  defaultName = 'avfoundation'
package/lib/packet.js CHANGED
@@ -30,6 +30,10 @@ module.exports = class FFmpegPacket {
30
30
  return Buffer.from(binding.getPacketData(this._handle))
31
31
  }
32
32
 
33
+ get isKeyframe() {
34
+ return binding.isPacketKeyframe(this._handle)
35
+ }
36
+
33
37
  [Symbol.dispose]() {
34
38
  this.destroy()
35
39
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bare-ffmpeg",
3
- "version": "1.0.0-14",
3
+ "version": "1.0.0-15",
4
4
  "description": "Low-level FFmpeg bindings for Bare",
5
5
  "exports": {
6
6
  ".": "./index.js",