@xyo-network/image-thumbnail-plugin 2.75.0 → 2.75.2
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/dist/docs.json +50260 -0
- package/dist/node/Diviner/Config.d.cts +11 -0
- package/dist/node/Diviner/Config.d.cts.map +1 -0
- package/dist/node/Diviner/Config.js +3 -1
- package/dist/node/Diviner/Config.js.map +1 -1
- package/dist/node/Diviner/Config.mjs +2 -1
- package/dist/node/Diviner/Config.mjs.map +1 -1
- package/dist/node/Diviner/Diviner.d.cts +30 -0
- package/dist/node/Diviner/Diviner.d.cts.map +1 -0
- package/dist/node/Diviner/Diviner.js +19 -11
- package/dist/node/Diviner/Diviner.js.map +1 -1
- package/dist/node/Diviner/Diviner.mjs +17 -10
- package/dist/node/Diviner/Diviner.mjs.map +1 -1
- package/dist/node/Diviner/Params.d.cts +5 -0
- package/dist/node/Diviner/Params.d.cts.map +1 -0
- package/dist/node/Diviner/Params.js +2 -0
- package/dist/node/Diviner/Params.js.map +1 -1
- package/dist/node/Diviner/index.d.cts +4 -0
- package/dist/node/Diviner/index.d.cts.map +1 -0
- package/dist/node/Diviner/index.js +189 -7
- package/dist/node/Diviner/index.js.map +1 -1
- package/dist/node/Diviner/index.mjs +180 -3
- package/dist/node/Diviner/index.mjs.map +1 -1
- package/dist/node/Plugin.d.cts +116 -0
- package/dist/node/Plugin.d.cts.map +1 -0
- package/dist/node/Plugin.js +517 -7
- package/dist/node/Plugin.js.map +1 -1
- package/dist/node/Plugin.mjs +504 -5
- package/dist/node/Plugin.mjs.map +1 -1
- package/dist/node/Witness/Config.d.cts +16 -0
- package/dist/node/Witness/Config.d.cts.map +1 -0
- package/dist/node/Witness/Config.js +3 -1
- package/dist/node/Witness/Config.js.map +1 -1
- package/dist/node/Witness/Config.mjs +2 -1
- package/dist/node/Witness/Config.mjs.map +1 -1
- package/dist/node/Witness/Params.d.cts +7 -0
- package/dist/node/Witness/Params.d.cts.map +1 -0
- package/dist/node/Witness/Params.js +2 -0
- package/dist/node/Witness/Params.js.map +1 -1
- package/dist/node/Witness/Witness.d.cts +66 -0
- package/dist/node/Witness/Witness.d.cts.map +1 -0
- package/dist/node/Witness/Witness.js +78 -29
- package/dist/node/Witness/Witness.js.map +1 -1
- package/dist/node/Witness/Witness.mjs +70 -22
- package/dist/node/Witness/Witness.mjs.map +1 -1
- package/dist/node/Witness/ffmpeg/fluent/getVideoFrameAsImageFluent.d.cts +8 -0
- package/dist/node/Witness/ffmpeg/fluent/getVideoFrameAsImageFluent.d.cts.map +1 -0
- package/dist/node/Witness/ffmpeg/fluent/getVideoFrameAsImageFluent.js +5 -3
- package/dist/node/Witness/ffmpeg/fluent/getVideoFrameAsImageFluent.js.map +1 -1
- package/dist/node/Witness/ffmpeg/fluent/getVideoFrameAsImageFluent.mjs +4 -3
- package/dist/node/Witness/ffmpeg/fluent/getVideoFrameAsImageFluent.mjs.map +1 -1
- package/dist/node/Witness/ffmpeg/fluent/index.d.cts +2 -0
- package/dist/node/Witness/ffmpeg/fluent/index.d.cts.map +1 -0
- package/dist/node/Witness/ffmpeg/fluent/index.js +59 -3
- package/dist/node/Witness/ffmpeg/fluent/index.js.map +1 -1
- package/dist/node/Witness/ffmpeg/fluent/index.mjs +41 -1
- package/dist/node/Witness/ffmpeg/fluent/index.mjs.map +1 -1
- package/dist/node/Witness/ffmpeg/index.d.cts +3 -0
- package/dist/node/Witness/ffmpeg/index.d.cts.map +1 -0
- package/dist/node/Witness/ffmpeg/index.js +89 -5
- package/dist/node/Witness/ffmpeg/index.js.map +1 -1
- package/dist/node/Witness/ffmpeg/index.mjs +69 -2
- package/dist/node/Witness/ffmpeg/index.mjs.map +1 -1
- package/dist/node/Witness/ffmpeg/spawn/executeFfmpeg.d.cts +9 -0
- package/dist/node/Witness/ffmpeg/spawn/executeFfmpeg.d.cts.map +1 -0
- package/dist/node/Witness/ffmpeg/spawn/executeFfmpeg.js +3 -1
- package/dist/node/Witness/ffmpeg/spawn/executeFfmpeg.js.map +1 -1
- package/dist/node/Witness/ffmpeg/spawn/executeFfmpeg.mjs +2 -1
- package/dist/node/Witness/ffmpeg/spawn/executeFfmpeg.mjs.map +1 -1
- package/dist/node/Witness/ffmpeg/spawn/getVideoFrameAsImage.d.cts +8 -0
- package/dist/node/Witness/ffmpeg/spawn/getVideoFrameAsImage.d.cts.map +1 -0
- package/dist/node/Witness/ffmpeg/spawn/getVideoFrameAsImage.js +26 -3
- package/dist/node/Witness/ffmpeg/spawn/getVideoFrameAsImage.js.map +1 -1
- package/dist/node/Witness/ffmpeg/spawn/getVideoFrameAsImage.mjs +22 -2
- package/dist/node/Witness/ffmpeg/spawn/getVideoFrameAsImage.mjs.map +1 -1
- package/dist/node/Witness/ffmpeg/spawn/index.d.cts +3 -0
- package/dist/node/Witness/ffmpeg/spawn/index.d.cts.map +1 -0
- package/dist/node/Witness/ffmpeg/spawn/index.js +38 -5
- package/dist/node/Witness/ffmpeg/spawn/index.js.map +1 -1
- package/dist/node/Witness/ffmpeg/spawn/index.mjs +29 -2
- package/dist/node/Witness/ffmpeg/spawn/index.mjs.map +1 -1
- package/dist/node/Witness/index.d.cts +4 -0
- package/dist/node/Witness/index.d.cts.map +1 -0
- package/dist/node/Witness/index.js +343 -7
- package/dist/node/Witness/index.js.map +1 -1
- package/dist/node/Witness/index.mjs +324 -3
- package/dist/node/Witness/index.mjs.map +1 -1
- package/dist/node/index.d.cts +6 -0
- package/dist/node/index.d.cts.map +1 -0
- package/dist/node/index.js +542 -8
- package/dist/node/index.js.map +1 -1
- package/dist/node/index.mjs +523 -3
- package/dist/node/index.mjs.map +1 -1
- package/package.json +19 -19
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/Witness/Witness.ts"],"sourcesContent":["/* eslint-disable max-statements */\nimport { promises as dnsPromises } from 'node:dns'\n\nimport { compact } from '@xylabs/lodash'\nimport { URL } from '@xylabs/url'\nimport { axios, AxiosError, AxiosResponse } from '@xyo-network/axios'\nimport { PayloadHasher } from '@xyo-network/core'\nimport { ImageThumbnail, ImageThumbnailSchema } from '@xyo-network/image-thumbnail-payload-plugin'\nimport { UrlPayload, UrlSchema } from '@xyo-network/url-payload-plugin'\nimport { AbstractWitness } from '@xyo-network/witness'\nimport { Semaphore } from 'async-mutex'\nimport FileType from 'file-type'\nimport graphicsMagick from 'gm'\nimport hasbin from 'hasbin'\nimport { sha256 } from 'hash-wasm'\nimport { LRUCache } from 'lru-cache'\nimport shajs from 'sha.js'\nimport Url from 'url-parse'\n\nimport { ImageThumbnailEncoding, ImageThumbnailWitnessConfigSchema } from './Config'\nimport { getVideoFrameAsImageFluent } from './ffmpeg'\nimport { ImageThumbnailWitnessParams } from './Params'\n\n//TODO: Break this into two Witnesses?\n\n// setFfmpegPath(ffmpegPath)\n\n// eslint-disable-next-line import/no-named-as-default-member\nconst gm = graphicsMagick.subClass({ imageMagick: '7+' })\n\nexport interface ImageThumbnailWitnessError extends Error {\n name: 'ImageThumbnailWitnessError'\n url: string\n}\n\nexport interface DnsError extends Error {\n code: string\n}\n\nexport class ImageThumbnailWitness<TParams extends ImageThumbnailWitnessParams = ImageThumbnailWitnessParams> extends AbstractWitness<TParams> {\n static override configSchemas = [ImageThumbnailWitnessConfigSchema]\n\n private _cache?: LRUCache<string, ImageThumbnail>\n private _semaphore = new Semaphore(this.maxAsyncProcesses)\n\n get cache() {\n this._cache =\n this._cache ??\n new LRUCache<string, ImageThumbnail>({\n max: this.maxCacheEntries,\n maxSize: this.maxCacheBytes,\n //just returning the size of the data\n sizeCalculation: (value) => value.url?.length ?? 1,\n })\n return this._cache\n }\n\n get encoding() {\n return this.config.encoding ?? 'PNG'\n }\n\n get height() {\n return this.config.height ?? 128\n }\n\n get ipfGateway() {\n return this.config.ipfsGateway ?? '5d7b6582.beta.decentralnetworkservices.com'\n }\n\n get maxAsyncProcesses() {\n return this.config.maxAsyncProcesses ?? 2\n }\n\n get maxCacheBytes() {\n return this.config.maxCacheBytes ?? 1024 * 1024 * 16 //64MB max size\n }\n\n get maxCacheEntries() {\n return this.config.maxCacheEntries ?? 500\n }\n\n get quality() {\n return this.config.quality ?? 50\n }\n\n get width() {\n return this.config.width ?? 128\n }\n\n private static async binaryToSha256(data: Uint8Array) {\n await PayloadHasher.wasmInitialized\n if (PayloadHasher.wasmSupport.canUseWasm) {\n try {\n return await sha256(data)\n } catch (ex) {\n PayloadHasher.wasmSupport.allowWasm = false\n }\n }\n\n return shajs('sha256').update(data).digest().toString()\n }\n\n private static bufferFromDataUrl(url: string): Buffer | undefined {\n if (url.startsWith('data:image')) {\n const data = url.split(',')[1]\n if (data) {\n return Buffer.from(Uint8Array.from(atob(data), (c) => c.charCodeAt(0)))\n } else {\n const error: ImageThumbnailWitnessError = {\n message: 'Invalid data Url',\n name: 'ImageThumbnailWitnessError',\n url,\n }\n throw error\n }\n }\n }\n\n /**\n * Returns the equivalent IPFS gateway URL for the supplied URL.\n * @param urlToCheck The URL to check\n * @returns If the supplied URL is an IPFS URL, it converts the URL to the\n * equivalent IPFS gateway URL. Otherwise, returns the original URL.\n */\n checkIpfsUrl(urlToCheck: string) {\n const url = new URL(urlToCheck)\n let protocol = url.protocol\n let host = url.host\n let path = url.pathname\n const query = url.search\n if (protocol === 'ipfs:') {\n protocol = 'https:'\n host = this.ipfGateway\n path = url.host === 'ipfs' ? `ipfs${path}` : `ipfs/${url.host}${path}`\n const root = `${protocol}//${host}/${path}`\n return query?.length > 0 ? `${root}?${query}` : root\n } else {\n return urlToCheck\n }\n }\n\n protected override async observeHandler(payloads: UrlPayload[] = []): Promise<ImageThumbnail[]> {\n // eslint-disable-next-line import/no-named-as-default-member\n if (!hasbin.sync('magick')) {\n throw Error('ImageMagick is required for this witness')\n }\n const urlPayloads = payloads.filter((payload) => payload.schema === UrlSchema)\n return await this._semaphore.runExclusive(async () =>\n compact(\n await Promise.all(\n urlPayloads.map<Promise<ImageThumbnail>>(async ({ url }) => {\n const cachedResult = this.cache.get(url)\n if (cachedResult) {\n return cachedResult\n }\n let result: ImageThumbnail\n\n //if it is a data URL, return a Buffer\n const dataBuffer = ImageThumbnailWitness.bufferFromDataUrl(url)\n\n if (dataBuffer) {\n result = {\n schema: ImageThumbnailSchema,\n sourceHash: await ImageThumbnailWitness.binaryToSha256(dataBuffer),\n sourceUrl: url,\n url,\n }\n } else {\n //if it is ipfs, go through cloud flair\n const mutatedUrl = this.checkIpfsUrl(url)\n result = await this.fromHttp(mutatedUrl, url)\n }\n this.cache.set(url, result)\n return result\n }),\n ),\n ),\n )\n }\n\n private async createThumbnailDataUrl(sourceBuffer: Buffer, encoding?: ImageThumbnailEncoding) {\n const thumb = await new Promise<Buffer>((resolve, reject) => {\n gm(sourceBuffer)\n .quality(this.quality)\n .resize(this.width, this.height)\n .flatten()\n .toBuffer(encoding ?? this.encoding, (error, buffer) => {\n if (error) {\n reject(error)\n } else {\n resolve(buffer)\n }\n })\n })\n return `data:image/png;base64,${thumb.toString('base64')}`\n }\n\n /**\n * Creates an image thumbnail from a video.\n * @param videoBuffer The input video buffer.\n * @returns An buffer containing an image thumbnail for the video.\n */\n private async createThumbnailFromVideo(videoBuffer: Buffer) {\n const imageBuffer = await getVideoFrameAsImageFluent(videoBuffer)\n return this.createThumbnailDataUrl(imageBuffer)\n }\n\n private async fromHttp(url: string, sourceUrl?: string): Promise<ImageThumbnail> {\n let response: AxiosResponse\n let dnsResult: string[]\n try {\n const urlObj = new Url(url)\n dnsResult = await dnsPromises.resolve(urlObj.host)\n // console.log(`dnsResult: ${JSON.stringify(dnsResult, null, 2)}`)\n } catch (ex) {\n const error = ex as DnsError\n const result: ImageThumbnail = {\n http: {\n dnsError: error.code,\n },\n schema: ImageThumbnailSchema,\n sourceUrl: sourceUrl ?? url,\n }\n return result\n }\n try {\n response = await axios.get(url, {\n responseType: 'arraybuffer',\n })\n } catch (ex) {\n const axiosError = ex as AxiosError\n if (axiosError.isAxiosError) {\n //selectively pick fields from AxiosError\n const result: ImageThumbnail = {\n http: {\n ipAddress: dnsResult[0],\n status: axiosError?.response?.status,\n },\n schema: ImageThumbnailSchema,\n sourceUrl: sourceUrl ?? url,\n }\n return result\n } else {\n throw ex\n }\n }\n\n const result: ImageThumbnail = {\n http: {\n status: response.status,\n },\n schema: ImageThumbnailSchema,\n sourceUrl: sourceUrl ?? url,\n }\n\n if (response.status >= 200 && response.status < 300) {\n const contentType: string = response.headers['content-type']?.toString()\n const [mediaType, fileType] = contentType.split('/')\n result.mime = result.mime ?? {}\n result.mime.returned = mediaType\n const sourceBuffer = Buffer.from(response.data, 'binary')\n\n try {\n result.mime.detected = await FileType.fromBuffer(sourceBuffer)\n } catch (ex) {\n const error = ex as Error\n this.logger?.error(`FileType error: ${error.message}`)\n }\n\n const processImage = async (encoding?: ImageThumbnailEncoding) => {\n result.sourceHash = await ImageThumbnailWitness.binaryToSha256(sourceBuffer)\n result.url = await this.createThumbnailDataUrl(sourceBuffer, encoding)\n }\n\n const processVideo = async () => {\n // Gracefully handle the case where ffmpeg is not installed.\n // eslint-disable-next-line import/no-named-as-default-member\n if (hasbin.sync('ffmpeg')) {\n result.sourceHash = await ImageThumbnailWitness.binaryToSha256(sourceBuffer)\n result.url = await this.createThumbnailFromVideo(sourceBuffer)\n } else {\n result.mime = result.mime ?? {}\n result.mime.invalid = true\n }\n }\n\n let encoding: ImageThumbnailEncoding = 'PNG'\n\n switch (fileType.toUpperCase()) {\n case 'GIF':\n encoding = 'GIF'\n break\n case 'JPG':\n case 'JPEG':\n encoding = 'JPG'\n break\n }\n\n switch (mediaType) {\n case 'image': {\n await processImage(encoding)\n result.mime.type = mediaType\n break\n }\n case 'video': {\n await processVideo()\n result.mime.type = mediaType\n break\n }\n default: {\n switch (result.mime.detected?.mime) {\n case 'image': {\n await processImage()\n result.mime.type = result.mime.detected?.mime\n break\n }\n case 'video': {\n await processVideo()\n result.mime.type = result.mime.detected?.mime\n break\n }\n default: {\n result.mime.invalid = true\n break\n }\n }\n break\n }\n }\n }\n return result\n }\n}\n"],"mappings":"AAC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AAO,KAAK,UAAU;AACtB;AAAA,YACF;AAAA,UACF;AACA;AAAA,QACF;AAAA,MACF;AAAA,IACF;AACA,WAAO;AAAA,EACT;AACF;","names":["result","encoding"]}
|
|
1
|
+
{"version":3,"sources":["../../../src/Witness/Witness.ts","../../../src/Witness/Config.ts","../../../src/Witness/ffmpeg/fluent/getVideoFrameAsImageFluent.ts"],"sourcesContent":["/* eslint-disable max-statements */\nimport { promises as dnsPromises } from 'node:dns'\n\nimport { compact } from '@xylabs/lodash'\nimport { URL } from '@xylabs/url'\nimport { axios, AxiosError, AxiosResponse } from '@xyo-network/axios'\nimport { PayloadHasher } from '@xyo-network/core'\nimport { ImageThumbnail, ImageThumbnailSchema } from '@xyo-network/image-thumbnail-payload-plugin'\nimport { UrlPayload, UrlSchema } from '@xyo-network/url-payload-plugin'\nimport { AbstractWitness } from '@xyo-network/witness'\nimport { Semaphore } from 'async-mutex'\nimport FileType from 'file-type'\nimport graphicsMagick from 'gm'\nimport hasbin from 'hasbin'\nimport { sha256 } from 'hash-wasm'\nimport { LRUCache } from 'lru-cache'\nimport shajs from 'sha.js'\nimport Url from 'url-parse'\n\nimport { ImageThumbnailEncoding, ImageThumbnailWitnessConfigSchema } from './Config'\nimport { getVideoFrameAsImageFluent } from './ffmpeg'\nimport { ImageThumbnailWitnessParams } from './Params'\n\n//TODO: Break this into two Witnesses?\n\n// setFfmpegPath(ffmpegPath)\n\n// eslint-disable-next-line import/no-named-as-default-member\nconst gm = graphicsMagick.subClass({ imageMagick: '7+' })\n\nexport interface ImageThumbnailWitnessError extends Error {\n name: 'ImageThumbnailWitnessError'\n url: string\n}\n\nexport interface DnsError extends Error {\n code: string\n}\n\nexport class ImageThumbnailWitness<TParams extends ImageThumbnailWitnessParams = ImageThumbnailWitnessParams> extends AbstractWitness<TParams> {\n static override configSchemas = [ImageThumbnailWitnessConfigSchema]\n\n private _cache?: LRUCache<string, ImageThumbnail>\n private _semaphore = new Semaphore(this.maxAsyncProcesses)\n\n get cache() {\n this._cache =\n this._cache ??\n new LRUCache<string, ImageThumbnail>({\n max: this.maxCacheEntries,\n maxSize: this.maxCacheBytes,\n //just returning the size of the data\n sizeCalculation: (value) => value.url?.length ?? 1,\n })\n return this._cache\n }\n\n get encoding() {\n return this.config.encoding ?? 'PNG'\n }\n\n get height() {\n return this.config.height ?? 128\n }\n\n get ipfGateway() {\n return this.config.ipfsGateway ?? '5d7b6582.beta.decentralnetworkservices.com'\n }\n\n get maxAsyncProcesses() {\n return this.config.maxAsyncProcesses ?? 2\n }\n\n get maxCacheBytes() {\n return this.config.maxCacheBytes ?? 1024 * 1024 * 16 //64MB max size\n }\n\n get maxCacheEntries() {\n return this.config.maxCacheEntries ?? 500\n }\n\n get quality() {\n return this.config.quality ?? 50\n }\n\n get width() {\n return this.config.width ?? 128\n }\n\n private static async binaryToSha256(data: Uint8Array) {\n await PayloadHasher.wasmInitialized\n if (PayloadHasher.wasmSupport.canUseWasm) {\n try {\n return await sha256(data)\n } catch (ex) {\n PayloadHasher.wasmSupport.allowWasm = false\n }\n }\n\n return shajs('sha256').update(data).digest().toString()\n }\n\n private static bufferFromDataUrl(url: string): Buffer | undefined {\n if (url.startsWith('data:image')) {\n const data = url.split(',')[1]\n if (data) {\n return Buffer.from(Uint8Array.from(atob(data), (c) => c.charCodeAt(0)))\n } else {\n const error: ImageThumbnailWitnessError = {\n message: 'Invalid data Url',\n name: 'ImageThumbnailWitnessError',\n url,\n }\n throw error\n }\n }\n }\n\n /**\n * Returns the equivalent IPFS gateway URL for the supplied URL.\n * @param urlToCheck The URL to check\n * @returns If the supplied URL is an IPFS URL, it converts the URL to the\n * equivalent IPFS gateway URL. Otherwise, returns the original URL.\n */\n checkIpfsUrl(urlToCheck: string) {\n const url = new URL(urlToCheck)\n let protocol = url.protocol\n let host = url.host\n let path = url.pathname\n const query = url.search\n if (protocol === 'ipfs:') {\n protocol = 'https:'\n host = this.ipfGateway\n path = url.host === 'ipfs' ? `ipfs${path}` : `ipfs/${url.host}${path}`\n const root = `${protocol}//${host}/${path}`\n return query?.length > 0 ? `${root}?${query}` : root\n } else {\n return urlToCheck\n }\n }\n\n protected override async observeHandler(payloads: UrlPayload[] = []): Promise<ImageThumbnail[]> {\n // eslint-disable-next-line import/no-named-as-default-member\n if (!hasbin.sync('magick')) {\n throw Error('ImageMagick is required for this witness')\n }\n const urlPayloads = payloads.filter((payload) => payload.schema === UrlSchema)\n return await this._semaphore.runExclusive(async () =>\n compact(\n await Promise.all(\n urlPayloads.map<Promise<ImageThumbnail>>(async ({ url }) => {\n const cachedResult = this.cache.get(url)\n if (cachedResult) {\n return cachedResult\n }\n let result: ImageThumbnail\n\n //if it is a data URL, return a Buffer\n const dataBuffer = ImageThumbnailWitness.bufferFromDataUrl(url)\n\n if (dataBuffer) {\n result = {\n schema: ImageThumbnailSchema,\n sourceHash: await ImageThumbnailWitness.binaryToSha256(dataBuffer),\n sourceUrl: url,\n url,\n }\n } else {\n //if it is ipfs, go through cloud flair\n const mutatedUrl = this.checkIpfsUrl(url)\n result = await this.fromHttp(mutatedUrl, url)\n }\n this.cache.set(url, result)\n return result\n }),\n ),\n ),\n )\n }\n\n private async createThumbnailDataUrl(sourceBuffer: Buffer, encoding?: ImageThumbnailEncoding) {\n const thumb = await new Promise<Buffer>((resolve, reject) => {\n gm(sourceBuffer)\n .quality(this.quality)\n .resize(this.width, this.height)\n .flatten()\n .toBuffer(encoding ?? this.encoding, (error, buffer) => {\n if (error) {\n reject(error)\n } else {\n resolve(buffer)\n }\n })\n })\n return `data:image/png;base64,${thumb.toString('base64')}`\n }\n\n /**\n * Creates an image thumbnail from a video.\n * @param videoBuffer The input video buffer.\n * @returns An buffer containing an image thumbnail for the video.\n */\n private async createThumbnailFromVideo(videoBuffer: Buffer) {\n const imageBuffer = await getVideoFrameAsImageFluent(videoBuffer)\n return this.createThumbnailDataUrl(imageBuffer)\n }\n\n private async fromHttp(url: string, sourceUrl?: string): Promise<ImageThumbnail> {\n let response: AxiosResponse\n let dnsResult: string[]\n try {\n const urlObj = new Url(url)\n dnsResult = await dnsPromises.resolve(urlObj.host)\n // console.log(`dnsResult: ${JSON.stringify(dnsResult, null, 2)}`)\n } catch (ex) {\n const error = ex as DnsError\n const result: ImageThumbnail = {\n http: {\n dnsError: error.code,\n },\n schema: ImageThumbnailSchema,\n sourceUrl: sourceUrl ?? url,\n }\n return result\n }\n try {\n response = await axios.get(url, {\n responseType: 'arraybuffer',\n })\n } catch (ex) {\n const axiosError = ex as AxiosError\n if (axiosError.isAxiosError) {\n //selectively pick fields from AxiosError\n const result: ImageThumbnail = {\n http: {\n ipAddress: dnsResult[0],\n status: axiosError?.response?.status,\n },\n schema: ImageThumbnailSchema,\n sourceUrl: sourceUrl ?? url,\n }\n return result\n } else {\n throw ex\n }\n }\n\n const result: ImageThumbnail = {\n http: {\n status: response.status,\n },\n schema: ImageThumbnailSchema,\n sourceUrl: sourceUrl ?? url,\n }\n\n if (response.status >= 200 && response.status < 300) {\n const contentType: string = response.headers['content-type']?.toString()\n const [mediaType, fileType] = contentType.split('/')\n result.mime = result.mime ?? {}\n result.mime.returned = mediaType\n const sourceBuffer = Buffer.from(response.data, 'binary')\n\n try {\n result.mime.detected = await FileType.fromBuffer(sourceBuffer)\n } catch (ex) {\n const error = ex as Error\n this.logger?.error(`FileType error: ${error.message}`)\n }\n\n const processImage = async (encoding?: ImageThumbnailEncoding) => {\n result.sourceHash = await ImageThumbnailWitness.binaryToSha256(sourceBuffer)\n result.url = await this.createThumbnailDataUrl(sourceBuffer, encoding)\n }\n\n const processVideo = async () => {\n // Gracefully handle the case where ffmpeg is not installed.\n // eslint-disable-next-line import/no-named-as-default-member\n if (hasbin.sync('ffmpeg')) {\n result.sourceHash = await ImageThumbnailWitness.binaryToSha256(sourceBuffer)\n result.url = await this.createThumbnailFromVideo(sourceBuffer)\n } else {\n result.mime = result.mime ?? {}\n result.mime.invalid = true\n }\n }\n\n let encoding: ImageThumbnailEncoding = 'PNG'\n\n switch (fileType.toUpperCase()) {\n case 'GIF':\n encoding = 'GIF'\n break\n case 'JPG':\n case 'JPEG':\n encoding = 'JPG'\n break\n }\n\n switch (mediaType) {\n case 'image': {\n await processImage(encoding)\n result.mime.type = mediaType\n break\n }\n case 'video': {\n await processVideo()\n result.mime.type = mediaType\n break\n }\n default: {\n switch (result.mime.detected?.mime) {\n case 'image': {\n await processImage()\n result.mime.type = result.mime.detected?.mime\n break\n }\n case 'video': {\n await processVideo()\n result.mime.type = result.mime.detected?.mime\n break\n }\n default: {\n result.mime.invalid = true\n break\n }\n }\n break\n }\n }\n }\n return result\n }\n}\n","import { ImageThumbnailSchema } from '@xyo-network/image-thumbnail-payload-plugin'\nimport { WitnessConfig } from '@xyo-network/witness'\n\nexport const ImageThumbnailWitnessConfigSchema = `${ImageThumbnailSchema}.witness.config` as const\nexport type ImageThumbnailWitnessConfigSchema = typeof ImageThumbnailWitnessConfigSchema\n\nexport type ImageThumbnailEncoding = 'PNG' | 'JPG' | 'GIF'\n\nexport type ImageThumbnailWitnessConfig = WitnessConfig<{\n encoding?: ImageThumbnailEncoding\n height?: number\n ipfsGateway?: string\n maxAsyncProcesses?: number\n maxCacheBytes?: number\n maxCacheEntries?: number\n quality?: number\n schema: ImageThumbnailWitnessConfigSchema\n width?: number\n}>\n","import { uuid } from '@xyo-network/core'\nimport ffmpeg from 'fluent-ffmpeg'\nimport { unlink, writeFile } from 'fs/promises'\nimport { tmpdir } from 'os'\nimport { Writable, WritableOptions } from 'stream'\n\n/**\n * A Writable stream that collects output from ffmpeg.\n */\nclass FfmpegOutputStream extends Writable {\n private readonly chunks: Uint8Array[] = []\n\n constructor(options?: WritableOptions) {\n super(options)\n }\n\n override _write(chunk: never, _encoding: BufferEncoding, callback: (error?: Error | null) => void): void {\n this.chunks.push(chunk)\n callback()\n }\n\n /**\n * Collects the output from ffmpeg into a buffer.\n * @returns A buffer containing the concatenated\n * output from ffmpeg.\n */\n toBuffer = () => Buffer.concat(this.chunks)\n}\n\n/**\n * Execute FFmpeg using fluent API with provided input buffer and video thumbnail image.\n * @param videoBuffer Input video buffer.\n * @returns Output buffer containing the video thumbnail image.\n */\nexport const getVideoFrameAsImageFluent = async (videoBuffer: Buffer) => {\n // Get a temp file name\n const tmpFile = `/${tmpdir()}/${uuid()}`\n try {\n // Write videoBuffer to temp file for use as input to ffmpeg to\n // avoid issues with ffmpeg inferring premature EOF from buffer\n // passed via stdin (happens when ffmpeg is trying to infer\n // input video format)\n await writeFile(tmpFile, videoBuffer, { encoding: 'binary' })\n const imageBuffer = await new Promise<Buffer>((resolve, reject) => {\n // Create a Writable stream to collect PNG output from ffmpeg\n const ffmpegOutput = new FfmpegOutputStream()\n // Execute ffmpeg using fluent API\n ffmpeg()\n // NOTE: Uncomment to debug CLI args to ffmpeg\n // .on('start', (commandLine) => console.log('Spawned Ffmpeg with command: ' + commandLine))\n .on('error', (err) => reject(err.message))\n // Listen for the 'end' event to combine the output into a buffer holding the PNG image\n .on('end', () => resolve(ffmpegOutput.toBuffer()))\n .input(tmpFile) // Use temp file as input\n .takeFrames(1) // Only take 1st video frame\n .withNoAudio() // Don't include audio\n .outputOptions('-f image2pipe') // Write output to stdout\n .videoCodec('png') // Force PNG output\n // Start processing and direct ffmpeg stdout to writable stream\n .pipe(ffmpegOutput)\n })\n return imageBuffer\n } finally {\n // Cleanup temp file\n try {\n await unlink(tmpFile)\n } catch {\n // No error here since file doesn't exist\n }\n }\n}\n"],"mappings":";AACA,SAAS,YAAY,mBAAmB;AAExC,SAAS,eAAe;AACxB,SAAS,WAAW;AACpB,SAAS,aAAwC;AACjD,SAAS,qBAAqB;AAC9B,SAAyB,wBAAAA,6BAA4B;AACrD,SAAqB,iBAAiB;AACtC,SAAS,uBAAuB;AAChC,SAAS,iBAAiB;AAC1B,OAAO,cAAc;AACrB,OAAO,oBAAoB;AAC3B,OAAO,YAAY;AACnB,SAAS,cAAc;AACvB,SAAS,gBAAgB;AACzB,OAAO,WAAW;AAClB,OAAO,SAAS;;;ACjBhB,SAAS,4BAA4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,YAAY;AAAA,QAC/D,OAAO;AACL,iBAAO,OAAO,OAAO,QAAQ,CAAC;AAC9B,iBAAO,KAAK,UAAU;AAAA,QACxB;AAAA,MACF;AAEA,UAAI,WAAmC;AAEvC,cAAQ,SAAS,YAAY,GAAG;AAAA,QAC9B,KAAK;AACH,qBAAW;AACX;AAAA,QACF,KAAK;AAAA,QACL,KAAK;AACH,qBAAW;AACX;AAAA,MACJ;AAEA,cAAQ,WAAW;AAAA,QACjB,KAAK,SAAS;AACZ,gBAAM,aAAa,QAAQ;AAC3B,iBAAO,KAAK,OAAO;AACnB;AAAA,QACF;AAAA,QACA,KAAK,SAAS;AACZ,gBAAM,aAAa;AACnB,iBAAO,KAAK,OAAO;AACnB;AAAA,QACF;AAAA,QACA,SAAS;AACP,mBAAQ,YAAO,KAAK,aAAZ,mBAAsB,MAAM;AAAA,YAClC,KAAK,SAAS;AACZ,oBAAM,aAAa;AACnB,qBAAO,KAAK,QAAO,YAAO,KAAK,aAAZ,mBAAsB;AACzC;AAAA,YACF;AAAA,YACA,KAAK,SAAS;AACZ,oBAAM,aAAa;AACnB,qBAAO,KAAK,QAAO,YAAO,KAAK,aAAZ,mBAAsB;AACzC;AAAA,YACF;AAAA,YACA,SAAS;AACP,qBAAO,KAAK,UAAU;AACtB;AAAA,YACF;AAAA,UACF;AACA;AAAA,QACF;AAAA,MACF;AAAA,IACF;AACA,WAAO;AAAA,EACT;AACF;","names":["ImageThumbnailSchema","ImageThumbnailSchema","result","encoding"]}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
/**
|
|
3
|
+
* Execute FFmpeg using fluent API with provided input buffer and video thumbnail image.
|
|
4
|
+
* @param videoBuffer Input video buffer.
|
|
5
|
+
* @returns Output buffer containing the video thumbnail image.
|
|
6
|
+
*/
|
|
7
|
+
export declare const getVideoFrameAsImageFluent: (videoBuffer: Buffer) => Promise<Buffer>;
|
|
8
|
+
//# sourceMappingURL=getVideoFrameAsImageFluent.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getVideoFrameAsImageFluent.d.ts","sourceRoot":"","sources":["../../../../../src/Witness/ffmpeg/fluent/getVideoFrameAsImageFluent.ts"],"names":[],"mappings":";AA6BA;;;;GAIG;AACH,eAAO,MAAM,0BAA0B,gBAAuB,MAAM,oBAoCnE,CAAA"}
|
|
@@ -26,6 +26,8 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
26
26
|
mod
|
|
27
27
|
));
|
|
28
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/Witness/ffmpeg/fluent/getVideoFrameAsImageFluent.ts
|
|
29
31
|
var getVideoFrameAsImageFluent_exports = {};
|
|
30
32
|
__export(getVideoFrameAsImageFluent_exports, {
|
|
31
33
|
getVideoFrameAsImageFluent: () => getVideoFrameAsImageFluent
|
|
@@ -36,7 +38,7 @@ var import_fluent_ffmpeg = __toESM(require("fluent-ffmpeg"));
|
|
|
36
38
|
var import_promises = require("fs/promises");
|
|
37
39
|
var import_os = require("os");
|
|
38
40
|
var import_stream = require("stream");
|
|
39
|
-
|
|
41
|
+
var FfmpegOutputStream = class extends import_stream.Writable {
|
|
40
42
|
chunks = [];
|
|
41
43
|
constructor(options) {
|
|
42
44
|
super(options);
|
|
@@ -51,8 +53,8 @@ class FfmpegOutputStream extends import_stream.Writable {
|
|
|
51
53
|
* output from ffmpeg.
|
|
52
54
|
*/
|
|
53
55
|
toBuffer = () => Buffer.concat(this.chunks);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
+
};
|
|
57
|
+
var getVideoFrameAsImageFluent = async (videoBuffer) => {
|
|
56
58
|
const tmpFile = `/${(0, import_os.tmpdir)()}/${(0, import_core.uuid)()}`;
|
|
57
59
|
try {
|
|
58
60
|
await (0, import_promises.writeFile)(tmpFile, videoBuffer, { encoding: "binary" });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/Witness/ffmpeg/fluent/getVideoFrameAsImageFluent.ts"],"sourcesContent":["import { uuid } from '@xyo-network/core'\nimport ffmpeg from 'fluent-ffmpeg'\nimport { unlink, writeFile } from 'fs/promises'\nimport { tmpdir } from 'os'\nimport { Writable, WritableOptions } from 'stream'\n\n/**\n * A Writable stream that collects output from ffmpeg.\n */\nclass FfmpegOutputStream extends Writable {\n private readonly chunks: Uint8Array[] = []\n\n constructor(options?: WritableOptions) {\n super(options)\n }\n\n override _write(chunk: never, _encoding: BufferEncoding, callback: (error?: Error | null) => void): void {\n this.chunks.push(chunk)\n callback()\n }\n\n /**\n * Collects the output from ffmpeg into a buffer.\n * @returns A buffer containing the concatenated\n * output from ffmpeg.\n */\n toBuffer = () => Buffer.concat(this.chunks)\n}\n\n/**\n * Execute FFmpeg using fluent API with provided input buffer and video thumbnail image.\n * @param videoBuffer Input video buffer.\n * @returns Output buffer containing the video thumbnail image.\n */\nexport const getVideoFrameAsImageFluent = async (videoBuffer: Buffer) => {\n // Get a temp file name\n const tmpFile = `/${tmpdir()}/${uuid()}`\n try {\n // Write videoBuffer to temp file for use as input to ffmpeg to\n // avoid issues with ffmpeg inferring premature EOF from buffer\n // passed via stdin (happens when ffmpeg is trying to infer\n // input video format)\n await writeFile(tmpFile, videoBuffer, { encoding: 'binary' })\n const imageBuffer = await new Promise<Buffer>((resolve, reject) => {\n // Create a Writable stream to collect PNG output from ffmpeg\n const ffmpegOutput = new FfmpegOutputStream()\n // Execute ffmpeg using fluent API\n ffmpeg()\n // NOTE: Uncomment to debug CLI args to ffmpeg\n // .on('start', (commandLine) => console.log('Spawned Ffmpeg with command: ' + commandLine))\n .on('error', (err) => reject(err.message))\n // Listen for the 'end' event to combine the output into a buffer holding the PNG image\n .on('end', () => resolve(ffmpegOutput.toBuffer()))\n .input(tmpFile) // Use temp file as input\n .takeFrames(1) // Only take 1st video frame\n .withNoAudio() // Don't include audio\n .outputOptions('-f image2pipe') // Write output to stdout\n .videoCodec('png') // Force PNG output\n // Start processing and direct ffmpeg stdout to writable stream\n .pipe(ffmpegOutput)\n })\n return imageBuffer\n } finally {\n // Cleanup temp file\n try {\n await unlink(tmpFile)\n } catch {\n // No error here since file doesn't exist\n }\n }\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../../../../src/Witness/ffmpeg/fluent/getVideoFrameAsImageFluent.ts"],"sourcesContent":["import { uuid } from '@xyo-network/core'\nimport ffmpeg from 'fluent-ffmpeg'\nimport { unlink, writeFile } from 'fs/promises'\nimport { tmpdir } from 'os'\nimport { Writable, WritableOptions } from 'stream'\n\n/**\n * A Writable stream that collects output from ffmpeg.\n */\nclass FfmpegOutputStream extends Writable {\n private readonly chunks: Uint8Array[] = []\n\n constructor(options?: WritableOptions) {\n super(options)\n }\n\n override _write(chunk: never, _encoding: BufferEncoding, callback: (error?: Error | null) => void): void {\n this.chunks.push(chunk)\n callback()\n }\n\n /**\n * Collects the output from ffmpeg into a buffer.\n * @returns A buffer containing the concatenated\n * output from ffmpeg.\n */\n toBuffer = () => Buffer.concat(this.chunks)\n}\n\n/**\n * Execute FFmpeg using fluent API with provided input buffer and video thumbnail image.\n * @param videoBuffer Input video buffer.\n * @returns Output buffer containing the video thumbnail image.\n */\nexport const getVideoFrameAsImageFluent = async (videoBuffer: Buffer) => {\n // Get a temp file name\n const tmpFile = `/${tmpdir()}/${uuid()}`\n try {\n // Write videoBuffer to temp file for use as input to ffmpeg to\n // avoid issues with ffmpeg inferring premature EOF from buffer\n // passed via stdin (happens when ffmpeg is trying to infer\n // input video format)\n await writeFile(tmpFile, videoBuffer, { encoding: 'binary' })\n const imageBuffer = await new Promise<Buffer>((resolve, reject) => {\n // Create a Writable stream to collect PNG output from ffmpeg\n const ffmpegOutput = new FfmpegOutputStream()\n // Execute ffmpeg using fluent API\n ffmpeg()\n // NOTE: Uncomment to debug CLI args to ffmpeg\n // .on('start', (commandLine) => console.log('Spawned Ffmpeg with command: ' + commandLine))\n .on('error', (err) => reject(err.message))\n // Listen for the 'end' event to combine the output into a buffer holding the PNG image\n .on('end', () => resolve(ffmpegOutput.toBuffer()))\n .input(tmpFile) // Use temp file as input\n .takeFrames(1) // Only take 1st video frame\n .withNoAudio() // Don't include audio\n .outputOptions('-f image2pipe') // Write output to stdout\n .videoCodec('png') // Force PNG output\n // Start processing and direct ffmpeg stdout to writable stream\n .pipe(ffmpegOutput)\n })\n return imageBuffer\n } finally {\n // Cleanup temp file\n try {\n await unlink(tmpFile)\n } catch {\n // No error here since file doesn't exist\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAAqB;AACrB,2BAAmB;AACnB,sBAAkC;AAClC,gBAAuB;AACvB,oBAA0C;AAK1C,IAAM,qBAAN,cAAiC,uBAAS;AAAA,EACvB,SAAuB,CAAC;AAAA,EAEzC,YAAY,SAA2B;AACrC,UAAM,OAAO;AAAA,EACf;AAAA,EAES,OAAO,OAAc,WAA2B,UAAgD;AACvG,SAAK,OAAO,KAAK,KAAK;AACtB,aAAS;AAAA,EACX;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,WAAW,MAAM,OAAO,OAAO,KAAK,MAAM;AAC5C;AAOO,IAAM,6BAA6B,OAAO,gBAAwB;AAEvE,QAAM,UAAU,QAAI,kBAAO,CAAC,QAAI,kBAAK,CAAC;AACtC,MAAI;AAKF,cAAM,2BAAU,SAAS,aAAa,EAAE,UAAU,SAAS,CAAC;AAC5D,UAAM,cAAc,MAAM,IAAI,QAAgB,CAAC,SAAS,WAAW;AAEjE,YAAM,eAAe,IAAI,mBAAmB;AAE5C,+BAAAA,SAAO,EAGJ,GAAG,SAAS,CAAC,QAAQ,OAAO,IAAI,OAAO,CAAC,EAExC,GAAG,OAAO,MAAM,QAAQ,aAAa,SAAS,CAAC,CAAC,EAChD,MAAM,OAAO,EACb,WAAW,CAAC,EACZ,YAAY,EACZ,cAAc,eAAe,EAC7B,WAAW,KAAK,EAEhB,KAAK,YAAY;AAAA,IACtB,CAAC;AACD,WAAO;AAAA,EACT,UAAE;AAEA,QAAI;AACF,gBAAM,wBAAO,OAAO;AAAA,IACtB,QAAQ;AAAA,IAER;AAAA,EACF;AACF;","names":["ffmpeg"]}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
+
// src/Witness/ffmpeg/fluent/getVideoFrameAsImageFluent.ts
|
|
1
2
|
import { uuid } from "@xyo-network/core";
|
|
2
3
|
import ffmpeg from "fluent-ffmpeg";
|
|
3
4
|
import { unlink, writeFile } from "fs/promises";
|
|
4
5
|
import { tmpdir } from "os";
|
|
5
6
|
import { Writable } from "stream";
|
|
6
|
-
|
|
7
|
+
var FfmpegOutputStream = class extends Writable {
|
|
7
8
|
chunks = [];
|
|
8
9
|
constructor(options) {
|
|
9
10
|
super(options);
|
|
@@ -18,8 +19,8 @@ class FfmpegOutputStream extends Writable {
|
|
|
18
19
|
* output from ffmpeg.
|
|
19
20
|
*/
|
|
20
21
|
toBuffer = () => Buffer.concat(this.chunks);
|
|
21
|
-
}
|
|
22
|
-
|
|
22
|
+
};
|
|
23
|
+
var getVideoFrameAsImageFluent = async (videoBuffer) => {
|
|
23
24
|
const tmpFile = `/${tmpdir()}/${uuid()}`;
|
|
24
25
|
try {
|
|
25
26
|
await writeFile(tmpFile, videoBuffer, { encoding: "binary" });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/Witness/ffmpeg/fluent/getVideoFrameAsImageFluent.ts"],"sourcesContent":["import { uuid } from '@xyo-network/core'\nimport ffmpeg from 'fluent-ffmpeg'\nimport { unlink, writeFile } from 'fs/promises'\nimport { tmpdir } from 'os'\nimport { Writable, WritableOptions } from 'stream'\n\n/**\n * A Writable stream that collects output from ffmpeg.\n */\nclass FfmpegOutputStream extends Writable {\n private readonly chunks: Uint8Array[] = []\n\n constructor(options?: WritableOptions) {\n super(options)\n }\n\n override _write(chunk: never, _encoding: BufferEncoding, callback: (error?: Error | null) => void): void {\n this.chunks.push(chunk)\n callback()\n }\n\n /**\n * Collects the output from ffmpeg into a buffer.\n * @returns A buffer containing the concatenated\n * output from ffmpeg.\n */\n toBuffer = () => Buffer.concat(this.chunks)\n}\n\n/**\n * Execute FFmpeg using fluent API with provided input buffer and video thumbnail image.\n * @param videoBuffer Input video buffer.\n * @returns Output buffer containing the video thumbnail image.\n */\nexport const getVideoFrameAsImageFluent = async (videoBuffer: Buffer) => {\n // Get a temp file name\n const tmpFile = `/${tmpdir()}/${uuid()}`\n try {\n // Write videoBuffer to temp file for use as input to ffmpeg to\n // avoid issues with ffmpeg inferring premature EOF from buffer\n // passed via stdin (happens when ffmpeg is trying to infer\n // input video format)\n await writeFile(tmpFile, videoBuffer, { encoding: 'binary' })\n const imageBuffer = await new Promise<Buffer>((resolve, reject) => {\n // Create a Writable stream to collect PNG output from ffmpeg\n const ffmpegOutput = new FfmpegOutputStream()\n // Execute ffmpeg using fluent API\n ffmpeg()\n // NOTE: Uncomment to debug CLI args to ffmpeg\n // .on('start', (commandLine) => console.log('Spawned Ffmpeg with command: ' + commandLine))\n .on('error', (err) => reject(err.message))\n // Listen for the 'end' event to combine the output into a buffer holding the PNG image\n .on('end', () => resolve(ffmpegOutput.toBuffer()))\n .input(tmpFile) // Use temp file as input\n .takeFrames(1) // Only take 1st video frame\n .withNoAudio() // Don't include audio\n .outputOptions('-f image2pipe') // Write output to stdout\n .videoCodec('png') // Force PNG output\n // Start processing and direct ffmpeg stdout to writable stream\n .pipe(ffmpegOutput)\n })\n return imageBuffer\n } finally {\n // Cleanup temp file\n try {\n await unlink(tmpFile)\n } catch {\n // No error here since file doesn't exist\n }\n }\n}\n"],"mappings":"AAAA,SAAS,YAAY;AACrB,OAAO,YAAY;AACnB,SAAS,QAAQ,iBAAiB;AAClC,SAAS,cAAc;AACvB,SAAS,gBAAiC;AAK1C,
|
|
1
|
+
{"version":3,"sources":["../../../../../src/Witness/ffmpeg/fluent/getVideoFrameAsImageFluent.ts"],"sourcesContent":["import { uuid } from '@xyo-network/core'\nimport ffmpeg from 'fluent-ffmpeg'\nimport { unlink, writeFile } from 'fs/promises'\nimport { tmpdir } from 'os'\nimport { Writable, WritableOptions } from 'stream'\n\n/**\n * A Writable stream that collects output from ffmpeg.\n */\nclass FfmpegOutputStream extends Writable {\n private readonly chunks: Uint8Array[] = []\n\n constructor(options?: WritableOptions) {\n super(options)\n }\n\n override _write(chunk: never, _encoding: BufferEncoding, callback: (error?: Error | null) => void): void {\n this.chunks.push(chunk)\n callback()\n }\n\n /**\n * Collects the output from ffmpeg into a buffer.\n * @returns A buffer containing the concatenated\n * output from ffmpeg.\n */\n toBuffer = () => Buffer.concat(this.chunks)\n}\n\n/**\n * Execute FFmpeg using fluent API with provided input buffer and video thumbnail image.\n * @param videoBuffer Input video buffer.\n * @returns Output buffer containing the video thumbnail image.\n */\nexport const getVideoFrameAsImageFluent = async (videoBuffer: Buffer) => {\n // Get a temp file name\n const tmpFile = `/${tmpdir()}/${uuid()}`\n try {\n // Write videoBuffer to temp file for use as input to ffmpeg to\n // avoid issues with ffmpeg inferring premature EOF from buffer\n // passed via stdin (happens when ffmpeg is trying to infer\n // input video format)\n await writeFile(tmpFile, videoBuffer, { encoding: 'binary' })\n const imageBuffer = await new Promise<Buffer>((resolve, reject) => {\n // Create a Writable stream to collect PNG output from ffmpeg\n const ffmpegOutput = new FfmpegOutputStream()\n // Execute ffmpeg using fluent API\n ffmpeg()\n // NOTE: Uncomment to debug CLI args to ffmpeg\n // .on('start', (commandLine) => console.log('Spawned Ffmpeg with command: ' + commandLine))\n .on('error', (err) => reject(err.message))\n // Listen for the 'end' event to combine the output into a buffer holding the PNG image\n .on('end', () => resolve(ffmpegOutput.toBuffer()))\n .input(tmpFile) // Use temp file as input\n .takeFrames(1) // Only take 1st video frame\n .withNoAudio() // Don't include audio\n .outputOptions('-f image2pipe') // Write output to stdout\n .videoCodec('png') // Force PNG output\n // Start processing and direct ffmpeg stdout to writable stream\n .pipe(ffmpegOutput)\n })\n return imageBuffer\n } finally {\n // Cleanup temp file\n try {\n await unlink(tmpFile)\n } catch {\n // No error here since file doesn't exist\n }\n }\n}\n"],"mappings":";AAAA,SAAS,YAAY;AACrB,OAAO,YAAY;AACnB,SAAS,QAAQ,iBAAiB;AAClC,SAAS,cAAc;AACvB,SAAS,gBAAiC;AAK1C,IAAM,qBAAN,cAAiC,SAAS;AAAA,EACvB,SAAuB,CAAC;AAAA,EAEzC,YAAY,SAA2B;AACrC,UAAM,OAAO;AAAA,EACf;AAAA,EAES,OAAO,OAAc,WAA2B,UAAgD;AACvG,SAAK,OAAO,KAAK,KAAK;AACtB,aAAS;AAAA,EACX;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,WAAW,MAAM,OAAO,OAAO,KAAK,MAAM;AAC5C;AAOO,IAAM,6BAA6B,OAAO,gBAAwB;AAEvE,QAAM,UAAU,IAAI,OAAO,CAAC,IAAI,KAAK,CAAC;AACtC,MAAI;AAKF,UAAM,UAAU,SAAS,aAAa,EAAE,UAAU,SAAS,CAAC;AAC5D,UAAM,cAAc,MAAM,IAAI,QAAgB,CAAC,SAAS,WAAW;AAEjE,YAAM,eAAe,IAAI,mBAAmB;AAE5C,aAAO,EAGJ,GAAG,SAAS,CAAC,QAAQ,OAAO,IAAI,OAAO,CAAC,EAExC,GAAG,OAAO,MAAM,QAAQ,aAAa,SAAS,CAAC,CAAC,EAChD,MAAM,OAAO,EACb,WAAW,CAAC,EACZ,YAAY,EACZ,cAAc,eAAe,EAC7B,WAAW,KAAK,EAEhB,KAAK,YAAY;AAAA,IACtB,CAAC;AACD,WAAO;AAAA,EACT,UAAE;AAEA,QAAI;AACF,YAAM,OAAO,OAAO;AAAA,IACtB,QAAQ;AAAA,IAER;AAAA,EACF;AACF;","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/Witness/ffmpeg/fluent/index.ts"],"names":[],"mappings":"AAAA,cAAc,8BAA8B,CAAA"}
|
|
@@ -1,8 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
2
3
|
var __defProp = Object.defineProperty;
|
|
3
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
5
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
6
12
|
var __copyProps = (to, from, except, desc) => {
|
|
7
13
|
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
14
|
for (let key of __getOwnPropNames(from))
|
|
@@ -11,13 +17,63 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
11
17
|
}
|
|
12
18
|
return to;
|
|
13
19
|
};
|
|
14
|
-
var
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
15
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/Witness/ffmpeg/fluent/index.ts
|
|
16
31
|
var fluent_exports = {};
|
|
32
|
+
__export(fluent_exports, {
|
|
33
|
+
getVideoFrameAsImageFluent: () => getVideoFrameAsImageFluent
|
|
34
|
+
});
|
|
17
35
|
module.exports = __toCommonJS(fluent_exports);
|
|
18
|
-
|
|
36
|
+
|
|
37
|
+
// src/Witness/ffmpeg/fluent/getVideoFrameAsImageFluent.ts
|
|
38
|
+
var import_core = require("@xyo-network/core");
|
|
39
|
+
var import_fluent_ffmpeg = __toESM(require("fluent-ffmpeg"));
|
|
40
|
+
var import_promises = require("fs/promises");
|
|
41
|
+
var import_os = require("os");
|
|
42
|
+
var import_stream = require("stream");
|
|
43
|
+
var FfmpegOutputStream = class extends import_stream.Writable {
|
|
44
|
+
chunks = [];
|
|
45
|
+
constructor(options) {
|
|
46
|
+
super(options);
|
|
47
|
+
}
|
|
48
|
+
_write(chunk, _encoding, callback) {
|
|
49
|
+
this.chunks.push(chunk);
|
|
50
|
+
callback();
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Collects the output from ffmpeg into a buffer.
|
|
54
|
+
* @returns A buffer containing the concatenated
|
|
55
|
+
* output from ffmpeg.
|
|
56
|
+
*/
|
|
57
|
+
toBuffer = () => Buffer.concat(this.chunks);
|
|
58
|
+
};
|
|
59
|
+
var getVideoFrameAsImageFluent = async (videoBuffer) => {
|
|
60
|
+
const tmpFile = `/${(0, import_os.tmpdir)()}/${(0, import_core.uuid)()}`;
|
|
61
|
+
try {
|
|
62
|
+
await (0, import_promises.writeFile)(tmpFile, videoBuffer, { encoding: "binary" });
|
|
63
|
+
const imageBuffer = await new Promise((resolve, reject) => {
|
|
64
|
+
const ffmpegOutput = new FfmpegOutputStream();
|
|
65
|
+
(0, import_fluent_ffmpeg.default)().on("error", (err) => reject(err.message)).on("end", () => resolve(ffmpegOutput.toBuffer())).input(tmpFile).takeFrames(1).withNoAudio().outputOptions("-f image2pipe").videoCodec("png").pipe(ffmpegOutput);
|
|
66
|
+
});
|
|
67
|
+
return imageBuffer;
|
|
68
|
+
} finally {
|
|
69
|
+
try {
|
|
70
|
+
await (0, import_promises.unlink)(tmpFile);
|
|
71
|
+
} catch {
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
};
|
|
19
75
|
// Annotate the CommonJS export names for ESM import in node:
|
|
20
76
|
0 && (module.exports = {
|
|
21
|
-
|
|
77
|
+
getVideoFrameAsImageFluent
|
|
22
78
|
});
|
|
23
79
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/Witness/ffmpeg/fluent/index.ts"],"sourcesContent":["export * from './getVideoFrameAsImageFluent'\n"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../../../../src/Witness/ffmpeg/fluent/index.ts","../../../../../src/Witness/ffmpeg/fluent/getVideoFrameAsImageFluent.ts"],"sourcesContent":["export * from './getVideoFrameAsImageFluent'\n","import { uuid } from '@xyo-network/core'\nimport ffmpeg from 'fluent-ffmpeg'\nimport { unlink, writeFile } from 'fs/promises'\nimport { tmpdir } from 'os'\nimport { Writable, WritableOptions } from 'stream'\n\n/**\n * A Writable stream that collects output from ffmpeg.\n */\nclass FfmpegOutputStream extends Writable {\n private readonly chunks: Uint8Array[] = []\n\n constructor(options?: WritableOptions) {\n super(options)\n }\n\n override _write(chunk: never, _encoding: BufferEncoding, callback: (error?: Error | null) => void): void {\n this.chunks.push(chunk)\n callback()\n }\n\n /**\n * Collects the output from ffmpeg into a buffer.\n * @returns A buffer containing the concatenated\n * output from ffmpeg.\n */\n toBuffer = () => Buffer.concat(this.chunks)\n}\n\n/**\n * Execute FFmpeg using fluent API with provided input buffer and video thumbnail image.\n * @param videoBuffer Input video buffer.\n * @returns Output buffer containing the video thumbnail image.\n */\nexport const getVideoFrameAsImageFluent = async (videoBuffer: Buffer) => {\n // Get a temp file name\n const tmpFile = `/${tmpdir()}/${uuid()}`\n try {\n // Write videoBuffer to temp file for use as input to ffmpeg to\n // avoid issues with ffmpeg inferring premature EOF from buffer\n // passed via stdin (happens when ffmpeg is trying to infer\n // input video format)\n await writeFile(tmpFile, videoBuffer, { encoding: 'binary' })\n const imageBuffer = await new Promise<Buffer>((resolve, reject) => {\n // Create a Writable stream to collect PNG output from ffmpeg\n const ffmpegOutput = new FfmpegOutputStream()\n // Execute ffmpeg using fluent API\n ffmpeg()\n // NOTE: Uncomment to debug CLI args to ffmpeg\n // .on('start', (commandLine) => console.log('Spawned Ffmpeg with command: ' + commandLine))\n .on('error', (err) => reject(err.message))\n // Listen for the 'end' event to combine the output into a buffer holding the PNG image\n .on('end', () => resolve(ffmpegOutput.toBuffer()))\n .input(tmpFile) // Use temp file as input\n .takeFrames(1) // Only take 1st video frame\n .withNoAudio() // Don't include audio\n .outputOptions('-f image2pipe') // Write output to stdout\n .videoCodec('png') // Force PNG output\n // Start processing and direct ffmpeg stdout to writable stream\n .pipe(ffmpegOutput)\n })\n return imageBuffer\n } finally {\n // Cleanup temp file\n try {\n await unlink(tmpFile)\n } catch {\n // No error here since file doesn't exist\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,kBAAqB;AACrB,2BAAmB;AACnB,sBAAkC;AAClC,gBAAuB;AACvB,oBAA0C;AAK1C,IAAM,qBAAN,cAAiC,uBAAS;AAAA,EACvB,SAAuB,CAAC;AAAA,EAEzC,YAAY,SAA2B;AACrC,UAAM,OAAO;AAAA,EACf;AAAA,EAES,OAAO,OAAc,WAA2B,UAAgD;AACvG,SAAK,OAAO,KAAK,KAAK;AACtB,aAAS;AAAA,EACX;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,WAAW,MAAM,OAAO,OAAO,KAAK,MAAM;AAC5C;AAOO,IAAM,6BAA6B,OAAO,gBAAwB;AAEvE,QAAM,UAAU,QAAI,kBAAO,CAAC,QAAI,kBAAK,CAAC;AACtC,MAAI;AAKF,cAAM,2BAAU,SAAS,aAAa,EAAE,UAAU,SAAS,CAAC;AAC5D,UAAM,cAAc,MAAM,IAAI,QAAgB,CAAC,SAAS,WAAW;AAEjE,YAAM,eAAe,IAAI,mBAAmB;AAE5C,+BAAAA,SAAO,EAGJ,GAAG,SAAS,CAAC,QAAQ,OAAO,IAAI,OAAO,CAAC,EAExC,GAAG,OAAO,MAAM,QAAQ,aAAa,SAAS,CAAC,CAAC,EAChD,MAAM,OAAO,EACb,WAAW,CAAC,EACZ,YAAY,EACZ,cAAc,eAAe,EAC7B,WAAW,KAAK,EAEhB,KAAK,YAAY;AAAA,IACtB,CAAC;AACD,WAAO;AAAA,EACT,UAAE;AAEA,QAAI;AACF,gBAAM,wBAAO,OAAO;AAAA,IACtB,QAAQ;AAAA,IAER;AAAA,EACF;AACF;","names":["ffmpeg"]}
|
|
@@ -1,2 +1,42 @@
|
|
|
1
|
-
|
|
1
|
+
// src/Witness/ffmpeg/fluent/getVideoFrameAsImageFluent.ts
|
|
2
|
+
import { uuid } from "@xyo-network/core";
|
|
3
|
+
import ffmpeg from "fluent-ffmpeg";
|
|
4
|
+
import { unlink, writeFile } from "fs/promises";
|
|
5
|
+
import { tmpdir } from "os";
|
|
6
|
+
import { Writable } from "stream";
|
|
7
|
+
var FfmpegOutputStream = class extends Writable {
|
|
8
|
+
chunks = [];
|
|
9
|
+
constructor(options) {
|
|
10
|
+
super(options);
|
|
11
|
+
}
|
|
12
|
+
_write(chunk, _encoding, callback) {
|
|
13
|
+
this.chunks.push(chunk);
|
|
14
|
+
callback();
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Collects the output from ffmpeg into a buffer.
|
|
18
|
+
* @returns A buffer containing the concatenated
|
|
19
|
+
* output from ffmpeg.
|
|
20
|
+
*/
|
|
21
|
+
toBuffer = () => Buffer.concat(this.chunks);
|
|
22
|
+
};
|
|
23
|
+
var getVideoFrameAsImageFluent = async (videoBuffer) => {
|
|
24
|
+
const tmpFile = `/${tmpdir()}/${uuid()}`;
|
|
25
|
+
try {
|
|
26
|
+
await writeFile(tmpFile, videoBuffer, { encoding: "binary" });
|
|
27
|
+
const imageBuffer = await new Promise((resolve, reject) => {
|
|
28
|
+
const ffmpegOutput = new FfmpegOutputStream();
|
|
29
|
+
ffmpeg().on("error", (err) => reject(err.message)).on("end", () => resolve(ffmpegOutput.toBuffer())).input(tmpFile).takeFrames(1).withNoAudio().outputOptions("-f image2pipe").videoCodec("png").pipe(ffmpegOutput);
|
|
30
|
+
});
|
|
31
|
+
return imageBuffer;
|
|
32
|
+
} finally {
|
|
33
|
+
try {
|
|
34
|
+
await unlink(tmpFile);
|
|
35
|
+
} catch {
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
export {
|
|
40
|
+
getVideoFrameAsImageFluent
|
|
41
|
+
};
|
|
2
42
|
//# sourceMappingURL=index.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/Witness/ffmpeg/fluent/
|
|
1
|
+
{"version":3,"sources":["../../../../../src/Witness/ffmpeg/fluent/getVideoFrameAsImageFluent.ts"],"sourcesContent":["import { uuid } from '@xyo-network/core'\nimport ffmpeg from 'fluent-ffmpeg'\nimport { unlink, writeFile } from 'fs/promises'\nimport { tmpdir } from 'os'\nimport { Writable, WritableOptions } from 'stream'\n\n/**\n * A Writable stream that collects output from ffmpeg.\n */\nclass FfmpegOutputStream extends Writable {\n private readonly chunks: Uint8Array[] = []\n\n constructor(options?: WritableOptions) {\n super(options)\n }\n\n override _write(chunk: never, _encoding: BufferEncoding, callback: (error?: Error | null) => void): void {\n this.chunks.push(chunk)\n callback()\n }\n\n /**\n * Collects the output from ffmpeg into a buffer.\n * @returns A buffer containing the concatenated\n * output from ffmpeg.\n */\n toBuffer = () => Buffer.concat(this.chunks)\n}\n\n/**\n * Execute FFmpeg using fluent API with provided input buffer and video thumbnail image.\n * @param videoBuffer Input video buffer.\n * @returns Output buffer containing the video thumbnail image.\n */\nexport const getVideoFrameAsImageFluent = async (videoBuffer: Buffer) => {\n // Get a temp file name\n const tmpFile = `/${tmpdir()}/${uuid()}`\n try {\n // Write videoBuffer to temp file for use as input to ffmpeg to\n // avoid issues with ffmpeg inferring premature EOF from buffer\n // passed via stdin (happens when ffmpeg is trying to infer\n // input video format)\n await writeFile(tmpFile, videoBuffer, { encoding: 'binary' })\n const imageBuffer = await new Promise<Buffer>((resolve, reject) => {\n // Create a Writable stream to collect PNG output from ffmpeg\n const ffmpegOutput = new FfmpegOutputStream()\n // Execute ffmpeg using fluent API\n ffmpeg()\n // NOTE: Uncomment to debug CLI args to ffmpeg\n // .on('start', (commandLine) => console.log('Spawned Ffmpeg with command: ' + commandLine))\n .on('error', (err) => reject(err.message))\n // Listen for the 'end' event to combine the output into a buffer holding the PNG image\n .on('end', () => resolve(ffmpegOutput.toBuffer()))\n .input(tmpFile) // Use temp file as input\n .takeFrames(1) // Only take 1st video frame\n .withNoAudio() // Don't include audio\n .outputOptions('-f image2pipe') // Write output to stdout\n .videoCodec('png') // Force PNG output\n // Start processing and direct ffmpeg stdout to writable stream\n .pipe(ffmpegOutput)\n })\n return imageBuffer\n } finally {\n // Cleanup temp file\n try {\n await unlink(tmpFile)\n } catch {\n // No error here since file doesn't exist\n }\n }\n}\n"],"mappings":";AAAA,SAAS,YAAY;AACrB,OAAO,YAAY;AACnB,SAAS,QAAQ,iBAAiB;AAClC,SAAS,cAAc;AACvB,SAAS,gBAAiC;AAK1C,IAAM,qBAAN,cAAiC,SAAS;AAAA,EACvB,SAAuB,CAAC;AAAA,EAEzC,YAAY,SAA2B;AACrC,UAAM,OAAO;AAAA,EACf;AAAA,EAES,OAAO,OAAc,WAA2B,UAAgD;AACvG,SAAK,OAAO,KAAK,KAAK;AACtB,aAAS;AAAA,EACX;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,WAAW,MAAM,OAAO,OAAO,KAAK,MAAM;AAC5C;AAOO,IAAM,6BAA6B,OAAO,gBAAwB;AAEvE,QAAM,UAAU,IAAI,OAAO,CAAC,IAAI,KAAK,CAAC;AACtC,MAAI;AAKF,UAAM,UAAU,SAAS,aAAa,EAAE,UAAU,SAAS,CAAC;AAC5D,UAAM,cAAc,MAAM,IAAI,QAAgB,CAAC,SAAS,WAAW;AAEjE,YAAM,eAAe,IAAI,mBAAmB;AAE5C,aAAO,EAGJ,GAAG,SAAS,CAAC,QAAQ,OAAO,IAAI,OAAO,CAAC,EAExC,GAAG,OAAO,MAAM,QAAQ,aAAa,SAAS,CAAC,CAAC,EAChD,MAAM,OAAO,EACb,WAAW,CAAC,EACZ,YAAY,EACZ,cAAc,eAAe,EAC7B,WAAW,KAAK,EAEhB,KAAK,YAAY;AAAA,IACtB,CAAC;AACD,WAAO;AAAA,EACT,UAAE;AAEA,QAAI;AACF,YAAM,OAAO,OAAO;AAAA,IACtB,QAAQ;AAAA,IAER;AAAA,EACF;AACF;","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/Witness/ffmpeg/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAA;AACxB,cAAc,SAAS,CAAA"}
|
|
@@ -1,8 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
2
3
|
var __defProp = Object.defineProperty;
|
|
3
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
5
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
6
12
|
var __copyProps = (to, from, except, desc) => {
|
|
7
13
|
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
14
|
for (let key of __getOwnPropNames(from))
|
|
@@ -11,15 +17,93 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
11
17
|
}
|
|
12
18
|
return to;
|
|
13
19
|
};
|
|
14
|
-
var
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
15
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/Witness/ffmpeg/index.ts
|
|
16
31
|
var ffmpeg_exports = {};
|
|
32
|
+
__export(ffmpeg_exports, {
|
|
33
|
+
executeFFmpeg: () => executeFFmpeg,
|
|
34
|
+
getVideoFrameAsImage: () => getVideoFrameAsImage,
|
|
35
|
+
getVideoFrameAsImageFluent: () => getVideoFrameAsImageFluent
|
|
36
|
+
});
|
|
17
37
|
module.exports = __toCommonJS(ffmpeg_exports);
|
|
18
|
-
|
|
19
|
-
|
|
38
|
+
|
|
39
|
+
// src/Witness/ffmpeg/fluent/getVideoFrameAsImageFluent.ts
|
|
40
|
+
var import_core = require("@xyo-network/core");
|
|
41
|
+
var import_fluent_ffmpeg = __toESM(require("fluent-ffmpeg"));
|
|
42
|
+
var import_promises = require("fs/promises");
|
|
43
|
+
var import_os = require("os");
|
|
44
|
+
var import_stream = require("stream");
|
|
45
|
+
var FfmpegOutputStream = class extends import_stream.Writable {
|
|
46
|
+
chunks = [];
|
|
47
|
+
constructor(options) {
|
|
48
|
+
super(options);
|
|
49
|
+
}
|
|
50
|
+
_write(chunk, _encoding, callback) {
|
|
51
|
+
this.chunks.push(chunk);
|
|
52
|
+
callback();
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Collects the output from ffmpeg into a buffer.
|
|
56
|
+
* @returns A buffer containing the concatenated
|
|
57
|
+
* output from ffmpeg.
|
|
58
|
+
*/
|
|
59
|
+
toBuffer = () => Buffer.concat(this.chunks);
|
|
60
|
+
};
|
|
61
|
+
var getVideoFrameAsImageFluent = async (videoBuffer) => {
|
|
62
|
+
const tmpFile = `/${(0, import_os.tmpdir)()}/${(0, import_core.uuid)()}`;
|
|
63
|
+
try {
|
|
64
|
+
await (0, import_promises.writeFile)(tmpFile, videoBuffer, { encoding: "binary" });
|
|
65
|
+
const imageBuffer = await new Promise((resolve, reject) => {
|
|
66
|
+
const ffmpegOutput = new FfmpegOutputStream();
|
|
67
|
+
(0, import_fluent_ffmpeg.default)().on("error", (err) => reject(err.message)).on("end", () => resolve(ffmpegOutput.toBuffer())).input(tmpFile).takeFrames(1).withNoAudio().outputOptions("-f image2pipe").videoCodec("png").pipe(ffmpegOutput);
|
|
68
|
+
});
|
|
69
|
+
return imageBuffer;
|
|
70
|
+
} finally {
|
|
71
|
+
try {
|
|
72
|
+
await (0, import_promises.unlink)(tmpFile);
|
|
73
|
+
} catch {
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
// src/Witness/ffmpeg/spawn/executeFfmpeg.ts
|
|
79
|
+
var import_child_process = require("child_process");
|
|
80
|
+
var executeFFmpeg = (videoBuffer, ffmpegArgs) => {
|
|
81
|
+
return new Promise((resolve, reject) => {
|
|
82
|
+
const imageData = [];
|
|
83
|
+
const ffmpeg2 = (0, import_child_process.spawn)("ffmpeg", ffmpegArgs);
|
|
84
|
+
ffmpeg2.stdout.on("data", (data) => imageData.push(data));
|
|
85
|
+
ffmpeg2.stdin.on("error", () => {
|
|
86
|
+
});
|
|
87
|
+
ffmpeg2.on("close", (code) => {
|
|
88
|
+
if (code !== 0) {
|
|
89
|
+
reject(new Error(`FFmpeg exited with code ${code}`));
|
|
90
|
+
} else {
|
|
91
|
+
resolve(Buffer.concat(imageData));
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
ffmpeg2.stdin.end(videoBuffer);
|
|
95
|
+
});
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
// src/Witness/ffmpeg/spawn/getVideoFrameAsImage.ts
|
|
99
|
+
var getVideoFrameAsImage = async (videoBuffer) => {
|
|
100
|
+
const imageBuffer = await executeFFmpeg(videoBuffer, ["-i", "pipe:", "-ss", "00:00:00", "-vframes", "1", "-f", "image2pipe", "-"]);
|
|
101
|
+
return imageBuffer;
|
|
102
|
+
};
|
|
20
103
|
// Annotate the CommonJS export names for ESM import in node:
|
|
21
104
|
0 && (module.exports = {
|
|
22
|
-
|
|
23
|
-
|
|
105
|
+
executeFFmpeg,
|
|
106
|
+
getVideoFrameAsImage,
|
|
107
|
+
getVideoFrameAsImageFluent
|
|
24
108
|
});
|
|
25
109
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/Witness/ffmpeg/index.ts"],"sourcesContent":["export * from './fluent'\nexport * from './spawn'\n"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../../../src/Witness/ffmpeg/index.ts","../../../../src/Witness/ffmpeg/fluent/getVideoFrameAsImageFluent.ts","../../../../src/Witness/ffmpeg/spawn/executeFfmpeg.ts","../../../../src/Witness/ffmpeg/spawn/getVideoFrameAsImage.ts"],"sourcesContent":["export * from './fluent'\nexport * from './spawn'\n","import { uuid } from '@xyo-network/core'\nimport ffmpeg from 'fluent-ffmpeg'\nimport { unlink, writeFile } from 'fs/promises'\nimport { tmpdir } from 'os'\nimport { Writable, WritableOptions } from 'stream'\n\n/**\n * A Writable stream that collects output from ffmpeg.\n */\nclass FfmpegOutputStream extends Writable {\n private readonly chunks: Uint8Array[] = []\n\n constructor(options?: WritableOptions) {\n super(options)\n }\n\n override _write(chunk: never, _encoding: BufferEncoding, callback: (error?: Error | null) => void): void {\n this.chunks.push(chunk)\n callback()\n }\n\n /**\n * Collects the output from ffmpeg into a buffer.\n * @returns A buffer containing the concatenated\n * output from ffmpeg.\n */\n toBuffer = () => Buffer.concat(this.chunks)\n}\n\n/**\n * Execute FFmpeg using fluent API with provided input buffer and video thumbnail image.\n * @param videoBuffer Input video buffer.\n * @returns Output buffer containing the video thumbnail image.\n */\nexport const getVideoFrameAsImageFluent = async (videoBuffer: Buffer) => {\n // Get a temp file name\n const tmpFile = `/${tmpdir()}/${uuid()}`\n try {\n // Write videoBuffer to temp file for use as input to ffmpeg to\n // avoid issues with ffmpeg inferring premature EOF from buffer\n // passed via stdin (happens when ffmpeg is trying to infer\n // input video format)\n await writeFile(tmpFile, videoBuffer, { encoding: 'binary' })\n const imageBuffer = await new Promise<Buffer>((resolve, reject) => {\n // Create a Writable stream to collect PNG output from ffmpeg\n const ffmpegOutput = new FfmpegOutputStream()\n // Execute ffmpeg using fluent API\n ffmpeg()\n // NOTE: Uncomment to debug CLI args to ffmpeg\n // .on('start', (commandLine) => console.log('Spawned Ffmpeg with command: ' + commandLine))\n .on('error', (err) => reject(err.message))\n // Listen for the 'end' event to combine the output into a buffer holding the PNG image\n .on('end', () => resolve(ffmpegOutput.toBuffer()))\n .input(tmpFile) // Use temp file as input\n .takeFrames(1) // Only take 1st video frame\n .withNoAudio() // Don't include audio\n .outputOptions('-f image2pipe') // Write output to stdout\n .videoCodec('png') // Force PNG output\n // Start processing and direct ffmpeg stdout to writable stream\n .pipe(ffmpegOutput)\n })\n return imageBuffer\n } finally {\n // Cleanup temp file\n try {\n await unlink(tmpFile)\n } catch {\n // No error here since file doesn't exist\n }\n }\n}\n","import { spawn } from 'child_process'\n\n/**\n * Execute FFmpeg with the provided arguments.\n * @param videoBuffer Input video buffer.\n * @param ffmpegArgs FFmpeg arguments.\n * @returns Output buffer containing the video thumbnail image.\n */\nexport const executeFFmpeg = (videoBuffer: Buffer, ffmpegArgs: string[]): Promise<Buffer> => {\n return new Promise((resolve, reject) => {\n const imageData: Buffer[] = []\n const ffmpeg = spawn('ffmpeg', ffmpegArgs)\n ffmpeg.stdout.on('data', (data: Buffer) => imageData.push(data))\n // TODO: This is required as we're seeing errors thrown due to\n // how we're piping the data to ffmpeg. Works perfectly though.\n ffmpeg.stdin.on('error', () => {})\n ffmpeg.on('close', (code) => {\n if (code !== 0) {\n reject(new Error(`FFmpeg exited with code ${code}`))\n } else {\n resolve(Buffer.concat(imageData))\n }\n })\n // Pipe the input stream to ffmpeg's stdin\n ffmpeg.stdin.end(videoBuffer)\n })\n}\n","import { executeFFmpeg } from './executeFfmpeg'\n\n/**\n * Execute FFmpeg with provided input buffer and return video thumbnail image.\n * @param videoBuffer Input video buffer.\n * @returns Output buffer containing the video thumbnail image.\n */\nexport const getVideoFrameAsImage = async (videoBuffer: Buffer) => {\n const imageBuffer = await executeFFmpeg(videoBuffer, ['-i', 'pipe:', '-ss', '00:00:00', '-vframes', '1', '-f', 'image2pipe', '-'])\n return imageBuffer\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,kBAAqB;AACrB,2BAAmB;AACnB,sBAAkC;AAClC,gBAAuB;AACvB,oBAA0C;AAK1C,IAAM,qBAAN,cAAiC,uBAAS;AAAA,EACvB,SAAuB,CAAC;AAAA,EAEzC,YAAY,SAA2B;AACrC,UAAM,OAAO;AAAA,EACf;AAAA,EAES,OAAO,OAAc,WAA2B,UAAgD;AACvG,SAAK,OAAO,KAAK,KAAK;AACtB,aAAS;AAAA,EACX;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,WAAW,MAAM,OAAO,OAAO,KAAK,MAAM;AAC5C;AAOO,IAAM,6BAA6B,OAAO,gBAAwB;AAEvE,QAAM,UAAU,QAAI,kBAAO,CAAC,QAAI,kBAAK,CAAC;AACtC,MAAI;AAKF,cAAM,2BAAU,SAAS,aAAa,EAAE,UAAU,SAAS,CAAC;AAC5D,UAAM,cAAc,MAAM,IAAI,QAAgB,CAAC,SAAS,WAAW;AAEjE,YAAM,eAAe,IAAI,mBAAmB;AAE5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{ uuid } from "@xyo-network/core";
|
|
3
|
+
import ffmpeg from "fluent-ffmpeg";
|
|
4
|
+
import { unlink, writeFile } from "fs/promises";
|
|
5
|
+
import { tmpdir } from "os";
|
|
6
|
+
import { Writable } from "stream";
|
|
7
|
+
var FfmpegOutputStream = class extends Writable {
|
|
8
|
+
chunks = [];
|
|
9
|
+
constructor(options) {
|
|
10
|
+
super(options);
|
|
11
|
+
}
|
|
12
|
+
_write(chunk, _encoding, callback) {
|
|
13
|
+
this.chunks.push(chunk);
|
|
14
|
+
callback();
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Collects the output from ffmpeg into a buffer.
|
|
18
|
+
* @returns A buffer containing the concatenated
|
|
19
|
+
* output from ffmpeg.
|
|
20
|
+
*/
|
|
21
|
+
toBuffer = () => Buffer.concat(this.chunks);
|
|
22
|
+
};
|
|
23
|
+
var getVideoFrameAsImageFluent = async (videoBuffer) => {
|
|
24
|
+
const tmpFile = `/${tmpdir()}/${uuid()}`;
|
|
25
|
+
try {
|
|
26
|
+
await writeFile(tmpFile, videoBuffer, { encoding: "binary" });
|
|
27
|
+
const imageBuffer = await new Promise((resolve, reject) => {
|
|
28
|
+
const ffmpegOutput = new FfmpegOutputStream();
|
|
29
|
+
ffmpeg().on("error", (err) => reject(err.message)).on("end", () => resolve(ffmpegOutput.toBuffer())).input(tmpFile).takeFrames(1).withNoAudio().outputOptions("-f image2pipe").videoCodec("png").pipe(ffmpegOutput);
|
|
30
|
+
});
|
|
31
|
+
return imageBuffer;
|
|
32
|
+
} finally {
|
|
33
|
+
try {
|
|
34
|
+
await unlink(tmpFile);
|
|
35
|
+
} catch {
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
// src/Witness/ffmpeg/spawn/executeFfmpeg.ts
|
|
41
|
+
import { spawn } from "child_process";
|
|
42
|
+
var executeFFmpeg = (videoBuffer, ffmpegArgs) => {
|
|
43
|
+
return new Promise((resolve, reject) => {
|
|
44
|
+
const imageData = [];
|
|
45
|
+
const ffmpeg2 = spawn("ffmpeg", ffmpegArgs);
|
|
46
|
+
ffmpeg2.stdout.on("data", (data) => imageData.push(data));
|
|
47
|
+
ffmpeg2.stdin.on("error", () => {
|
|
48
|
+
});
|
|
49
|
+
ffmpeg2.on("close", (code) => {
|
|
50
|
+
if (code !== 0) {
|
|
51
|
+
reject(new Error(`FFmpeg exited with code ${code}`));
|
|
52
|
+
} else {
|
|
53
|
+
resolve(Buffer.concat(imageData));
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
ffmpeg2.stdin.end(videoBuffer);
|
|
57
|
+
});
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
// src/Witness/ffmpeg/spawn/getVideoFrameAsImage.ts
|
|
61
|
+
var getVideoFrameAsImage = async (videoBuffer) => {
|
|
62
|
+
const imageBuffer = await executeFFmpeg(videoBuffer, ["-i", "pipe:", "-ss", "00:00:00", "-vframes", "1", "-f", "image2pipe", "-"]);
|
|
63
|
+
return imageBuffer;
|
|
64
|
+
};
|
|
65
|
+
export {
|
|
66
|
+
executeFFmpeg,
|
|
67
|
+
getVideoFrameAsImage,
|
|
68
|
+
getVideoFrameAsImageFluent
|
|
69
|
+
};
|
|
3
70
|
//# sourceMappingURL=index.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/Witness/ffmpeg/
|
|
1
|
+
{"version":3,"sources":["../../../../src/Witness/ffmpeg/fluent/getVideoFrameAsImageFluent.ts","../../../../src/Witness/ffmpeg/spawn/executeFfmpeg.ts","../../../../src/Witness/ffmpeg/spawn/getVideoFrameAsImage.ts"],"sourcesContent":["import { uuid } from '@xyo-network/core'\nimport ffmpeg from 'fluent-ffmpeg'\nimport { unlink, writeFile } from 'fs/promises'\nimport { tmpdir } from 'os'\nimport { Writable, WritableOptions } from 'stream'\n\n/**\n * A Writable stream that collects output from ffmpeg.\n */\nclass FfmpegOutputStream extends Writable {\n private readonly chunks: Uint8Array[] = []\n\n constructor(options?: WritableOptions) {\n super(options)\n }\n\n override _write(chunk: never, _encoding: BufferEncoding, callback: (error?: Error | null) => void): void {\n this.chunks.push(chunk)\n callback()\n }\n\n /**\n * Collects the output from ffmpeg into a buffer.\n * @returns A buffer containing the concatenated\n * output from ffmpeg.\n */\n toBuffer = () => Buffer.concat(this.chunks)\n}\n\n/**\n * Execute FFmpeg using fluent API with provided input buffer and video thumbnail image.\n * @param videoBuffer Input video buffer.\n * @returns Output buffer containing the video thumbnail image.\n */\nexport const getVideoFrameAsImageFluent = async (videoBuffer: Buffer) => {\n // Get a temp file name\n const tmpFile = `/${tmpdir()}/${uuid()}`\n try {\n // Write videoBuffer to temp file for use as input to ffmpeg to\n // avoid issues with ffmpeg inferring premature EOF from buffer\n // passed via stdin (happens when ffmpeg is trying to infer\n // input video format)\n await writeFile(tmpFile, videoBuffer, { encoding: 'binary' })\n const imageBuffer = await new Promise<Buffer>((resolve, reject) => {\n // Create a Writable stream to collect PNG output from ffmpeg\n const ffmpegOutput = new FfmpegOutputStream()\n // Execute ffmpeg using fluent API\n ffmpeg()\n // NOTE: Uncomment to debug CLI args to ffmpeg\n // .on('start', (commandLine) => console.log('Spawned Ffmpeg with command: ' + commandLine))\n .on('error', (err) => reject(err.message))\n // Listen for the 'end' event to combine the output into a buffer holding the PNG image\n .on('end', () => resolve(ffmpegOutput.toBuffer()))\n .input(tmpFile) // Use temp file as input\n .takeFrames(1) // Only take 1st video frame\n .withNoAudio() // Don't include audio\n .outputOptions('-f image2pipe') // Write output to stdout\n .videoCodec('png') // Force PNG output\n // Start processing and direct ffmpeg stdout to writable stream\n .pipe(ffmpegOutput)\n })\n return imageBuffer\n } finally {\n // Cleanup temp file\n try {\n await unlink(tmpFile)\n } catch {\n // No error here since file doesn't exist\n }\n }\n}\n","import { spawn } from 'child_process'\n\n/**\n * Execute FFmpeg with the provided arguments.\n * @param videoBuffer Input video buffer.\n * @param ffmpegArgs FFmpeg arguments.\n * @returns Output buffer containing the video thumbnail image.\n */\nexport const executeFFmpeg = (videoBuffer: Buffer, ffmpegArgs: string[]): Promise<Buffer> => {\n return new Promise((resolve, reject) => {\n const imageData: Buffer[] = []\n const ffmpeg = spawn('ffmpeg', ffmpegArgs)\n ffmpeg.stdout.on('data', (data: Buffer) => imageData.push(data))\n // TODO: This is required as we're seeing errors thrown due to\n // how we're piping the data to ffmpeg. Works perfectly though.\n ffmpeg.stdin.on('error', () => {})\n ffmpeg.on('close', (code) => {\n if (code !== 0) {\n reject(new Error(`FFmpeg exited with code ${code}`))\n } else {\n resolve(Buffer.concat(imageData))\n }\n })\n // Pipe the input stream to ffmpeg's stdin\n ffmpeg.stdin.end(videoBuffer)\n })\n}\n","import { executeFFmpeg } from './executeFfmpeg'\n\n/**\n * Execute FFmpeg with provided input buffer and return video thumbnail image.\n * @param videoBuffer Input video buffer.\n * @returns Output buffer containing the video thumbnail image.\n */\nexport const getVideoFrameAsImage = async (videoBuffer: Buffer) => {\n const imageBuffer = await executeFFmpeg(videoBuffer, ['-i', 'pipe:', '-ss', '00:00:00', '-vframes', '1', '-f', 'image2pipe', '-'])\n return imageBuffer\n}\n"],"mappings":";AAAA,SAAS,YAAY;AACrB,OAAO,YAAY;AACnB,SAAS,QAAQ,iBAAiB;AAClC,SAAS,cAAc;AACvB,SAAS,gBAAiC;AAK1C,IAAM,qBAAN,cAAiC,SAAS;AAAA,EACvB,SAAuB,CAAC;AAAA,EAEzC,YAAY,SAA2B;AACrC,UAAM,OAAO;AAAA,EACf;AAAA,EAES,OAAO,OAAc,WAA2B,UAAgD;AACvG,SAAK,OAAO,KAAK,KAAK;AACtB,aAAS;AAAA,EACX;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,WAAW,MAAM,OAAO,OAAO,KAAK,MAAM;AAC5C;AAOO,IAAM,6BAA6B,OAAO,gBAAwB;AAEvE,QAAM,UAAU,IAAI,OAAO,CAAC,IAAI,KAAK,CAAC;AACtC,MAAI;AAKF,UAAM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}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
/**
|
|
3
|
+
* Execute FFmpeg with the provided arguments.
|
|
4
|
+
* @param videoBuffer Input video buffer.
|
|
5
|
+
* @param ffmpegArgs FFmpeg arguments.
|
|
6
|
+
* @returns Output buffer containing the video thumbnail image.
|
|
7
|
+
*/
|
|
8
|
+
export declare const executeFFmpeg: (videoBuffer: Buffer, ffmpegArgs: string[]) => Promise<Buffer>;
|
|
9
|
+
//# sourceMappingURL=executeFfmpeg.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"executeFfmpeg.d.ts","sourceRoot":"","sources":["../../../../../src/Witness/ffmpeg/spawn/executeFfmpeg.ts"],"names":[],"mappings":";AAEA;;;;;GAKG;AACH,eAAO,MAAM,aAAa,gBAAiB,MAAM,cAAc,MAAM,EAAE,KAAG,QAAQ,MAAM,CAkBvF,CAAA"}
|