import nanospawn in cjs interop way
This commit is contained in:
parent
de09154fc8
commit
77b8fe75d9
@ -1,5 +1,4 @@
|
|||||||
import type { Task, Helpers } from "graphile-worker";
|
import type { Task, Helpers } from "graphile-worker";
|
||||||
import spawn from 'nano-spawn';
|
|
||||||
import { PrismaClient } from "../../generated/prisma";
|
import { PrismaClient } from "../../generated/prisma";
|
||||||
import { withAccelerate } from "@prisma/extension-accelerate";
|
import { withAccelerate } from "@prisma/extension-accelerate";
|
||||||
import { getOrDownloadAsset } from "../utils/cache";
|
import { getOrDownloadAsset } from "../utils/cache";
|
||||||
@ -11,6 +10,7 @@ import { basename, join, dirname } from "node:path";
|
|||||||
import { mkdirp } from "fs-extra";
|
import { mkdirp } from "fs-extra";
|
||||||
import { listFilesRecursive } from "../utils/filesystem";
|
import { listFilesRecursive } from "../utils/filesystem";
|
||||||
import { getMimeType } from "../utils/mimetype";
|
import { getMimeType } from "../utils/mimetype";
|
||||||
|
import { getNanoSpawn } from "../utils/nanoSpawn";
|
||||||
|
|
||||||
const prisma = new PrismaClient().$extends(withAccelerate());
|
const prisma = new PrismaClient().$extends(withAccelerate());
|
||||||
|
|
||||||
@ -47,10 +47,12 @@ interface HlsVariant {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
export async function createVariants(helpers: Helpers, inputFilePath: string): Promise<HlsVariant[]> {
|
export async function createVariants(helpers: Helpers, inputFilePath: string): Promise<HlsVariant[]> {
|
||||||
const workdir = join(env.CACHE_ROOT, nanoid());
|
const workdir = join(env.CACHE_ROOT, nanoid());
|
||||||
await mkdirp(workdir);
|
await mkdirp(workdir);
|
||||||
const baseName = basename(inputFilePath, '.mp4');
|
const baseName = basename(inputFilePath, '.mp4');
|
||||||
|
const spawn = await getNanoSpawn()
|
||||||
|
|
||||||
const resolutions = [
|
const resolutions = [
|
||||||
{ width: 1920, height: 1080, bitrate: 4000000, name: '1080p' }, // 4Mbps
|
{ width: 1920, height: 1080, bitrate: 4000000, name: '1080p' }, // 4Mbps
|
||||||
@ -99,6 +101,7 @@ export async function packageHls(
|
|||||||
): Promise<string> {
|
): Promise<string> {
|
||||||
const args: string[] = [];
|
const args: string[] = [];
|
||||||
|
|
||||||
|
const spawn = await getNanoSpawn()
|
||||||
// Optional: sort variants by bandwidth descending
|
// Optional: sort variants by bandwidth descending
|
||||||
variants.sort((a, b) => b.bandwidth - a.bandwidth);
|
variants.sort((a, b) => b.bandwidth - a.bandwidth);
|
||||||
|
|
||||||
@ -123,18 +126,6 @@ export async function packageHls(
|
|||||||
args.push('--segment_duration=2'); // matches Twitch’s chunk size
|
args.push('--segment_duration=2'); // matches Twitch’s chunk size
|
||||||
|
|
||||||
|
|
||||||
helpers.logger.info(`PILLS HERE\nPILLS HERE\nPILLS HERE\nPILLS HERE\nPILLS HERE\nPILLS HERE\nPILLS HERE`)
|
|
||||||
helpers.logger.info(`PILLS HERE\nPILLS HERE\nPILLS HERE\nPILLS HERE\nPILLS HERE\nPILLS HERE\nPILLS HERE`)
|
|
||||||
helpers.logger.info(`PILLS HERE\nPILLS HERE\nPILLS HERE\nPILLS HERE\nPILLS HERE\nPILLS HERE\nPILLS HERE`)
|
|
||||||
helpers.logger.info(`PILLS HERE\nPILLS HERE\nPILLS HERE\nPILLS HERE\nPILLS HERE\nPILLS HERE\nPILLS HERE`)
|
|
||||||
helpers.logger.info(`PILLS HERE\nPILLS HERE\nPILLS HERE\nPILLS HERE\nPILLS HERE\nPILLS HERE\nPILLS HERE`)
|
|
||||||
helpers.logger.info(`PILLS HERE\nPILLS HERE\nPILLS HERE\nPILLS HERE\nPILLS HERE\nPILLS HERE\nPILLS HERE`)
|
|
||||||
helpers.logger.info(`PILLS HERE\nPILLS HERE\nPILLS HERE\nPILLS HERE\nPILLS HERE\nPILLS HERE\nPILLS HERE`)
|
|
||||||
helpers.logger.info(`PILLS HERE\nPILLS HERE\nPILLS HERE\nPILLS HERE\nPILLS HERE\nPILLS HERE\nPILLS HERE`)
|
|
||||||
helpers.logger.info(`PILLS HERE\nPILLS HERE\nPILLS HERE\nPILLS HERE\nPILLS HERE\nPILLS HERE\nPILLS HERE`)
|
|
||||||
helpers.logger.info(`PILLS HERE\nPILLS HERE\nPILLS HERE\nPILLS HERE\nPILLS HERE\nPILLS HERE\nPILLS HERE`)
|
|
||||||
helpers.logger.info(`PILLS HERE\nPILLS HERE\nPILLS HERE\nPILLS HERE\nPILLS HERE\nPILLS HERE\nPILLS HERE`)
|
|
||||||
helpers.logger.info(`PILLS HERE\nPILLS HERE\nPILLS HERE\nPILLS HERE\nPILLS HERE\nPILLS HERE\nPILLS HERE`)
|
|
||||||
helpers.logger.info(`PILLS HERE\nPILLS HERE\nPILLS HERE\nPILLS HERE\nPILLS HERE\nPILLS HERE\nPILLS HERE`)
|
helpers.logger.info(`PILLS HERE\nPILLS HERE\nPILLS HERE\nPILLS HERE\nPILLS HERE\nPILLS HERE\nPILLS HERE`)
|
||||||
|
|
||||||
await spawn('packager', args, {
|
await spawn('packager', args, {
|
||||||
|
7
services/our/src/utils/nanoSpawn.ts
Normal file
7
services/our/src/utils/nanoSpawn.ts
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
// utils/nanoSpawn.ts
|
||||||
|
// we do this because we need to use dynamic import() when using ESM only module via tsup CJS interop.
|
||||||
|
|
||||||
|
export async function getNanoSpawn() {
|
||||||
|
const nanoSpawn = (await import('nano-spawn')).default;
|
||||||
|
return nanoSpawn
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user