@quatrain/worker 1.2.12 → 1.2.14-pr25.8334

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.
@@ -137,7 +137,13 @@ class FileSystem {
137
137
  */
138
138
  static async uploadFile(filename, meta, mime = 'video/mp4') {
139
139
  // try to get more file metadata
140
- const info = await FileSystem.getInfo(filename);
140
+ let info = {};
141
+ try {
142
+ info = await FileSystem.getInfo(filename);
143
+ }
144
+ catch (err) {
145
+ Worker_1.Worker.warn(`Could not probe media info for ${filename}: ${err?.message || err}`);
146
+ }
141
147
  meta = { ...meta, ...info };
142
148
  Worker_1.Worker.info(`Uploading file ${filename} to ${meta.uploadUrl}`);
143
149
  const { size } = node_fs_1.default.statSync(filename);
@@ -167,13 +173,30 @@ class FileSystem {
167
173
  */
168
174
  static getInfo = (file) => {
169
175
  if (file.endsWith('.mp4') || file.endsWith('.insv')) {
176
+ try {
177
+ const ffprobeStatic = require('ffprobe-static');
178
+ if (ffprobeStatic && ffprobeStatic.path) {
179
+ ffmpeg.setFfprobePath(ffprobeStatic.path);
180
+ }
181
+ }
182
+ catch {
183
+ // ffprobe-static not present, fallback to system PATH
184
+ }
170
185
  return new Promise((resolve, reject) => ffmpeg.ffprobe(file, (err, metadata) => {
171
186
  if (err) {
172
187
  Worker_1.Worker.error(err);
173
- reject(err);
188
+ return reject(err);
189
+ }
190
+ if (!metadata || !metadata.streams || !metadata.streams.length) {
191
+ Worker_1.Worker.warn(`No streams found in ffprobe metadata for ${file}`);
192
+ return resolve({});
193
+ }
194
+ const videoStream = metadata.streams.find((s) => s.codec_type === 'video') ||
195
+ metadata.streams[0];
196
+ if (!videoStream) {
197
+ return resolve({});
174
198
  }
175
- // Worker.debug(`ffprobe getInfo: ${JSON.stringify(metadata)}`)
176
- const { width, height, duration, bit_rate: bitrate, nb_frames: nbFramees, } = metadata.streams[0];
199
+ const { width, height, duration, bit_rate: bitrate, nb_frames: nbFramees, } = videoStream;
177
200
  const nb_frames = Number.parseFloat(nbFramees);
178
201
  const framerate = nb_frames / Number.parseFloat(duration);
179
202
  resolve({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@quatrain/worker",
3
- "version": "1.2.12",
3
+ "version": "1.2.14-pr25.8334",
4
4
  "description": "Container Worker helpers",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -34,7 +34,7 @@
34
34
  "typescript": "^5.1.5"
35
35
  },
36
36
  "dependencies": {
37
- "@quatrain/core": "^1.2.17",
37
+ "@quatrain/core": "^1.2.18",
38
38
  "@quatrain/queue": "^1.2.3",
39
39
  "@quatrain/storage": "^1.2.13",
40
40
  "axios": "^1.7.7",
package/src/FileSystem.ts CHANGED
@@ -111,7 +111,12 @@ export class FileSystem {
111
111
  mime = 'video/mp4'
112
112
  ): Promise<FileType> {
113
113
  // try to get more file metadata
114
- const info = await FileSystem.getInfo(filename)
114
+ let info = {}
115
+ try {
116
+ info = await FileSystem.getInfo(filename)
117
+ } catch (err: any) {
118
+ Worker.warn(`Could not probe media info for ${filename}: ${(err as Error)?.message || err}`)
119
+ }
115
120
  meta = { ...meta, ...info }
116
121
  Worker.info(`Uploading file ${filename} to ${meta.uploadUrl}`)
117
122
  const { size } = fs.statSync(filename)
@@ -145,22 +150,46 @@ export class FileSystem {
145
150
  */
146
151
  static getInfo = (file: string): Promise<any> => {
147
152
  if (file.endsWith('.mp4') || file.endsWith('.insv')) {
153
+ try {
154
+ const ffprobeStatic = require('ffprobe-static')
155
+ if (ffprobeStatic && ffprobeStatic.path) {
156
+ ffmpeg.setFfprobePath(ffprobeStatic.path)
157
+ }
158
+ } catch {
159
+ // ffprobe-static not present, fallback to system PATH
160
+ }
161
+
148
162
  return new Promise((resolve, reject) =>
149
163
  ffmpeg.ffprobe(file, (err: any, metadata: any) => {
150
164
  if (err) {
151
165
  Worker.error(err)
152
- reject(err)
166
+ return reject(err)
167
+ }
168
+
169
+ if (!metadata || !metadata.streams || !metadata.streams.length) {
170
+ Worker.warn(`No streams found in ffprobe metadata for ${file}`)
171
+ return resolve({})
172
+ }
173
+
174
+ const videoStream =
175
+ metadata.streams.find((s: any) => s.codec_type === 'video') ||
176
+ metadata.streams[0]
177
+
178
+ if (!videoStream) {
179
+ return resolve({})
153
180
  }
154
- // Worker.debug(`ffprobe getInfo: ${JSON.stringify(metadata)}`)
181
+
155
182
  const {
156
183
  width,
157
184
  height,
158
185
  duration,
159
186
  bit_rate: bitrate,
160
187
  nb_frames: nbFramees,
161
- } = metadata.streams[0]
188
+ } = videoStream
189
+
162
190
  const nb_frames: number = Number.parseFloat(nbFramees as string)
163
191
  const framerate = nb_frames / Number.parseFloat(duration as string)
192
+
164
193
  resolve({
165
194
  width,
166
195
  height,