@dcmjs-org/video 1.0.0-beta.3 → 1.0.0-beta.5
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/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 +22 -7
- package/src/encapsulated/encapsulatedVideo.js +0 -338
- package/src/encapsulated/index.js +0 -21
- package/src/eventStream/fromVideo.js +0 -184
- package/src/image/index.js +0 -8
- package/src/image/mp4Info.js +0 -296
- package/src/index.js +0 -14
- package/test/encapsulatedVideo.test.js +0 -176
- package/test/eventStream/fromVideo.test.js +0 -231
- package/test/mp4Info.test.js +0 -115
- package/test/utils/makeTinyMp4.js +0 -240
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":["../src/image/mp4Info.js","../src/encapsulated/encapsulatedVideo.js","../src/eventStream/fromVideo.js"],"sourcesContent":["// src/image/mp4Info.js\n//\n// Minimal MP4 (ISO BMFF) header inspection: walk the box structure to recover\n// the geometry and timing DICOM needs (Rows/Columns/NumberOfFrames/frame rate)\n// and identify the matching video transfer syntax — WITHOUT decoding any\n// pixels. H.264 in MP4 is a legal DICOM transfer syntax family (Supplement\n// 225), so the MP4 stream can be carried as encapsulated PixelData verbatim;\n// only the moov metadata must be understood.\n//\n// The moov box normally sits AFTER the (potentially enormous) mdat box, so the\n// parser works against a random-access reader — { size, read(offset, length) }\n// — and never buffers more than the moov box itself (a few MB even for a\n// 20 GB file). Plain Uint8Array/ArrayBuffer input is wrapped in an in-memory\n// reader so both call styles share one code path.\n\n// The AVC profile/level → transfer syntax mapping moved to @dcmjs-org/imaging\n// (it's shared, codec-free lookup). parseMp4Info uses it to label the stream.\nimport { h264TransferSyntaxUID } from \"@dcmjs-org/imaging\";\n\n/** Wrap in-memory bytes in the random-access reader contract. */\nfunction memoryReader(input) {\n const bytes =\n input instanceof ArrayBuffer\n ? new Uint8Array(input)\n : new Uint8Array(input.buffer, input.byteOffset, input.byteLength);\n return {\n size: bytes.byteLength,\n read: (offset, length) =>\n Promise.resolve(bytes.subarray(offset, offset + length))\n };\n}\n\nfunction isReader(input) {\n return (\n input &&\n typeof input === \"object\" &&\n typeof input.read === \"function\" &&\n typeof input.size === \"number\"\n );\n}\n\n/** Big-endian readers over a Uint8Array (MP4 box fields are big-endian). */\nfunction u16(bytes, offset) {\n return (bytes[offset] << 8) | bytes[offset + 1];\n}\nfunction u32(bytes, offset) {\n return (\n (bytes[offset] * 0x1000000 +\n (bytes[offset + 1] << 16) +\n (bytes[offset + 2] << 8) +\n bytes[offset + 3]) >>>\n 0\n );\n}\nfunction u64(bytes, offset) {\n // Box sizes and v1 durations: safe as a Number (files < 2^53 bytes).\n return u32(bytes, offset) * 0x100000000 + u32(bytes, offset + 4);\n}\nfunction fourCC(bytes, offset) {\n return String.fromCharCode(\n bytes[offset],\n bytes[offset + 1],\n bytes[offset + 2],\n bytes[offset + 3]\n );\n}\n\n/**\n * Iterate the child boxes of a byte range inside an in-memory buffer.\n * Yields { type, offset, size, headerLength } with offset relative to `bytes`.\n */\nfunction* boxes(bytes, start, end) {\n let offset = start;\n while (offset + 8 <= end) {\n let size = u32(bytes, offset);\n const type = fourCC(bytes, offset + 4);\n let headerLength = 8;\n if (size === 1) {\n size = u64(bytes, offset + 8);\n headerLength = 16;\n } else if (size === 0) {\n size = end - offset;\n }\n if (size < headerLength || offset + size > end) {\n return; // malformed child; stop rather than walk garbage\n }\n yield { type, offset, size, headerLength };\n offset += size;\n }\n}\n\nfunction findBox(bytes, start, end, type) {\n for (const box of boxes(bytes, start, end)) {\n if (box.type === type) {\n return box;\n }\n }\n return null;\n}\n\n/**\n * Inspect an MP4 file and return what DICOM video encapsulation needs.\n *\n * @param {Uint8Array|ArrayBuffer|{size: number, read: (offset: number,\n * length: number) => Promise<Uint8Array>}} input - the MP4 bytes, or a\n * random-access reader over them (the streaming path for large files)\n * @returns {Promise<{ rows, columns, numberOfFrames, frameRate, cineRate,\n * frameTime, codec, profileIdc, levelIdc, transferSyntaxUID: string|null,\n * mp4ByteLength }>}\n * @throws on non-MP4 input or when no video track is present\n */\nexport async function parseMp4Info(input) {\n const reader = isReader(input) ? input : memoryReader(input);\n\n // Top-level scan: a handful of 16-byte header reads regardless of file\n // size. The first box must be ftyp — that is also the validity check.\n let offset = 0;\n let moovLocation = null;\n let first = true;\n while (offset + 8 <= reader.size) {\n const head = await reader.read(\n offset,\n Math.min(16, reader.size - offset)\n );\n let size = u32(head, 0);\n const type = fourCC(head, 4);\n if (size === 1) {\n if (head.byteLength < 16) {\n break;\n }\n size = u64(head, 8);\n } else if (size === 0) {\n size = reader.size - offset;\n }\n if (first && type !== \"ftyp\") {\n throw new Error(\n \"parseMp4Info: input is not an MP4 file (missing ftyp box)\"\n );\n }\n first = false;\n if (size < 8 || offset + size > reader.size) {\n throw new Error(\n `parseMp4Info: malformed box '${type}' at offset ${offset}`\n );\n }\n if (type === \"moov\") {\n moovLocation = { offset, size };\n break;\n }\n offset += size;\n }\n if (!moovLocation) {\n throw new Error(\n \"parseMp4Info: no moov box found — truncated or still-recording MP4\"\n );\n }\n\n // The moov box is metadata only (a few MB at most); buffer it whole.\n const moov = await reader.read(moovLocation.offset, moovLocation.size);\n\n // First trak whose handler is \"vide\".\n let video = null;\n for (const trak of boxes(moov, 8, moov.byteLength)) {\n if (trak.type !== \"trak\") {\n continue;\n }\n const trakEnd = trak.offset + trak.size;\n const mdia = findBox(moov, trak.offset + 8, trakEnd, \"mdia\");\n if (!mdia) {\n continue;\n }\n const mdiaEnd = mdia.offset + mdia.size;\n const hdlr = findBox(moov, mdia.offset + 8, mdiaEnd, \"hdlr\");\n // hdlr: 8 header + 4 version/flags + 4 pre_defined, then handler_type\n if (!hdlr || fourCC(moov, hdlr.offset + 16) !== \"vide\") {\n continue;\n }\n video = { mdia, mdiaEnd };\n break;\n }\n if (!video) {\n throw new Error(\n \"parseMp4Info: no video track found in the MP4 (audio-only file?)\"\n );\n }\n\n const { mdia, mdiaEnd } = video;\n\n // mdhd → timescale/duration (v0: 32-bit fields, v1: 64-bit times).\n const mdhd = findBox(moov, mdia.offset + 8, mdiaEnd, \"mdhd\");\n if (!mdhd) {\n throw new Error(\"parseMp4Info: video track has no mdhd box\");\n }\n const mdhdVersion = moov[mdhd.offset + 8];\n let timescale, duration;\n if (mdhdVersion === 1) {\n timescale = u32(moov, mdhd.offset + 12 + 16);\n duration = u64(moov, mdhd.offset + 12 + 20);\n } else {\n timescale = u32(moov, mdhd.offset + 12 + 8);\n duration = u32(moov, mdhd.offset + 12 + 12);\n }\n\n const minf = findBox(moov, mdia.offset + 8, mdiaEnd, \"minf\");\n const stbl =\n minf && findBox(moov, minf.offset + 8, minf.offset + minf.size, \"stbl\");\n const stsd =\n stbl && findBox(moov, stbl.offset + 8, stbl.offset + stbl.size, \"stsd\");\n if (!stsd) {\n throw new Error(\"parseMp4Info: video track has no sample description\");\n }\n const stblEnd = stbl.offset + stbl.size;\n\n // stsd: 8 header + 4 version/flags + 4 entry_count, then sample entries.\n const entry = stsd.offset + 16;\n const entrySize = u32(moov, entry);\n const codec = fourCC(moov, entry + 4);\n // VisualSampleEntry: 8 box header + 6 reserved + 2 data_reference_index\n // + 16 pre_defined/reserved → width at +32, height at +34 (validated\n // against real encoder output, not just the spec).\n const columns = u16(moov, entry + 32);\n const rows = u16(moov, entry + 34);\n\n // avcC → AVCDecoderConfigurationRecord: profile_idc and level_idc are\n // bytes 1 and 3 of the record. The fixed part of a VisualSampleEntry is\n // 86 bytes; codec-specific child boxes follow.\n let profileIdc = null;\n let levelIdc = null;\n if (codec === \"avc1\" || codec === \"avc3\") {\n const avcC = findBox(moov, entry + 86, entry + entrySize, \"avcC\");\n if (avcC) {\n profileIdc = moov[avcC.offset + 9];\n levelIdc = moov[avcC.offset + 11];\n }\n }\n\n // Frame count: stsz sample_count (authoritative), stts sum as fallback.\n let numberOfFrames = 0;\n const stsz = findBox(moov, stbl.offset + 8, stblEnd, \"stsz\");\n if (stsz) {\n numberOfFrames = u32(moov, stsz.offset + 16);\n }\n const stts = findBox(moov, stbl.offset + 8, stblEnd, \"stts\");\n if (!numberOfFrames && stts) {\n const entryCount = u32(moov, stts.offset + 12);\n // Each stts entry is 8 bytes after the 16-byte fixed part. A raw\n // entry_count beyond the box's own size is malformed: walking it\n // would read zero-coerced garbage past the box and block the thread\n // for seconds at large counts (review finding 15).\n if (16 + entryCount * 8 > stts.size) {\n throw new Error(\n `parseMp4Info: malformed stts box — entry_count ${entryCount} ` +\n `does not fit in a ${stts.size}-byte box`\n );\n }\n for (let i = 0; i < entryCount; i++) {\n numberOfFrames += u32(moov, stts.offset + 16 + i * 8);\n }\n }\n\n // Frame rate: exact from a single-entry stts (constant frame rate);\n // otherwise the average over the track (variable frame rate).\n let frameRate = null;\n if (stts && u32(moov, stts.offset + 12) === 1) {\n const sampleDelta = u32(moov, stts.offset + 20);\n if (sampleDelta > 0) {\n frameRate = timescale / sampleDelta;\n }\n }\n if (!frameRate && duration > 0 && numberOfFrames > 0) {\n frameRate = (numberOfFrames * timescale) / duration;\n }\n if (!frameRate) {\n throw new Error(\n \"parseMp4Info: could not determine the frame rate from the video track\"\n );\n }\n\n return {\n rows,\n columns,\n numberOfFrames,\n frameRate,\n cineRate: Math.round(frameRate),\n // FrameTime (0018,1063) is DS: milliseconds per frame as a string.\n frameTime: (1000 / frameRate).toFixed(6),\n codec,\n profileIdc,\n levelIdc,\n transferSyntaxUID:\n profileIdc !== null\n ? h264TransferSyntaxUID(profileIdc, levelIdc)\n : null,\n mp4ByteLength: reader.size\n };\n}\n","// src/encapsulated/encapsulatedVideo.js\n//\n// Video encapsulation (Supplement 225): an MP4's H.264 stream travels inside\n// a Video Photographic Image instance VERBATIM — the pixel data fragments are\n// consecutive byte ranges of the one MP4 stream, so extraction is\n// concatenation and the round trip is byte-identical. Two directions,\n// mirroring encapsulatedPdf.js:\n//\n// buildVideoDataset(mp4Info, options) — dataset shell (no PixelData), used\n// by both the buffered and the streaming encapsulation paths.\n// encapsulateVideo(mp4Bytes, options) — MP4 in (buffered): dataset plus\n// PixelData as fragment-sized ArrayBuffer slices.\n// extractEncapsulatedVideo(dataset) — MP4 out: recover the stream from a\n// naturalized video instance, truncated to the declared total length.\n//\n// The (7FE0,0003) Encapsulated Pixel Data Value Total Length element (VR UV,\n// uint64) records the exact stream length so the required trailing pad byte\n// on an odd-length final fragment can be dropped on extraction.\n\nimport {\n combineBases,\n createInstance,\n defaultInstanceBase,\n isVideoTransferSyntax\n} from \"@dcmjs-org/core\";\nimport { parseMp4Info } from \"../image/mp4Info.js\";\n\nconst VIDEO_PHOTOGRAPHIC_SOP_CLASS_UID = \"1.2.840.10008.5.1.4.1.1.77.1.4.1\";\n\n// 256 MiB: small enough that one in-flight fragment stays comfortably in\n// memory, large enough that a 21.8 GB stream is only ~82 fragments.\nconst DEFAULT_FRAGMENT_BYTES = 256 * 1024 * 1024;\n\n/**\n * Validate/default the encapsulation fragment size. Fragment item lengths are\n * 32-bit and must be even (PS3.5 §A.4), so the size must be an even integer\n * below 2^32-2.\n *\n * @param {number} [fragmentBytes]\n * @returns {number}\n */\nfunction normalizeFragmentBytes(fragmentBytes) {\n if (fragmentBytes === undefined || fragmentBytes === null) {\n return DEFAULT_FRAGMENT_BYTES;\n }\n if (\n !Number.isInteger(fragmentBytes) ||\n fragmentBytes < 2 ||\n fragmentBytes % 2 !== 0 ||\n fragmentBytes >= 0xfffffffe\n ) {\n throw new Error(\n `fragmentBytes must be an even integer between 2 and 2^32-2 ` +\n `(fragment item lengths are even 32-bit values); got ${fragmentBytes}`\n );\n }\n return fragmentBytes;\n}\n\n/** The corrective error for codecs no DICOM video transfer syntax carries. */\nfunction unsupportedCodecError(info) {\n const profile =\n info.profileIdc !== null\n ? ` profile ${info.profileIdc} level ${(info.levelIdc / 10).toFixed(\n 1\n )}`\n : \"\";\n return new Error(\n `unsupported video codec '${info.codec}'${profile} — DICOM video ` +\n \"encapsulation supports H.264 Baseline/Main/High up to Level 4.2. \" +\n \"Transcode first, e.g.: ffmpeg -i in.mp4 -c:v libx264 \" +\n \"-profile:v high -level 4.2 -c:a copy out.mp4\"\n );\n}\n\n/**\n * The Video Photographic Image attributes that do not depend on the stream:\n * XC modality, and the Image Pixel values that every MPEG-4 AVC transfer\n * syntax mandates (PS3.5 §8.2.6); the stream carries the real subsampling.\n */\nconst videoPhotographicBase = {\n SOPClassUID: VIDEO_PHOTOGRAPHIC_SOP_CLASS_UID,\n Modality: \"XC\",\n SamplesPerPixel: 3,\n PhotometricInterpretation: \"YBR_PARTIAL_420\",\n PlanarConfiguration: 0,\n BitsAllocated: 8,\n BitsStored: 8,\n HighBit: 7,\n PixelRepresentation: 0,\n LossyImageCompression: \"01\"\n};\n\n/**\n * The default base of `buildVideoDataset`: core instance defaults and the\n * Video Photographic Image block. It has no `predecessorBase`, so\n * `predecessor: true` has no effect; use\n * `combineBases(videoBase, predecessorBase)` for a predecessor\n * (CORE-USR-9). Use `.items` to build a variant.\n */\nconst videoBase = combineBases(defaultInstanceBase, videoPhotographicBase);\n\n/**\n * Build the naturalized dataset shell for a Video Photographic Image\n * instance — everything except PixelData, which the caller supplies either\n * buffered (encapsulateVideo) or as a fragment event stream\n * (createVideoEventSource).\n *\n * The dataset comes from {@link createInstance} with `videoBase`; the\n * options follow CORE-USR-1 (`packages/core/README.md`), and the video rules\n * are VID-USR-n in `packages/video/README.md`. The options object holds the\n * controls; the DICOM attributes go in `options.overrides` (a naturalized\n * DICOM provider with the forms of `baseDicom`). An extra option key has no\n * effect (CORE-USR-7). With `dataLevel: \"series\"`, `instance` is the sample\n * instance in the series (CORE-USR-5).\n *\n * The stream attributes are set last, and replace an override from each\n * form of `overrides` (VID-USR-2): CineRate and FrameTime from the measured\n * frame rate, NumberOfFrames, Rows, Columns, `_meta.TransferSyntaxUID`, and\n * the (7FE0,0003) total length as a BigInt (VR UV is a uint64). A field\n * that `mp4Info` does not give writes no attribute. The element list\n * mirrors the Supplement 225 fixture.\n *\n * @example\n * buildVideoDataset(mp4Info, {\n * instance,\n * overrides: { SeriesDescription: \"Endoscopy\" }\n * });\n *\n * @param {Object} mp4Info - parseMp4Info result\n * @param {Object} [options] - the createInstance options (`baseDicom`\n * defaults to `videoBase`; `overrides` holds the DICOM attributes;\n * createInstance calls `postProcess` before the builder sets the stream\n * attributes), plus the control option of the callers (`fragmentBytes`),\n * which is ignored here\n * @returns {Object} naturalized dataset with _meta/_vrMap, no PixelData\n */\nfunction buildVideoDataset(mp4Info, options = {}) {\n if (!mp4Info.transferSyntaxUID) {\n throw unsupportedCodecError(mp4Info);\n }\n\n // fragmentBytes is a control key of the callers (CORE-IMP-9).\n const { baseDicom = videoBase, fragmentBytes, ...rest } = options;\n const dataset = createInstance({ baseDicom, ...rest });\n\n const streamAttributes = {\n CineRate: mp4Info.cineRate,\n FrameTime: mp4Info.frameTime,\n NumberOfFrames: mp4Info.numberOfFrames,\n Rows: mp4Info.rows,\n Columns: mp4Info.columns\n };\n for (const [keyword, value] of Object.entries(streamAttributes)) {\n if (value !== undefined) {\n dataset[keyword] = value;\n }\n }\n // Exact stream length, without the pad byte of an odd-length final\n // fragment (Sup 225).\n dataset.EncapsulatedPixelDataValueTotalLength = BigInt(\n mp4Info.mp4ByteLength\n );\n // A copy that keeps the other _meta keys (CORE-USR-13).\n dataset._meta = {\n ...(dataset._meta || {}),\n TransferSyntaxUID: { Value: [mp4Info.transferSyntaxUID] }\n };\n dataset._vrMap = { ...(dataset._vrMap || {}), PixelData: \"OB\" };\n return dataset;\n}\n\n/**\n * Wrap MP4 bytes into a naturalized video instance, buffered: PixelData is an\n * array of fragment-sized ArrayBuffer slices ready for datasetToDict /\n * datasetToBuffer. For files too large to buffer, use\n * createVideoEventSource instead.\n *\n * @param {ArrayBuffer|Uint8Array} mp4Bytes\n * @param {Object} [options] - the buildVideoDataset options (the DICOM\n * attributes go in `overrides`), plus `fragmentBytes`\n * @returns {Promise<Object>} naturalized dataset\n */\nasync function encapsulateVideo(mp4Bytes, options = {}) {\n const bytes =\n mp4Bytes instanceof ArrayBuffer\n ? new Uint8Array(mp4Bytes)\n : new Uint8Array(\n mp4Bytes.buffer,\n mp4Bytes.byteOffset,\n mp4Bytes.byteLength\n );\n const info = await parseMp4Info(bytes);\n const dataset = buildVideoDataset(info, options);\n const fragmentBytes = normalizeFragmentBytes(options.fragmentBytes);\n\n const fragments = [];\n for (let offset = 0; offset < bytes.byteLength; offset += fragmentBytes) {\n const end = Math.min(offset + fragmentBytes, bytes.byteLength);\n // slice() so each fragment is an exact, unshared ArrayBuffer.\n fragments.push(\n bytes.buffer.slice(\n bytes.byteOffset + offset,\n bytes.byteOffset + end\n )\n );\n }\n dataset.PixelData = fragments;\n return dataset;\n}\n\n/** Unwrap one naturalized binary payload to fragments of Uint8Array. */\nfunction toFragmentList(payload) {\n if (payload === undefined || payload === null) {\n return [];\n }\n // A naturalized binary value is a list of fragments; DICOM JSON input\n // can also give { InlineBinary } (a buffer, a view, base64, or a list).\n if (\n typeof payload === \"object\" &&\n !(payload instanceof ArrayBuffer) &&\n !ArrayBuffer.isView(payload) &&\n !Array.isArray(payload) &&\n payload.InlineBinary !== undefined\n ) {\n payload = payload.InlineBinary;\n }\n const list = Array.isArray(payload) ? payload : [payload];\n return list.map(fragment => {\n if (typeof fragment === \"string\") {\n const binary = atob(fragment);\n const decoded = new Uint8Array(binary.length);\n for (let i = 0; i < binary.length; i++) {\n decoded[i] = binary.charCodeAt(i);\n }\n return decoded;\n }\n if (\n fragment &&\n typeof fragment === \"object\" &&\n !(fragment instanceof ArrayBuffer) &&\n !ArrayBuffer.isView(fragment) &&\n fragment.InlineBinary !== undefined\n ) {\n return toFragmentList(fragment)[0];\n }\n return ArrayBuffer.isView(fragment)\n ? new Uint8Array(\n fragment.buffer,\n fragment.byteOffset,\n fragment.byteLength\n )\n : new Uint8Array(fragment);\n });\n}\n\n/** The meta transfer syntax of a naturalized dataset, tolerant of shape. */\nfunction metaTransferSyntax(dataset) {\n const meta = dataset._meta;\n if (!meta) {\n return undefined;\n }\n const entry = meta.TransferSyntaxUID || meta[\"00020010\"];\n if (!entry) {\n return undefined;\n }\n if (typeof entry === \"string\") {\n return entry;\n }\n return Array.isArray(entry.Value) ? entry.Value[0] : entry.Value;\n}\n\n/**\n * Recover the verbatim video stream from a naturalized video instance.\n *\n * Fragments are concatenated and the result truncated to the declared\n * (7FE0,0003) total length, which drops the pad byte a Part 10 writer adds\n * to an odd-length final fragment. When the element is absent (older\n * producers), nothing is trimmed and `declaredLength` is null so the caller\n * can decide how loudly to warn. A dataset that is not a video throws an\n * error (VID-USR-6).\n *\n * @param {Object} dataset - naturalized video instance\n * @returns {{ bytes: Uint8Array, transferSyntaxUID: string|undefined,\n * declaredLength: number|null }}\n */\nfunction extractEncapsulatedVideo(dataset) {\n const transferSyntaxUID = metaTransferSyntax(dataset);\n const isVideo =\n dataset.SOPClassUID === VIDEO_PHOTOGRAPHIC_SOP_CLASS_UID ||\n isVideoTransferSyntax(transferSyntaxUID);\n if (!isVideo || dataset.PixelData === undefined) {\n throw new Error(\n \"extractEncapsulatedVideo: dataset is not an encapsulated video \" +\n \"instance (expected SOP Class \" +\n VIDEO_PHOTOGRAPHIC_SOP_CLASS_UID +\n \" or a video transfer syntax, with PixelData). \" +\n (transferSyntaxUID\n ? `Found transfer syntax ${transferSyntaxUID}. `\n : \"\") +\n \"For an Encapsulated PDF use extractEncapsulatedPdf; for \" +\n \"pixel images read the dataset with NaturalizedListener.\"\n );\n }\n\n const fragments = toFragmentList(dataset.PixelData);\n const total = fragments.reduce((n, f) => n + f.byteLength, 0);\n const out = new Uint8Array(total);\n let offset = 0;\n for (const fragment of fragments) {\n out.set(fragment, offset);\n offset += fragment.byteLength;\n }\n\n const declared = dataset.EncapsulatedPixelDataValueTotalLength;\n const declaredLength =\n declared === undefined || declared === null\n ? null\n : Number(Array.isArray(declared) ? declared[0] : declared);\n\n const bytes =\n declaredLength !== null && declaredLength <= out.byteLength\n ? out.subarray(0, declaredLength)\n : out;\n\n return { bytes, transferSyntaxUID, declaredLength };\n}\n\nexport {\n videoBase,\n videoPhotographicBase,\n buildVideoDataset,\n encapsulateVideo,\n extractEncapsulatedVideo,\n normalizeFragmentBytes,\n VIDEO_PHOTOGRAPHIC_SOP_CLASS_UID,\n DEFAULT_FRAGMENT_BYTES\n};\n","// src/eventStream/fromVideo.js\n//\n// MP4 → event stream (Supplement 225 video encapsulation). The dataset shell\n// is built eagerly (stable UIDs across re-runs); running the\n// stream replays the shell, then emits the MP4 as encapsulated PixelData\n// fragments read one at a time from a random-access reader — so a 21.8 GB\n// file streams with at most one fragment in memory, and the same code path\n// serves in-memory bytes.\n//\n// The natural sink is StreamingPart10Writer, which turns each binaryFragment\n// into one fragment item (undefined-length OB, empty Basic Offset Table,\n// even-padded items, sequence delimiter). Backpressure is honored between\n// fragments via listener.awaitDrain().\n\nimport { DicomMetaDictionary, EXPLICIT_LITTLE_ENDIAN } from \"@dcmjs-org/core\";\nimport { fromDataSet, EVENT_STREAM_VOCABULARY } from \"@dcmjs-org/parser\";\nimport { parseMp4Info } from \"../image/mp4Info.js\";\nimport {\n buildVideoDataset,\n normalizeFragmentBytes\n} from \"../encapsulated/encapsulatedVideo.js\";\n\nconst PIXEL_DATA_TAG = \"7FE00010\";\n\nconst IMPLEMENTATION_CLASS_UID =\n \"2.25.80302813137786398554742050926734630921603366648225212145404\";\n\n/**\n * Denaturalize a dataset into the plain `{ meta, dict }` shape fromDataSet\n * consumes: the file meta group is minted from the dataset identity exactly\n * the way legacy's datasetToDict does it, minus the DicomDict wrapper —\n * nothing here writes bytes, so no writer object is needed. The meta group\n * is a local object: the `_meta` of `dataset` does not change\n * (CORE-USR-13, CORE-IMP-7).\n *\n * Each other `_meta` key (its `Value[0]`) goes into the file meta group\n * (VID-USR-2). The defaults of `FileMetaInformationVersion`,\n * `ImplementationClassUID`, and `ImplementationVersionName` apply only when\n * `_meta` has no value. `MediaStorageSOPClassUID`,\n * `MediaStorageSOPInstanceUID`, and `TransferSyntaxUID` always come from the\n * dataset.\n */\nfunction datasetToMetaDict(dataset) {\n const fileMetaInformationVersionArray = new Uint8Array(2);\n fileMetaInformationVersionArray[1] = 1;\n\n const TransferSyntaxUID =\n dataset._meta?.TransferSyntaxUID?.Value?.[0] || EXPLICIT_LITTLE_ENDIAN;\n\n const callerMeta = {};\n for (const [keyword, entry] of Object.entries(dataset._meta || {})) {\n const value = Array.isArray(entry?.Value) ? entry.Value[0] : entry;\n if (value !== undefined && value !== null && value !== \"\") {\n callerMeta[keyword] = value;\n }\n }\n\n const meta = {\n FileMetaInformationVersion: fileMetaInformationVersionArray.buffer,\n ImplementationClassUID: IMPLEMENTATION_CLASS_UID,\n ImplementationVersionName: \"dcmjs-0.0\",\n ...callerMeta,\n MediaStorageSOPClassUID: dataset.SOPClassUID,\n MediaStorageSOPInstanceUID: dataset.SOPInstanceUID,\n TransferSyntaxUID\n };\n\n return {\n meta: DicomMetaDictionary.denaturalizeDataset(meta),\n dict: DicomMetaDictionary.denaturalizeDataset(dataset)\n };\n}\n\n/** Wrap in-memory bytes in the random-access reader contract. */\nfunction memoryReader(input) {\n const bytes =\n input instanceof ArrayBuffer\n ? new Uint8Array(input)\n : new Uint8Array(input.buffer, input.byteOffset, input.byteLength);\n return {\n size: bytes.byteLength,\n read: (offset, length) =>\n Promise.resolve(bytes.subarray(offset, offset + length))\n };\n}\n\n/**\n * Fragments must reach buffered sinks as EXACT buffers: the collector →\n * DicomDict.write path resolves a typed-array view to its whole backing\n * ArrayBuffer (byteOffset is lost), so a subarray view would serialize the\n * wrong bytes. Views that already span their full backing buffer (the\n * fd-read case in streaming CLIs) pass through copy-free.\n */\nfunction exactFragment(fragment) {\n if (\n ArrayBuffer.isView(fragment) &&\n (fragment.byteOffset !== 0 ||\n fragment.byteLength !== fragment.buffer.byteLength)\n ) {\n return fragment.buffer.slice(\n fragment.byteOffset,\n fragment.byteOffset + fragment.byteLength\n );\n }\n return fragment;\n}\n\n/**\n * A forwarding view of `listener` that swallows endDataSet, so the dataset\n * shell can be replayed first and the stream closed only after the pixel\n * data fragments. awaitDrain/setDrain forward too — backpressure must\n * survive the wrapper or the shell replay would run ungated.\n */\nfunction withoutEndDataSet(listener) {\n const wrapper = {};\n for (const method of EVENT_STREAM_VOCABULARY) {\n wrapper[method] = (...args) => listener[method](...args);\n }\n wrapper.endDataSet = () => {};\n wrapper.awaitDrain = () => listener.awaitDrain();\n wrapper.setDrain = fn => listener.setDrain(fn);\n return wrapper;\n}\n\n/**\n * Rebuild a dict with its tags in ascending order. fromDataSet emits entries\n * in key order and StreamingPart10Writer writes them as they arrive, so key\n * order IS file order; naturalized→denaturalized dicts follow property\n * insertion order, which need not be tag order. Fixed-width uppercase hex\n * sorts lexicographically === numerically.\n */\nfunction sortDict(dict) {\n const sorted = {};\n for (const tag of Object.keys(dict).sort()) {\n sorted[tag] = dict[tag];\n }\n return sorted;\n}\n\n/**\n * Create the video event source. The function is async, because\n * `parseMp4Info` reads the MP4 header through the reader. The returned\n * `dataset` is the result of `buildVideoDataset`, without `PixelData`;\n * `run(listener)` emits the dataset, then the MP4 as `PixelData` fragments.\n *\n * @param {Uint8Array|ArrayBuffer|{size, read(offset, length)}} input - MP4\n * bytes or a random-access reader over them\n * @param {Object} [options] - the buildVideoDataset options (the DICOM\n * attributes go in `overrides`), plus `fragmentBytes`\n * @returns {Promise<{ run: (listener) => Promise<void>, info: Object,\n * dataset: Object }>}\n */\nexport async function createVideoEventSource(input, options = {}) {\n const reader =\n input instanceof ArrayBuffer || ArrayBuffer.isView(input)\n ? memoryReader(input)\n : input;\n const info = await parseMp4Info(reader);\n const dataset = buildVideoDataset(info, options);\n const fragmentBytes = normalizeFragmentBytes(options.fragmentBytes);\n\n const dicomDict = datasetToMetaDict(dataset);\n dicomDict.dict = sortDict(dicomDict.dict);\n\n async function run(listener) {\n await fromDataSet(dicomDict, withoutEndDataSet(listener));\n\n listener.startElement(PIXEL_DATA_TAG, { vr: \"OB\", length: -1 });\n listener.startBinary({ encapsulated: true });\n for (let offset = 0; offset < reader.size; offset += fragmentBytes) {\n const length = Math.min(fragmentBytes, reader.size - offset);\n listener.binaryFragment(\n exactFragment(await reader.read(offset, length))\n );\n // The defined backpressure checkpoint between fragments.\n await listener.awaitDrain();\n }\n listener.endBinary();\n listener.endElement();\n listener.endDataSet();\n }\n\n return { run, info, dataset };\n}\n"],"names":["memoryReader"],"mappings":";;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AAMA;AACA,SAASA,cAAY,CAAC,KAAK,EAAE;AAC7B,IAAI,MAAM,KAAK;AACf,QAAQ,KAAK,YAAY;AACzB,cAAc,IAAI,UAAU,CAAC,KAAK;AAClC,cAAc,IAAI,UAAU,CAAC,KAAK,CAAC,MAAM,EAAE,KAAK,CAAC,UAAU,EAAE,KAAK,CAAC,UAAU,CAAC;AAC9E,IAAI,OAAO;AACX,QAAQ,IAAI,EAAE,KAAK,CAAC,UAAU;AAC9B,QAAQ,IAAI,EAAE,CAAC,MAAM,EAAE,MAAM;AAC7B,YAAY,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC;AACnE,KAAK;AACL;;AAEA,SAAS,QAAQ,CAAC,KAAK,EAAE;AACzB,IAAI;AACJ,QAAQ,KAAK;AACb,QAAQ,OAAO,KAAK,KAAK,QAAQ;AACjC,QAAQ,OAAO,KAAK,CAAC,IAAI,KAAK,UAAU;AACxC,QAAQ,OAAO,KAAK,CAAC,IAAI,KAAK;AAC9B;AACA;;AAEA;AACA,SAAS,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE;AAC5B,IAAI,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC;AACnD;AACA,SAAS,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE;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vE,QAAQ,QAAQ,CAAC,WAAW,CAAC,EAAE,YAAY,EAAE,IAAI,EAAE,CAAC;AACpD,QAAQ,KAAK,IAAI,MAAM,GAAG,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC,IAAI,EAAE,MAAM,IAAI,aAAa,EAAE;AAC5E,YAAY,MAAM,MAAM,GAAG,IAAI,CAAC,GAAG,CAAC,aAAa,EAAE,MAAM,CAAC,IAAI,GAAG,MAAM,CAAC;AACxE,YAAY,QAAQ,CAAC,cAAc;AACnC,gBAAgB,aAAa,CAAC,MAAM,MAAM,CAAC,IAAI,CAAC,MAAM,EAAE,MAAM,CAAC;AAC/D,aAAa;AACb;AACA,YAAY,MAAM,QAAQ,CAAC,UAAU,EAAE;AACvC,QAAQ;AACR,QAAQ,QAAQ,CAAC,SAAS,EAAE;AAC5B,QAAQ,QAAQ,CAAC,UAAU,EAAE;AAC7B,QAAQ,QAAQ,CAAC,UAAU,EAAE;AAC7B,IAAI;;AAEJ,IAAI,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,OAAO,EAAE;AACjC;;;;"}
|
package/package.json
CHANGED
|
@@ -1,8 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dcmjs-org/video",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.5",
|
|
4
4
|
"description": "MP4-to-DICOM video encapsulation for dcmjs (Supplement 225): MP4 header inspection without decoding, and wrapping/streaming an MP4's H.264 stream into a Video Photographic Image instance. Codec-free image building lives in @dcmjs-org/imaging",
|
|
5
|
-
"main": "./
|
|
5
|
+
"main": "./dist/index.cjs",
|
|
6
|
+
"exports": {
|
|
7
|
+
".": {
|
|
8
|
+
"import": "./dist/index.mjs",
|
|
9
|
+
"require": "./dist/index.cjs"
|
|
10
|
+
},
|
|
11
|
+
"./package.json": "./package.json"
|
|
12
|
+
},
|
|
13
|
+
"files": [
|
|
14
|
+
"dist",
|
|
15
|
+
"README.md"
|
|
16
|
+
],
|
|
6
17
|
"license": "MIT",
|
|
7
18
|
"repository": {
|
|
8
19
|
"type": "git",
|
|
@@ -10,11 +21,15 @@
|
|
|
10
21
|
"directory": "packages/video"
|
|
11
22
|
},
|
|
12
23
|
"dependencies": {
|
|
13
|
-
"@dcmjs-org/core": "1.0.0-beta.
|
|
14
|
-
"@dcmjs-org/imaging": "1.0.0-beta.
|
|
15
|
-
"@dcmjs-org/parser": "1.0.0-beta.
|
|
24
|
+
"@dcmjs-org/core": "1.0.0-beta.5",
|
|
25
|
+
"@dcmjs-org/imaging": "1.0.0-beta.5",
|
|
26
|
+
"@dcmjs-org/parser": "1.0.0-beta.5"
|
|
16
27
|
},
|
|
17
28
|
"devDependencies": {
|
|
18
|
-
"@dcmjs-org/generator": "1.0.0-beta.
|
|
19
|
-
}
|
|
29
|
+
"@dcmjs-org/generator": "1.0.0-beta.5"
|
|
30
|
+
},
|
|
31
|
+
"scripts": {
|
|
32
|
+
"build": "rollup -c ../../rollup.packages.config.mjs"
|
|
33
|
+
},
|
|
34
|
+
"module": "./dist/index.mjs"
|
|
20
35
|
}
|
|
@@ -1,338 +0,0 @@
|
|
|
1
|
-
// src/encapsulated/encapsulatedVideo.js
|
|
2
|
-
//
|
|
3
|
-
// Video encapsulation (Supplement 225): an MP4's H.264 stream travels inside
|
|
4
|
-
// a Video Photographic Image instance VERBATIM — the pixel data fragments are
|
|
5
|
-
// consecutive byte ranges of the one MP4 stream, so extraction is
|
|
6
|
-
// concatenation and the round trip is byte-identical. Two directions,
|
|
7
|
-
// mirroring encapsulatedPdf.js:
|
|
8
|
-
//
|
|
9
|
-
// buildVideoDataset(mp4Info, options) — dataset shell (no PixelData), used
|
|
10
|
-
// by both the buffered and the streaming encapsulation paths.
|
|
11
|
-
// encapsulateVideo(mp4Bytes, options) — MP4 in (buffered): dataset plus
|
|
12
|
-
// PixelData as fragment-sized ArrayBuffer slices.
|
|
13
|
-
// extractEncapsulatedVideo(dataset) — MP4 out: recover the stream from a
|
|
14
|
-
// naturalized video instance, truncated to the declared total length.
|
|
15
|
-
//
|
|
16
|
-
// The (7FE0,0003) Encapsulated Pixel Data Value Total Length element (VR UV,
|
|
17
|
-
// uint64) records the exact stream length so the required trailing pad byte
|
|
18
|
-
// on an odd-length final fragment can be dropped on extraction.
|
|
19
|
-
|
|
20
|
-
import {
|
|
21
|
-
combineBases,
|
|
22
|
-
createInstance,
|
|
23
|
-
defaultInstanceBase,
|
|
24
|
-
isVideoTransferSyntax
|
|
25
|
-
} from "@dcmjs-org/core";
|
|
26
|
-
import { parseMp4Info } from "../image/mp4Info.js";
|
|
27
|
-
|
|
28
|
-
const VIDEO_PHOTOGRAPHIC_SOP_CLASS_UID = "1.2.840.10008.5.1.4.1.1.77.1.4.1";
|
|
29
|
-
|
|
30
|
-
// 256 MiB: small enough that one in-flight fragment stays comfortably in
|
|
31
|
-
// memory, large enough that a 21.8 GB stream is only ~82 fragments.
|
|
32
|
-
const DEFAULT_FRAGMENT_BYTES = 256 * 1024 * 1024;
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* Validate/default the encapsulation fragment size. Fragment item lengths are
|
|
36
|
-
* 32-bit and must be even (PS3.5 §A.4), so the size must be an even integer
|
|
37
|
-
* below 2^32-2.
|
|
38
|
-
*
|
|
39
|
-
* @param {number} [fragmentBytes]
|
|
40
|
-
* @returns {number}
|
|
41
|
-
*/
|
|
42
|
-
function normalizeFragmentBytes(fragmentBytes) {
|
|
43
|
-
if (fragmentBytes === undefined || fragmentBytes === null) {
|
|
44
|
-
return DEFAULT_FRAGMENT_BYTES;
|
|
45
|
-
}
|
|
46
|
-
if (
|
|
47
|
-
!Number.isInteger(fragmentBytes) ||
|
|
48
|
-
fragmentBytes < 2 ||
|
|
49
|
-
fragmentBytes % 2 !== 0 ||
|
|
50
|
-
fragmentBytes >= 0xfffffffe
|
|
51
|
-
) {
|
|
52
|
-
throw new Error(
|
|
53
|
-
`fragmentBytes must be an even integer between 2 and 2^32-2 ` +
|
|
54
|
-
`(fragment item lengths are even 32-bit values); got ${fragmentBytes}`
|
|
55
|
-
);
|
|
56
|
-
}
|
|
57
|
-
return fragmentBytes;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
/** The corrective error for codecs no DICOM video transfer syntax carries. */
|
|
61
|
-
function unsupportedCodecError(info) {
|
|
62
|
-
const profile =
|
|
63
|
-
info.profileIdc !== null
|
|
64
|
-
? ` profile ${info.profileIdc} level ${(info.levelIdc / 10).toFixed(
|
|
65
|
-
1
|
|
66
|
-
)}`
|
|
67
|
-
: "";
|
|
68
|
-
return new Error(
|
|
69
|
-
`unsupported video codec '${info.codec}'${profile} — DICOM video ` +
|
|
70
|
-
"encapsulation supports H.264 Baseline/Main/High up to Level 4.2. " +
|
|
71
|
-
"Transcode first, e.g.: ffmpeg -i in.mp4 -c:v libx264 " +
|
|
72
|
-
"-profile:v high -level 4.2 -c:a copy out.mp4"
|
|
73
|
-
);
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
/**
|
|
77
|
-
* The Video Photographic Image attributes that do not depend on the stream:
|
|
78
|
-
* XC modality, and the Image Pixel values that every MPEG-4 AVC transfer
|
|
79
|
-
* syntax mandates (PS3.5 §8.2.6); the stream carries the real subsampling.
|
|
80
|
-
*/
|
|
81
|
-
const videoPhotographicBase = {
|
|
82
|
-
SOPClassUID: VIDEO_PHOTOGRAPHIC_SOP_CLASS_UID,
|
|
83
|
-
Modality: "XC",
|
|
84
|
-
SamplesPerPixel: 3,
|
|
85
|
-
PhotometricInterpretation: "YBR_PARTIAL_420",
|
|
86
|
-
PlanarConfiguration: 0,
|
|
87
|
-
BitsAllocated: 8,
|
|
88
|
-
BitsStored: 8,
|
|
89
|
-
HighBit: 7,
|
|
90
|
-
PixelRepresentation: 0,
|
|
91
|
-
LossyImageCompression: "01"
|
|
92
|
-
};
|
|
93
|
-
|
|
94
|
-
/**
|
|
95
|
-
* The default base of `buildVideoDataset`: core instance defaults and the
|
|
96
|
-
* Video Photographic Image block. It has no `predecessorBase`, so
|
|
97
|
-
* `predecessor: true` has no effect; use
|
|
98
|
-
* `combineBases(videoBase, predecessorBase)` for a predecessor
|
|
99
|
-
* (CORE-USR-9). Use `.items` to build a variant.
|
|
100
|
-
*/
|
|
101
|
-
const videoBase = combineBases(defaultInstanceBase, videoPhotographicBase);
|
|
102
|
-
|
|
103
|
-
/**
|
|
104
|
-
* Build the naturalized dataset shell for a Video Photographic Image
|
|
105
|
-
* instance — everything except PixelData, which the caller supplies either
|
|
106
|
-
* buffered (encapsulateVideo) or as a fragment event stream
|
|
107
|
-
* (createVideoEventSource).
|
|
108
|
-
*
|
|
109
|
-
* The dataset comes from {@link createInstance} with `videoBase`; the
|
|
110
|
-
* options follow CORE-USR-1 (`packages/core/README.md`), and the video rules
|
|
111
|
-
* are VID-USR-n in `packages/video/README.md`. The options object holds the
|
|
112
|
-
* controls; the DICOM attributes go in `options.overrides` (a naturalized
|
|
113
|
-
* DICOM provider with the forms of `baseDicom`). An extra option key has no
|
|
114
|
-
* effect (CORE-USR-7). With `dataLevel: "series"`, `instance` is the sample
|
|
115
|
-
* instance in the series (CORE-USR-5).
|
|
116
|
-
*
|
|
117
|
-
* The stream attributes are set last, and replace an override from each
|
|
118
|
-
* form of `overrides` (VID-USR-2): CineRate and FrameTime from the measured
|
|
119
|
-
* frame rate, NumberOfFrames, Rows, Columns, `_meta.TransferSyntaxUID`, and
|
|
120
|
-
* the (7FE0,0003) total length as a BigInt (VR UV is a uint64). A field
|
|
121
|
-
* that `mp4Info` does not give writes no attribute. The element list
|
|
122
|
-
* mirrors the Supplement 225 fixture.
|
|
123
|
-
*
|
|
124
|
-
* @example
|
|
125
|
-
* buildVideoDataset(mp4Info, {
|
|
126
|
-
* instance,
|
|
127
|
-
* overrides: { SeriesDescription: "Endoscopy" }
|
|
128
|
-
* });
|
|
129
|
-
*
|
|
130
|
-
* @param {Object} mp4Info - parseMp4Info result
|
|
131
|
-
* @param {Object} [options] - the createInstance options (`baseDicom`
|
|
132
|
-
* defaults to `videoBase`; `overrides` holds the DICOM attributes;
|
|
133
|
-
* createInstance calls `postProcess` before the builder sets the stream
|
|
134
|
-
* attributes), plus the control option of the callers (`fragmentBytes`),
|
|
135
|
-
* which is ignored here
|
|
136
|
-
* @returns {Object} naturalized dataset with _meta/_vrMap, no PixelData
|
|
137
|
-
*/
|
|
138
|
-
function buildVideoDataset(mp4Info, options = {}) {
|
|
139
|
-
if (!mp4Info.transferSyntaxUID) {
|
|
140
|
-
throw unsupportedCodecError(mp4Info);
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
// fragmentBytes is a control key of the callers (CORE-IMP-9).
|
|
144
|
-
const { baseDicom = videoBase, fragmentBytes, ...rest } = options;
|
|
145
|
-
const dataset = createInstance({ baseDicom, ...rest });
|
|
146
|
-
|
|
147
|
-
const streamAttributes = {
|
|
148
|
-
CineRate: mp4Info.cineRate,
|
|
149
|
-
FrameTime: mp4Info.frameTime,
|
|
150
|
-
NumberOfFrames: mp4Info.numberOfFrames,
|
|
151
|
-
Rows: mp4Info.rows,
|
|
152
|
-
Columns: mp4Info.columns
|
|
153
|
-
};
|
|
154
|
-
for (const [keyword, value] of Object.entries(streamAttributes)) {
|
|
155
|
-
if (value !== undefined) {
|
|
156
|
-
dataset[keyword] = value;
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
// Exact stream length, without the pad byte of an odd-length final
|
|
160
|
-
// fragment (Sup 225).
|
|
161
|
-
dataset.EncapsulatedPixelDataValueTotalLength = BigInt(
|
|
162
|
-
mp4Info.mp4ByteLength
|
|
163
|
-
);
|
|
164
|
-
// A copy that keeps the other _meta keys (CORE-USR-13).
|
|
165
|
-
dataset._meta = {
|
|
166
|
-
...(dataset._meta || {}),
|
|
167
|
-
TransferSyntaxUID: { Value: [mp4Info.transferSyntaxUID] }
|
|
168
|
-
};
|
|
169
|
-
dataset._vrMap = { ...(dataset._vrMap || {}), PixelData: "OB" };
|
|
170
|
-
return dataset;
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
/**
|
|
174
|
-
* Wrap MP4 bytes into a naturalized video instance, buffered: PixelData is an
|
|
175
|
-
* array of fragment-sized ArrayBuffer slices ready for datasetToDict /
|
|
176
|
-
* datasetToBuffer. For files too large to buffer, use
|
|
177
|
-
* createVideoEventSource instead.
|
|
178
|
-
*
|
|
179
|
-
* @param {ArrayBuffer|Uint8Array} mp4Bytes
|
|
180
|
-
* @param {Object} [options] - the buildVideoDataset options (the DICOM
|
|
181
|
-
* attributes go in `overrides`), plus `fragmentBytes`
|
|
182
|
-
* @returns {Promise<Object>} naturalized dataset
|
|
183
|
-
*/
|
|
184
|
-
async function encapsulateVideo(mp4Bytes, options = {}) {
|
|
185
|
-
const bytes =
|
|
186
|
-
mp4Bytes instanceof ArrayBuffer
|
|
187
|
-
? new Uint8Array(mp4Bytes)
|
|
188
|
-
: new Uint8Array(
|
|
189
|
-
mp4Bytes.buffer,
|
|
190
|
-
mp4Bytes.byteOffset,
|
|
191
|
-
mp4Bytes.byteLength
|
|
192
|
-
);
|
|
193
|
-
const info = await parseMp4Info(bytes);
|
|
194
|
-
const dataset = buildVideoDataset(info, options);
|
|
195
|
-
const fragmentBytes = normalizeFragmentBytes(options.fragmentBytes);
|
|
196
|
-
|
|
197
|
-
const fragments = [];
|
|
198
|
-
for (let offset = 0; offset < bytes.byteLength; offset += fragmentBytes) {
|
|
199
|
-
const end = Math.min(offset + fragmentBytes, bytes.byteLength);
|
|
200
|
-
// slice() so each fragment is an exact, unshared ArrayBuffer.
|
|
201
|
-
fragments.push(
|
|
202
|
-
bytes.buffer.slice(
|
|
203
|
-
bytes.byteOffset + offset,
|
|
204
|
-
bytes.byteOffset + end
|
|
205
|
-
)
|
|
206
|
-
);
|
|
207
|
-
}
|
|
208
|
-
dataset.PixelData = fragments;
|
|
209
|
-
return dataset;
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
/** Unwrap one naturalized binary payload to fragments of Uint8Array. */
|
|
213
|
-
function toFragmentList(payload) {
|
|
214
|
-
if (payload === undefined || payload === null) {
|
|
215
|
-
return [];
|
|
216
|
-
}
|
|
217
|
-
// The event-stream naturalizer wraps binary as { InlineBinary } (an
|
|
218
|
-
// ArrayBuffer, a view, a base64 string, or an array of fragments).
|
|
219
|
-
if (
|
|
220
|
-
typeof payload === "object" &&
|
|
221
|
-
!(payload instanceof ArrayBuffer) &&
|
|
222
|
-
!ArrayBuffer.isView(payload) &&
|
|
223
|
-
!Array.isArray(payload) &&
|
|
224
|
-
payload.InlineBinary !== undefined
|
|
225
|
-
) {
|
|
226
|
-
payload = payload.InlineBinary;
|
|
227
|
-
}
|
|
228
|
-
const list = Array.isArray(payload) ? payload : [payload];
|
|
229
|
-
return list.map(fragment => {
|
|
230
|
-
if (typeof fragment === "string") {
|
|
231
|
-
const binary = atob(fragment);
|
|
232
|
-
const decoded = new Uint8Array(binary.length);
|
|
233
|
-
for (let i = 0; i < binary.length; i++) {
|
|
234
|
-
decoded[i] = binary.charCodeAt(i);
|
|
235
|
-
}
|
|
236
|
-
return decoded;
|
|
237
|
-
}
|
|
238
|
-
if (
|
|
239
|
-
fragment &&
|
|
240
|
-
typeof fragment === "object" &&
|
|
241
|
-
!(fragment instanceof ArrayBuffer) &&
|
|
242
|
-
!ArrayBuffer.isView(fragment) &&
|
|
243
|
-
fragment.InlineBinary !== undefined
|
|
244
|
-
) {
|
|
245
|
-
return toFragmentList(fragment)[0];
|
|
246
|
-
}
|
|
247
|
-
return ArrayBuffer.isView(fragment)
|
|
248
|
-
? new Uint8Array(
|
|
249
|
-
fragment.buffer,
|
|
250
|
-
fragment.byteOffset,
|
|
251
|
-
fragment.byteLength
|
|
252
|
-
)
|
|
253
|
-
: new Uint8Array(fragment);
|
|
254
|
-
});
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
/** The meta transfer syntax of a naturalized dataset, tolerant of shape. */
|
|
258
|
-
function metaTransferSyntax(dataset) {
|
|
259
|
-
const meta = dataset._meta;
|
|
260
|
-
if (!meta) {
|
|
261
|
-
return undefined;
|
|
262
|
-
}
|
|
263
|
-
const entry = meta.TransferSyntaxUID || meta["00020010"];
|
|
264
|
-
if (!entry) {
|
|
265
|
-
return undefined;
|
|
266
|
-
}
|
|
267
|
-
if (typeof entry === "string") {
|
|
268
|
-
return entry;
|
|
269
|
-
}
|
|
270
|
-
return Array.isArray(entry.Value) ? entry.Value[0] : entry.Value;
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
/**
|
|
274
|
-
* Recover the verbatim video stream from a naturalized video instance.
|
|
275
|
-
*
|
|
276
|
-
* Fragments are concatenated and the result truncated to the declared
|
|
277
|
-
* (7FE0,0003) total length, which drops the pad byte a Part 10 writer adds
|
|
278
|
-
* to an odd-length final fragment. When the element is absent (older
|
|
279
|
-
* producers), nothing is trimmed and `declaredLength` is null so the caller
|
|
280
|
-
* can decide how loudly to warn. A dataset that is not a video throws an
|
|
281
|
-
* error (VID-USR-6).
|
|
282
|
-
*
|
|
283
|
-
* @param {Object} dataset - naturalized video instance
|
|
284
|
-
* @returns {{ bytes: Uint8Array, transferSyntaxUID: string|undefined,
|
|
285
|
-
* declaredLength: number|null }}
|
|
286
|
-
*/
|
|
287
|
-
function extractEncapsulatedVideo(dataset) {
|
|
288
|
-
const transferSyntaxUID = metaTransferSyntax(dataset);
|
|
289
|
-
const isVideo =
|
|
290
|
-
dataset.SOPClassUID === VIDEO_PHOTOGRAPHIC_SOP_CLASS_UID ||
|
|
291
|
-
isVideoTransferSyntax(transferSyntaxUID);
|
|
292
|
-
if (!isVideo || dataset.PixelData === undefined) {
|
|
293
|
-
throw new Error(
|
|
294
|
-
"extractEncapsulatedVideo: dataset is not an encapsulated video " +
|
|
295
|
-
"instance (expected SOP Class " +
|
|
296
|
-
VIDEO_PHOTOGRAPHIC_SOP_CLASS_UID +
|
|
297
|
-
" or a video transfer syntax, with PixelData). " +
|
|
298
|
-
(transferSyntaxUID
|
|
299
|
-
? `Found transfer syntax ${transferSyntaxUID}. `
|
|
300
|
-
: "") +
|
|
301
|
-
"For an Encapsulated PDF use extractEncapsulatedPdf; for " +
|
|
302
|
-
"pixel images read the dataset with NaturalizedListener."
|
|
303
|
-
);
|
|
304
|
-
}
|
|
305
|
-
|
|
306
|
-
const fragments = toFragmentList(dataset.PixelData);
|
|
307
|
-
const total = fragments.reduce((n, f) => n + f.byteLength, 0);
|
|
308
|
-
const out = new Uint8Array(total);
|
|
309
|
-
let offset = 0;
|
|
310
|
-
for (const fragment of fragments) {
|
|
311
|
-
out.set(fragment, offset);
|
|
312
|
-
offset += fragment.byteLength;
|
|
313
|
-
}
|
|
314
|
-
|
|
315
|
-
const declared = dataset.EncapsulatedPixelDataValueTotalLength;
|
|
316
|
-
const declaredLength =
|
|
317
|
-
declared === undefined || declared === null
|
|
318
|
-
? null
|
|
319
|
-
: Number(Array.isArray(declared) ? declared[0] : declared);
|
|
320
|
-
|
|
321
|
-
const bytes =
|
|
322
|
-
declaredLength !== null && declaredLength <= out.byteLength
|
|
323
|
-
? out.subarray(0, declaredLength)
|
|
324
|
-
: out;
|
|
325
|
-
|
|
326
|
-
return { bytes, transferSyntaxUID, declaredLength };
|
|
327
|
-
}
|
|
328
|
-
|
|
329
|
-
export {
|
|
330
|
-
videoBase,
|
|
331
|
-
videoPhotographicBase,
|
|
332
|
-
buildVideoDataset,
|
|
333
|
-
encapsulateVideo,
|
|
334
|
-
extractEncapsulatedVideo,
|
|
335
|
-
normalizeFragmentBytes,
|
|
336
|
-
VIDEO_PHOTOGRAPHIC_SOP_CLASS_UID,
|
|
337
|
-
DEFAULT_FRAGMENT_BYTES
|
|
338
|
-
};
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
// src/encapsulated/index.js — the video half of the encapsulated module.
|
|
2
|
-
// The PDF half (encapsulatePdf) is in @dcmjs-org/encapsulated.
|
|
3
|
-
import {
|
|
4
|
-
videoBase,
|
|
5
|
-
videoPhotographicBase,
|
|
6
|
-
buildVideoDataset,
|
|
7
|
-
encapsulateVideo,
|
|
8
|
-
extractEncapsulatedVideo,
|
|
9
|
-
VIDEO_PHOTOGRAPHIC_SOP_CLASS_UID,
|
|
10
|
-
DEFAULT_FRAGMENT_BYTES
|
|
11
|
-
} from "./encapsulatedVideo.js";
|
|
12
|
-
|
|
13
|
-
export {
|
|
14
|
-
videoBase,
|
|
15
|
-
videoPhotographicBase,
|
|
16
|
-
buildVideoDataset,
|
|
17
|
-
encapsulateVideo,
|
|
18
|
-
extractEncapsulatedVideo,
|
|
19
|
-
VIDEO_PHOTOGRAPHIC_SOP_CLASS_UID,
|
|
20
|
-
DEFAULT_FRAGMENT_BYTES
|
|
21
|
-
};
|