@remotion/renderer 4.0.0-offthread.21 → 4.0.0-offthread.27

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.
@@ -1,7 +1,17 @@
1
1
  /// <reference types="node" />
2
2
  import { FfmpegExecutable } from 'remotion';
3
- export declare const extractFrameFromVideo: ({ time, src, ffmpegExecutable, }: {
3
+ import { Readable } from 'stream';
4
+ export declare function streamToString(stream: Readable): Promise<string>;
5
+ export declare const getLastFrameOfVideo: ({ ffmpegExecutable, offset, src, }: {
6
+ ffmpegExecutable: FfmpegExecutable;
7
+ offset: number;
8
+ src: string;
9
+ }) => Promise<Buffer>;
10
+ declare type Options = {
4
11
  time: number;
5
12
  src: string;
6
13
  ffmpegExecutable: FfmpegExecutable;
7
- }) => import("stream").Readable | null;
14
+ };
15
+ export declare const extractFrameFromVideoFn: ({ time, src, ffmpegExecutable, }: Options) => Promise<Buffer>;
16
+ export declare const extractFrameFromVideo: (options: Options) => Promise<Buffer>;
17
+ export {};
@@ -3,12 +3,72 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.extractFrameFromVideo = void 0;
6
+ exports.extractFrameFromVideo = exports.extractFrameFromVideoFn = exports.getLastFrameOfVideo = exports.streamToString = void 0;
7
7
  const execa_1 = __importDefault(require("execa"));
8
8
  const frame_to_ffmpeg_timestamp_1 = require("./frame-to-ffmpeg-timestamp");
9
- const extractFrameFromVideo = ({ time, src, ffmpegExecutable, }) => {
9
+ const p_limit_1 = require("./p-limit");
10
+ function streamToString(stream) {
11
+ const chunks = [];
12
+ return new Promise((resolve, reject) => {
13
+ stream.on('data', (chunk) => chunks.push(Buffer.from(chunk)));
14
+ stream.on('error', (err) => reject(err));
15
+ stream.on('end', () => resolve(Buffer.concat(chunks).toString('utf8')));
16
+ });
17
+ }
18
+ exports.streamToString = streamToString;
19
+ const getLastFrameOfVideo = ({ ffmpegExecutable, offset, src, }) => {
20
+ if (offset > 100) {
21
+ throw new Error('could not get last frame of ' +
22
+ src +
23
+ '. Tried to seek 100ms before the end of the video and no frame was found. The video container has a duration that is longer than it contains video.');
24
+ }
25
+ const actualOffset = `-${offset + 10}ms`;
26
+ const { stdout, stderr } = (0, execa_1.default)(ffmpegExecutable !== null && ffmpegExecutable !== void 0 ? ffmpegExecutable : 'ffmpeg', [
27
+ '-sseof',
28
+ actualOffset,
29
+ '-i',
30
+ src,
31
+ '-frames:v',
32
+ '1',
33
+ '-f',
34
+ 'image2pipe',
35
+ '-',
36
+ ]);
37
+ if (!stderr) {
38
+ throw new Error('unexpectedly did not get stderr');
39
+ }
40
+ if (!stdout) {
41
+ throw new Error('unexpectedly did not get stdout');
42
+ }
43
+ const chunks = [];
44
+ return new Promise((resolve, reject) => {
45
+ let isEmpty = false;
46
+ stderr.on('data', (d) => {
47
+ if (d.toString().includes('Output file is empty')) {
48
+ isEmpty = true;
49
+ (0, exports.getLastFrameOfVideo)({ ffmpegExecutable, offset: offset + 10, src })
50
+ .then((frame) => resolve(frame))
51
+ .catch((err) => reject(err));
52
+ }
53
+ });
54
+ stdout.on('data', (d) => {
55
+ chunks.push(d);
56
+ });
57
+ stdout.on('error', (err) => {
58
+ reject(err);
59
+ });
60
+ stdout.on('end', () => {
61
+ if (!isEmpty) {
62
+ resolve(Buffer.concat(chunks));
63
+ }
64
+ });
65
+ });
66
+ };
67
+ exports.getLastFrameOfVideo = getLastFrameOfVideo;
68
+ const limit = (0, p_limit_1.pLimit)(5);
69
+ const extractFrameFromVideoFn = ({ time, src, ffmpegExecutable, }) => {
10
70
  const ffmpegTimestamp = (0, frame_to_ffmpeg_timestamp_1.frameToFfmpegTimestamp)(time);
11
- const { stdout } = (0, execa_1.default)(ffmpegExecutable !== null && ffmpegExecutable !== void 0 ? ffmpegExecutable : 'ffmpeg', [
71
+ const { stdout, stderr } = (0, execa_1.default)(ffmpegExecutable !== null && ffmpegExecutable !== void 0 ? ffmpegExecutable : 'ffmpeg', [
12
72
  '-ss',
13
73
  ffmpegTimestamp,
14
74
  '-i',
@@ -18,7 +78,41 @@ const extractFrameFromVideo = ({ time, src, ffmpegExecutable, }) => {
18
78
  '-f',
19
79
  'image2pipe',
20
80
  '-',
21
- ]);
22
- return stdout;
81
+ ], {
82
+ buffer: false,
83
+ });
84
+ if (!stderr) {
85
+ throw new Error('unexpectedly did not get stderr');
86
+ }
87
+ if (!stdout) {
88
+ throw new Error('unexpectedly did not get stdout');
89
+ }
90
+ const chunks = [];
91
+ return new Promise((resolve, reject) => {
92
+ let isEmpty = false;
93
+ stderr === null || stderr === void 0 ? void 0 : stderr.on('data', (d) => {
94
+ if (d.toString().includes('Output file is empty')) {
95
+ isEmpty = true;
96
+ (0, exports.getLastFrameOfVideo)({ ffmpegExecutable, offset: 0, src })
97
+ .then((frame) => resolve(frame))
98
+ .catch((err) => reject(err));
99
+ }
100
+ });
101
+ stdout === null || stdout === void 0 ? void 0 : stdout.on('data', (d) => {
102
+ chunks.push(d);
103
+ });
104
+ stdout === null || stdout === void 0 ? void 0 : stdout.on('error', (err) => {
105
+ reject(err);
106
+ });
107
+ stdout === null || stdout === void 0 ? void 0 : stdout.on('end', () => {
108
+ if (!isEmpty) {
109
+ resolve(Buffer.concat(chunks));
110
+ }
111
+ });
112
+ });
113
+ };
114
+ exports.extractFrameFromVideoFn = extractFrameFromVideoFn;
115
+ const extractFrameFromVideo = (options) => {
116
+ return limit(exports.extractFrameFromVideoFn, options);
23
117
  };
24
118
  exports.extractFrameFromVideo = extractFrameFromVideo;
File without changes
File without changes
File without changes
@@ -50,14 +50,8 @@ const startOffthreadVideoServer = (ffmpegExecutable, downloadDir, onDownload, on
50
50
  throw new Error('no readable from ffmpeg');
51
51
  }
52
52
  res.writeHead(200);
53
- readable
54
- .pipe(res)
55
- .on('close', () => {
56
- res.end();
57
- })
58
- .on('error', (err) => {
59
- onError(err);
60
- });
53
+ res.write(readable);
54
+ res.end();
61
55
  })
62
56
  .catch((err) => {
63
57
  res.writeHead(500);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@remotion/renderer",
3
- "version": "4.0.0-offthread.21+1965d2596",
3
+ "version": "4.0.0-offthread.27+32abe2e78",
4
4
  "description": "Renderer for Remotion",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -22,7 +22,7 @@
22
22
  "dependencies": {
23
23
  "execa": "5.1.1",
24
24
  "puppeteer-core": "13.5.1",
25
- "remotion": "4.0.0-offthread.21+1965d2596",
25
+ "remotion": "4.0.0-offthread.27+32abe2e78",
26
26
  "serve-handler": "6.1.3",
27
27
  "source-map": "^0.8.0-beta.0"
28
28
  },
@@ -59,5 +59,5 @@
59
59
  "publishConfig": {
60
60
  "access": "public"
61
61
  },
62
- "gitHead": "1965d2596493ada30f25a823ee3d85de7325c341"
62
+ "gitHead": "32abe2e782eb088fe72b1093f0ee35b1dd16ac8e"
63
63
  }