ffmpeg-progress 1.4.0 → 1.5.0

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
@@ -51,6 +51,15 @@ console.log(await getVideoResolution('test/rotate.mp4'))
51
51
  // { width: 3024, height: 4032 }
52
52
  ```
53
53
 
54
+ **Get video duration in seconds**:
55
+
56
+ ```typescript
57
+ import { getVideoDuration } from 'ffmpeg-progress'
58
+
59
+ console.log(await getVideoDuration('test/in.mp4'))
60
+ // 15.04 (duration in seconds)
61
+ ```
62
+
54
63
  ## Typescript Types
55
64
 
56
65
  ```typescript
@@ -107,6 +116,9 @@ export function getVideoResolution(video_file: string): Promise<{
107
116
  width: number
108
117
  height: number
109
118
  }>
119
+
120
+ /** @description get video duration in seconds, e.g. `15.04` */
121
+ export async function getVideoDuration(video_file: string): Promise<number>
110
122
  ```
111
123
 
112
124
  ## License
package/core.d.ts CHANGED
@@ -62,3 +62,5 @@ export declare function getVideoResolution(video_file: string): Promise<{
62
62
  width: number;
63
63
  height: number;
64
64
  }>;
65
+ /** @description get video duration in seconds, e.g. `15.04` */
66
+ export declare function getVideoDuration(video_file: string): Promise<number>;
package/core.js CHANGED
@@ -8,6 +8,7 @@ exports.convertFile = convertFile;
8
8
  exports.attachChildProcess = attachChildProcess;
9
9
  exports.estimateOutSize = estimateOutSize;
10
10
  exports.getVideoResolution = getVideoResolution;
11
+ exports.getVideoDuration = getVideoDuration;
11
12
  const child_process_1 = require("child_process");
12
13
  const promises_1 = require("fs/promises");
13
14
  const path_1 = require("path");
@@ -232,6 +233,27 @@ async function getVideoResolution(video_file) {
232
233
  await (0, promises_1.unlink)(image_file);
233
234
  return resolution;
234
235
  }
236
+ /** @description get video duration in seconds, e.g. `15.04` */
237
+ async function getVideoDuration(video_file) {
238
+ let childProcess = (0, child_process_1.spawn)('ffprobe', [
239
+ '-v',
240
+ 'error',
241
+ '-show_entries',
242
+ 'format=duration',
243
+ '-of',
244
+ 'default=noprint_wrappers=1:nokey=1',
245
+ video_file,
246
+ ]);
247
+ var { stdout, stderr, code, signal } = await waitChildProcess(childProcess);
248
+ if (code != 0) {
249
+ throw new Error(`ffprobe exit abnormally, exit code: ${code}, signal: ${signal}, stdout: ${stdout}, stderr: ${stderr}`);
250
+ }
251
+ let duration = +stdout;
252
+ if (!duration) {
253
+ throw new Error('failed to parse video duration: ' + JSON.stringify(stdout));
254
+ }
255
+ return duration;
256
+ }
235
257
  function waitChildProcess(childProcess) {
236
258
  return new Promise((resolve, reject) => {
237
259
  let stdout = '';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ffmpeg-progress",
3
- "version": "1.4.0",
3
+ "version": "1.5.0",
4
4
  "description": "Extract progress from ffmpeg child_process",
5
5
  "keywords": [
6
6
  "ffmpeg",