forked from Streampunk/beamcoder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathframeSpec.js
145 lines (136 loc) · 4.5 KB
/
frameSpec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
/*
Aerostat Beam Coder - Node.js native bindings for FFmpeg.
Copyright (C) 2019 Streampunk Media Ltd.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
https://www.streampunk.media/ mailto:furnace@streampunk.media
14 Ormiscaig, Aultbea, Achnasheen, IV22 2JJ U.K.
*/
const test = require('tape');
const beamcoder = require('../index.js');
const util = require('util');
test('Create a frame', t => {
let fr = beamcoder.frame();
t.ok(fr, 'is truthy.');
t.end();
});
test('Minimal JSON serialization', t => {
let fr = beamcoder.frame({});
let fp = JSON.stringify(fr);
t.ok(fp, 'JSON serialization is truthy.');
let pfp = JSON.parse(fp);
t.deepEqual(pfp, { type: 'Frame', linesize: [], reordered_opaque: 0 }, 'makes minimal JSON.');
let rf = beamcoder.frame(fp);
t.ok(rf, 'roundtrip is truthy.');
t.equal(util.inspect(rf), util.inspect(beamcoder.frame()), 'same as a new frame.');
t.end();
});
test('Maximal JSON serialization', t => {
let fr = beamcoder.frame({ type: 'Frame',
linesize: [42],
width: 43,
height: 44,
nb_samples: 45,
format: 'fltp',
key_frame: false,
pict_type: 'I',
sample_aspect_ratio: [ 16, 9 ],
pts: 46,
pkt_dts: 47,
coded_picture_number: 48,
display_picture_number: 49,
quality: 50,
repeat_pict: 51,
interlaced_frame: true,
top_field_first: true,
palette_has_changed: true,
reordered_opaque: 52,
sample_rate: 48000,
channel_layout: 'stereo',
data: [ Buffer.from('wibble wobble wibble wobble jelly on a place at least 42 chars and some more')],
side_data: { replaygain: Buffer.from('wibble') },
flags: { CORRUPT: true, DISCARD: false },
color_range: 'tv',
color_primaries: 'bt709',
color_trc: 'bt709',
colorspace: 'bt709',
chroma_location: 'top',
best_effort_timestamp: 53,
pkt_pos: 54,
pkt_duration: 55,
metadata: { fred: 'ginger' },
decode_error_flags: { INVALID_BITSTREAM: true, MISSING_REFERENCE: false },
channels: 2,
pkt_size: 56,
crop_top: 57,
crop_bottom: 58,
crop_left: 59,
crop_right: 60 });
t.ok(fr, 'frame is truthy.');
let fs = JSON.stringify(fr);
t.equal(typeof fs, 'string', 'stringify created a string.');
let rfr = beamcoder.frame(fs);
t.ok(rfr, 'roundtrip packet is truthy.');
t.deepEqual(util.inspect(rfr), util.inspect(beamcoder.frame({
linesize: [42],
width: 43,
height: 44,
nb_samples: 45,
format: 'fltp',
key_frame: false,
pict_type: 'I',
sample_aspect_ratio: [ 16, 9 ],
pts: 46,
pkt_dts: 47,
coded_picture_number: 48,
display_picture_number: 49,
quality: 50,
repeat_pict: 51,
interlaced_frame: true,
top_field_first: true,
palette_has_changed: true,
reordered_opaque: 52,
sample_rate: 48000,
channel_layout: 'stereo',
data: [], // Data does not roundtrip
side_data: { replaygain: Buffer.from('wibble') },
flags: { CORRUPT: true, DISCARD: false },
color_range: 'tv',
color_primaries: 'bt709',
color_trc: 'bt709',
colorspace: 'bt709',
chroma_location: 'top',
best_effort_timestamp: 53,
pkt_pos: 54,
pkt_duration: 55,
metadata: { fred: 'ginger' },
decode_error_flags: { INVALID_BITSTREAM: true, MISSING_REFERENCE: false },
channels: 2,
pkt_size: 56,
crop_top: 57,
crop_bottom: 58,
crop_left: 59,
crop_right: 60 })), 'roundtrips expected value.');
t.end();
});
test('Can delete data', t => {
let f = beamcoder.frame({ width: 1920, height: 1080, format: 'yuv420p' }).alloc();
t.ok(Array.isArray(f.data), 'data is an array ...');
t.ok(f.data.every(x => Buffer.isBuffer(x)), '... of buffers.');
t.equal(f.data.length, 3, 'data buffer has length 3.');
t.deepEqual(f.data.map(x => x.length),
f.linesize.map(x => x * f.height),
'buffer sizes as expected.');
f.data = null;
t.ok(Array.isArray(f.data), 'After reset, data is an array ...');
t.equal(f.data.length, 0, 'of length zero.');
t.end();
});