@dcmjs-org/video 0.0.0-bootstrap.0 → 1.0.0-beta.10
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/License.txt +22 -0
- package/README.md +141 -0
- package/dist/index.cjs +809 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.mjs +799 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +28 -4
package/License.txt
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
|
|
2
|
+
The MIT License (MIT)
|
|
3
|
+
|
|
4
|
+
Copyright (c) 2017 Steve Pieper
|
|
5
|
+
|
|
6
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
in the Software without restriction, including without limitation the rights
|
|
9
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
furnished to do so, subject to the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1 +1,142 @@
|
|
|
1
1
|
# @dcmjs-org/video
|
|
2
|
+
|
|
3
|
+
MP4-to-DICOM video encapsulation for dcmjs (Supplement 225). The package
|
|
4
|
+
reads the MP4 header without a decode, and puts the H.264 stream of the MP4
|
|
5
|
+
into a Video Photographic Image instance. The stream goes into the pixel data
|
|
6
|
+
fragments without a change, so the round trip is byte-identical.
|
|
7
|
+
|
|
8
|
+
- `parseMp4Info(bytes | reader)` (async) — the geometry, the timing, and
|
|
9
|
+
the transfer syntax of an MP4, without a decode.
|
|
10
|
+
- `buildVideoDataset(mp4Info, options)` (sync) — the dataset without
|
|
11
|
+
`PixelData`. It calls `createInstance` from `@dcmjs-org/core`, then sets
|
|
12
|
+
the stream attributes.
|
|
13
|
+
- `encapsulateVideo(mp4Bytes, options)` (async) — the buffered path. It
|
|
14
|
+
returns a `Promise` of the dataset with `PixelData` as fragments.
|
|
15
|
+
- `createVideoEventSource(input, options)` (async) — the streaming path.
|
|
16
|
+
It returns a `Promise` of `{ run, info, dataset }`:
|
|
17
|
+
- `run(listener)` emits the dataset and the fragments as events, with
|
|
18
|
+
one fragment in memory at a time. It returns a `Promise`.
|
|
19
|
+
- `info` is the `parseMp4Info` result.
|
|
20
|
+
- `dataset` is the `buildVideoDataset` result, without `PixelData`.
|
|
21
|
+
- `extractEncapsulatedVideo(dataset)` — gets the MP4 stream back from a
|
|
22
|
+
naturalized video instance.
|
|
23
|
+
- `videoBase` and `videoPhotographicBase` — the default base blocks.
|
|
24
|
+
|
|
25
|
+
The functions that read an MP4 are async, because `parseMp4Info` accepts a
|
|
26
|
+
random-access reader. `input` of `createVideoEventSource` is MP4 bytes or
|
|
27
|
+
such a reader.
|
|
28
|
+
|
|
29
|
+
The codec-free image builder (`buildImageDataset`) and the JPEG and H.264
|
|
30
|
+
header inspection are in `@dcmjs-org/imaging`.
|
|
31
|
+
|
|
32
|
+
## Options
|
|
33
|
+
|
|
34
|
+
The options of `buildVideoDataset`, `encapsulateVideo`, and
|
|
35
|
+
`createVideoEventSource` follow CORE-USR-1 in `packages/core/README.md`: the
|
|
36
|
+
`createInstance` controls, `overrides`, and these control keys. All of
|
|
37
|
+
them are options. `overrides` is a naturalized DICOM provider with the
|
|
38
|
+
forms of `baseDicom`, and holds only DICOM attributes. A control key never
|
|
39
|
+
goes in `overrides`. An extra option key has no effect (CORE-USR-7).
|
|
40
|
+
|
|
41
|
+
- `baseDicom` (default `videoBase`) — base blocks. `videoBase` has no
|
|
42
|
+
`predecessorBase`, so `predecessor: true` needs a custom base
|
|
43
|
+
(VID-USR-8).
|
|
44
|
+
- `fragmentBytes` (default 256 MiB) — the size of each `PixelData`
|
|
45
|
+
fragment. `buildVideoDataset` ignores it.
|
|
46
|
+
|
|
47
|
+
```js
|
|
48
|
+
const video = await encapsulateVideo(mp4Bytes, {
|
|
49
|
+
instance: priorInstanceInSeries,
|
|
50
|
+
dataLevel: "series",
|
|
51
|
+
overrides: { SeriesDescription: "Endoscopy" }
|
|
52
|
+
});
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## Scope and change rule
|
|
56
|
+
|
|
57
|
+
The shared requirements of `createInstance` (CORE-USR-n, CORE-IMP-n in
|
|
58
|
+
`packages/core/README.md`) apply to the video builders. This README lists
|
|
59
|
+
only the requirements of this package.
|
|
60
|
+
|
|
61
|
+
The change rule of the core README applies. Change a user requirement
|
|
62
|
+
(VID-USR-n) only when it describes the behaviour wrongly, or when the
|
|
63
|
+
intended user-facing behaviour changes, and name the change in the pull
|
|
64
|
+
request. The implementation requirements (VID-IMP-n) describe the current
|
|
65
|
+
approach, and can change freely. Do not renumber an identifier.
|
|
66
|
+
|
|
67
|
+
## § User requirements
|
|
68
|
+
|
|
69
|
+
- **VID-USR-1** `instance` is where the new video goes (CORE-USR-3). The
|
|
70
|
+
default levels do not copy the identity of `instance` (CORE-USR-4).
|
|
71
|
+
Without a `SOPClassUID` override, and without a custom `levels` that
|
|
72
|
+
lists `SOPClassUID`, `videoBase` sets the Video Photographic Image
|
|
73
|
+
`SOPClassUID`.
|
|
74
|
+
- **VID-USR-2** The stream attributes come from the MP4: `CineRate`,
|
|
75
|
+
`FrameTime`, `NumberOfFrames`, `Rows`, `Columns`,
|
|
76
|
+
`EncapsulatedPixelDataValueTotalLength (7FE0,0003)`, and
|
|
77
|
+
`_meta.TransferSyntaxUID`. `buildVideoDataset` sets them after
|
|
78
|
+
`createInstance`, and replaces an override of them with no warning.
|
|
79
|
+
This rule applies to each form of `overrides`. A field that `mp4Info`
|
|
80
|
+
does not give writes no attribute, so the value of the base, of
|
|
81
|
+
`instance`, or of `overrides` stays. The `_meta` rule of CORE-USR-13
|
|
82
|
+
applies: the builder always sets `_meta.TransferSyntaxUID`, and keeps
|
|
83
|
+
the other `_meta` keys. `encapsulateVideo` and `createVideoEventSource`
|
|
84
|
+
set `PixelData` from the stream. `createVideoEventSource` does not
|
|
85
|
+
change the `_meta` of the dataset that it returns. It makes the file
|
|
86
|
+
meta group of its events in a separate object. The file meta group
|
|
87
|
+
gets each key of the dataset `_meta`, for example
|
|
88
|
+
`ImplementationVersionName`. `createVideoEventSource` always sets
|
|
89
|
+
`TransferSyntaxUID`, `MediaStorageSOPClassUID`, and
|
|
90
|
+
`MediaStorageSOPInstanceUID` from the dataset. It sets
|
|
91
|
+
`FileMetaInformationVersion`, `ImplementationClassUID`, and
|
|
92
|
+
`ImplementationVersionName` only when the dataset `_meta` has no value.
|
|
93
|
+
Thus a caller can set these three keys and other file meta keys in
|
|
94
|
+
`overrides._meta`.
|
|
95
|
+
- **VID-USR-3** A caller can set in `overrides` the Image Pixel values
|
|
96
|
+
that the MPEG-4 AVC transfer syntaxes mandate (`SamplesPerPixel`,
|
|
97
|
+
`PhotometricInterpretation`, `PlanarConfiguration`, `BitsAllocated`,
|
|
98
|
+
`BitsStored`, `HighBit`, `PixelRepresentation`), and
|
|
99
|
+
`LossyImageCompression`. The builder permits this on purpose. A
|
|
100
|
+
conformant reader uses the values of the codec stream, and these values
|
|
101
|
+
take precedence over the dataset values.
|
|
102
|
+
- **VID-USR-4** An MP4 with a codec that no DICOM video transfer syntax
|
|
103
|
+
carries throws an error. The error gives an `ffmpeg` command that makes a
|
|
104
|
+
supported stream (H.264 Baseline, Main, or High, up to Level 4.2).
|
|
105
|
+
- **VID-USR-5** `fragmentBytes` is an even integer from 2 to 2^32-2. Each
|
|
106
|
+
other value throws an error.
|
|
107
|
+
- **VID-USR-6** `extractEncapsulatedVideo` returns the stream that was
|
|
108
|
+
encapsulated, byte for byte. It removes the pad byte of an odd-length
|
|
109
|
+
last fragment through the declared total length. A dataset that is not
|
|
110
|
+
a video throws an error. A video dataset has the Video Photographic
|
|
111
|
+
Image `SOPClassUID` or a video transfer syntax, and has `PixelData`.
|
|
112
|
+
- **VID-USR-7** `parseMp4Info`, and thus `encapsulateVideo` and
|
|
113
|
+
`createVideoEventSource`, throw an error for an MP4 that they cannot
|
|
114
|
+
read (CORE-IMP-11): no `ftyp` box first, a malformed box, no `moov`
|
|
115
|
+
box, no video track, a video track without `mdhd` or a sample
|
|
116
|
+
description, a malformed `stts` box, or no frame rate.
|
|
117
|
+
- **VID-USR-8** `videoBase` does not include `predecessorBase`
|
|
118
|
+
(CORE-USR-9). With the default base, `predecessor: true` has no effect:
|
|
119
|
+
the result has no `PredecessorDocumentsSequence`, and the builder throws
|
|
120
|
+
no predecessor error. For a predecessor, give
|
|
121
|
+
`baseDicom: combineBases(videoBase, predecessorBase)`, with
|
|
122
|
+
`predecessorBase` from `@dcmjs-org/core`.
|
|
123
|
+
|
|
124
|
+
## § Implementation requirements
|
|
125
|
+
|
|
126
|
+
- **VID-IMP-1** `videoBase` is `defaultInstanceBase`,
|
|
127
|
+
`videoPhotographicBase` (SOP class, Modality `XC`, the Image Pixel values
|
|
128
|
+
of VID-USR-3, `LossyImageCompression` `"01"`) (CORE-IMP-3). `videoBase`
|
|
129
|
+
has no `predecessorBase` (VID-USR-8).
|
|
130
|
+
- **VID-IMP-2** `buildVideoDataset` removes its control key `fragmentBytes`
|
|
131
|
+
before it calls `createInstance` (CORE-IMP-9), and passes `overrides`
|
|
132
|
+
and `postProcess` through.
|
|
133
|
+
- **VID-IMP-3** `EncapsulatedPixelDataValueTotalLength` is a BigInt,
|
|
134
|
+
because VR UV is a 64-bit unsigned integer.
|
|
135
|
+
- **VID-IMP-4** `extractEncapsulatedVideo` keeps all of the bytes when the
|
|
136
|
+
dataset has no total length, and returns `declaredLength: null`, so the
|
|
137
|
+
caller can choose a warning.
|
|
138
|
+
|
|
139
|
+
## Dependencies
|
|
140
|
+
|
|
141
|
+
The package builds on `@dcmjs-org/core`, `@dcmjs-org/imaging` (the shared
|
|
142
|
+
`h264TransferSyntaxUID` map), and `@dcmjs-org/parser`.
|