-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
2,402 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,3 +13,5 @@ casparcg.config | |
!.yarn/releases | ||
!.yarn/sdks | ||
!.yarn/versions | ||
.ffmpeg/ | ||
/coverage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
module.exports = { | ||
transform: { | ||
'^.+\\.(ts|tsx)$': [ | ||
'ts-jest', | ||
{ | ||
tsconfig: 'tsconfig.json', | ||
}, | ||
], | ||
}, | ||
testMatch: ['**/__tests__/**/*.spec.(ts|js)'], | ||
testPathIgnorePatterns: ['integrationTests'], | ||
testEnvironment: 'node', | ||
coverageThreshold: { | ||
global: { | ||
branches: 0, | ||
functions: 0, | ||
lines: 0, | ||
statements: 0, | ||
}, | ||
}, | ||
collectCoverageFrom: [ | ||
'**/src/**/*.{ts,js}', | ||
'!**/src/__tests__/**', | ||
'!**/node_modules/**', | ||
'!**/dist/**', | ||
'!packages/webhid-demo/**', | ||
], | ||
collectCoverage: true, | ||
projects: ['<rootDir>'], | ||
coverageDirectory: '<rootDir>/coverage/', | ||
|
||
preset: 'ts-jest', | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { generateInfo } from '../ffmpeg' | ||
import { PouchDBMediaDocument } from '../db' | ||
import path from 'path' | ||
import moment from 'moment' | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-var-requires | ||
const targetVersions = require('./ffmpegReleases.json') | ||
|
||
const testMediaPath = path.join(__dirname, 'samples') | ||
|
||
function runForFFmpegRelease(ffprobePath: string, ffmpegPath: string) { | ||
function createBareDoc(filename: string): PouchDBMediaDocument { | ||
return { | ||
_id: 'test', | ||
_rev: '0', | ||
mediaPath: path.join(testMediaPath, filename), | ||
mediaSize: 45678, | ||
mediaTime: moment('2023-12-06 12:34:56').unix() * 1000, | ||
} | ||
} | ||
const defaultConfig = { | ||
metadata: null, | ||
paths: { | ||
media: testMediaPath, | ||
ffprobe: ffprobePath, | ||
ffmpeg: ffmpegPath, | ||
}, | ||
} | ||
|
||
it('png', async () => { | ||
const doc = createBareDoc('grey.png') | ||
await generateInfo(defaultConfig, doc) | ||
expect(doc.cinf).toBe('"GREY" STILL 45678 20231206123456 0 0/1\r\n') | ||
}) | ||
} | ||
|
||
const ffprobeFilename = process.platform === 'win32' ? 'bin/ffprobe.exe' : 'ffprobe' | ||
const ffmpegFilename = process.platform === 'win32' ? 'bin/ffmpeg.exe' : 'ffmpeg' | ||
|
||
const ffmpegRootPath = path.join(__dirname, '../../.ffmpeg') | ||
for (const version of targetVersions[`${process.platform}-${process.arch}`]) { | ||
describe(`FFmpeg ${version.id}`, () => { | ||
runForFFmpegRelease( | ||
path.join(ffmpegRootPath, version.id, ffprobeFilename), | ||
path.join(ffmpegRootPath, version.id, ffmpegFilename) | ||
) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
{ | ||
"linux-x64": [ | ||
{ | ||
"id": "4.1.4", | ||
"url": "https://github.com/CasparCG/dependencies/releases/download/ffmpeg-binaries/ffmpeg-4.1.4-amd64-static.tar.xz" | ||
}, | ||
{ | ||
"id": "4.2.2", | ||
"url": "https://github.com/CasparCG/dependencies/releases/download/ffmpeg-binaries/ffmpeg-4.2.2-amd64-static.tar.xz" | ||
}, | ||
{ | ||
"id": "4.4.1", | ||
"url": "https://github.com/CasparCG/dependencies/releases/download/ffmpeg-binaries/ffmpeg-4.4.1-amd64-static.tar.xz" | ||
}, | ||
{ | ||
"id": "5.1.1", | ||
"url": "https://github.com/CasparCG/dependencies/releases/download/ffmpeg-binaries/ffmpeg-5.1.1-amd64-static.tar.xz" | ||
}, | ||
{ | ||
"id": "6.1", | ||
"url": "https://github.com/CasparCG/dependencies/releases/download/ffmpeg-binaries/ffmpeg-6.1-amd64-static.tar.xz" | ||
} | ||
], | ||
"win32-x64": [ | ||
{ | ||
"id": "4.1.4", | ||
"url": "https://github.com/CasparCG/dependencies/releases/download/ffmpeg-binaries/ffmpeg-4.1.4-win64-static.zip" | ||
}, | ||
{ | ||
"id": "4.2.2", | ||
"url": "https://github.com/CasparCG/dependencies/releases/download/ffmpeg-binaries/ffmpeg-4.2.2-win64-static.zip" | ||
}, | ||
{ | ||
"id": "4.3.1", | ||
"url": "https://github.com/CasparCG/dependencies/releases/download/ffmpeg-binaries/ffmpeg-4.3.1-win64-static.zip" | ||
}, | ||
{ | ||
"id": "5.1.2", | ||
"url": "https://github.com/CasparCG/dependencies/releases/download/ffmpeg-binaries/ffmpeg-5.1.2-essentials_build.zip" | ||
}, | ||
{ | ||
"id": "6.1", | ||
"url": "https://github.com/CasparCG/dependencies/releases/download/ffmpeg-binaries/ffmpeg-6.1-essentials_build.zip" | ||
} | ||
] | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import fs from 'fs/promises' | ||
import { pipeline } from 'node:stream' | ||
import { promisify } from 'node:util' | ||
import { createWriteStream } from 'node:fs' | ||
import path from 'path' | ||
import cp from 'child_process' | ||
|
||
const targetVersions = JSON.parse(await fs.readFile('./src/__tests__/ffmpegReleases.json')) | ||
|
||
const toPosix = (str) => str.split(path.sep).join(path.posix.sep) | ||
|
||
const streamPipeline = promisify(pipeline) | ||
|
||
const ffmpegRootDir = './.ffmpeg' | ||
await fs.mkdir(ffmpegRootDir).catch(() => null) | ||
|
||
async function pathExists(path) { | ||
try { | ||
await fs.stat(path) | ||
return true | ||
} catch (e) { | ||
return false | ||
} | ||
} | ||
|
||
const platformInfo = `${process.platform}-${process.arch}` | ||
const platformVersions = targetVersions[platformInfo] | ||
|
||
if (platformVersions) { | ||
const tmpPath = path.join(ffmpegRootDir, 'tmp') | ||
|
||
for (const version of platformVersions) { | ||
const versionPath = path.join(ffmpegRootDir, version.id) | ||
const dirStat = await pathExists(versionPath) | ||
if (!dirStat) { | ||
console.log(`Fetching ${version.url}`) | ||
// Download it | ||
|
||
// eslint-disable-next-line no-undef | ||
const response = await fetch(version.url) | ||
if (!response.ok) throw new Error(`unexpected response ${response.statusText}`) | ||
await streamPipeline(response.body, createWriteStream(tmpPath)) | ||
|
||
// Extract it | ||
if (version.url.endsWith('.tar.xz')) { | ||
await fs.mkdir(versionPath).catch(() => null) | ||
cp.execSync(`tar -xJf ${toPosix(tmpPath)} --strip-components=1 -C ${toPosix(versionPath)}`) | ||
} else if (version.url.endsWith('.zip')) { | ||
cp.execSync(`unzip ${toPosix(tmpPath)} -d ${toPosix(ffmpegRootDir)}`) | ||
|
||
const dirname = path.parse(version.url).name | ||
await fs.rename(path.join(ffmpegRootDir, dirname), versionPath) | ||
} else { | ||
throw new Error(`Unhandled file extension: ${version.url}`) | ||
} | ||
await fs.rm(tmpPath) | ||
} | ||
} | ||
} else { | ||
throw new Error(`FFmpeg downloading for "${platformInfo}" not supported yet`) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.