Skip to content

Commit

Permalink
fix: support ffmpeg 7 (#1)
Browse files Browse the repository at this point in the history
This removes getCpuTime that breaks functionality for mac/windows
  • Loading branch information
oscnord authored Jun 1, 2024
1 parent f858bc6 commit 8cb97b0
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 60 deletions.
29 changes: 20 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@
"@types/yargs": "^17.0.13",
"aws-sdk-client-mock": "^0.6.2",
"jest": "^28.1.3",
"prettier": "^3.2.5",
"tslib": "^2.3.1",
"typescript": "^4.6.2",
"prettier": "^3.2.5"
"typescript": "^4.6.2"
},
"dependencies": {
"@aws-sdk/client-ecs": "^3.36.0",
Expand All @@ -57,7 +57,7 @@
"@aws-sdk/lib-storage": "^3.36.0",
"@types/aws-lambda": "^8.10.86",
"aws-sdk": "^2.1584.0",
"fluent-ffmpeg": "https://github.com/Eyevinn/node-fluent-ffmpeg.git#measure-cpu",
"fluent-ffmpeg": "^2.1.3",
"objects-to-csv": "^1.3.6",
"papaparse": "^5.3.1",
"typedoc": "^0.22.15",
Expand Down
4 changes: 1 addition & 3 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,7 @@ async function exportWmafResultToCsv(argv) {
filename: resolutionVmaf.vmafFile,
resolution: `${resolutionVmaf.resolution.width}X${resolutionVmaf.resolution.height}`,
vmaf: resolutionVmaf.vmaf,
bitrate: result[0],
realTime: resolutionVmaf.cpuTime?.realTime,
cpuTime: resolutionVmaf.cpuTime?.cpuTime
bitrate: result[0]
}));
});

Expand Down
46 changes: 1 addition & 45 deletions src/pairVmaf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ export async function pairVmafWithResolutionAndBitrate(
{
resolution: Resolution;
vmaf: number;
cpuTime?: { realTime: number; cpuTime: number };
vmafFile: string;
}[]
>();
Expand All @@ -36,31 +35,24 @@ export async function pairVmafWithResolutionAndBitrate(
vmafs.map((vmaf) => path.resolve(directoryWithVmafFiles, vmaf.filename))
)
: undefined;
const cpuTimes:
| Record<string, { realTime: number; cpuTime: number }>
| undefined = await getCpuTimes(
vmafs.map((vmaf) => path.resolve(directoryWithVmafFiles, vmaf.filename))
);
vmafs.forEach(({ filename, vmaf }) => {
const [resolutionStr, bitrateStr] = filename.split('_');
const [widthStr, heightStr] = resolutionStr.split('x');

const width = parseInt(widthStr);
const height = parseInt(heightStr);
const bitrate = bitrates ? bitrates[filename] : parseInt(bitrateStr);
const cpuTime = cpuTimes ? cpuTimes[filename] : undefined;

if (filterFunction(bitrate, { width, height }, vmaf)) {
if (pairs.has(bitrate)) {
pairs.get(bitrate)?.push({
resolution: { width, height },
vmaf,
cpuTime,
vmafFile: filename
});
} else {
pairs.set(bitrate, [
{ resolution: { width, height }, vmaf, cpuTime, vmafFile: filename }
{ resolution: { width, height }, vmaf, vmafFile: filename }
]);
}
}
Expand All @@ -71,42 +63,6 @@ export async function pairVmafWithResolutionAndBitrate(
return pairs;
}

async function getCpuTimes(vmafFiles: string[]) {
const cpuTimes: Record<string, { realTime: number; cpuTime: number }> = {};
for (const filename of vmafFiles) {
cpuTimes[path.basename(filename)] = await getCpuTime(filename);
}
return cpuTimes;
}

async function getCpuTime(file: string) {
let timeFile = file.replace('_vmaf.json', '.mp4.pass1-cpu-time.txt');
if (!fileExists(timeFile)) {
// Look in parent folder
timeFile = path.resolve(
path.dirname(timeFile),
`../${path.basename(timeFile)}`
);
}
if (!fileExists(timeFile)) {
throw new Error(
`Unable to find corresponding cpu-time file: ${timeFile} for vmaf file: ${file}`
);
}

const metadata = JSON.parse(fs.readFileSync(timeFile, 'utf8'));
const realTime = metadata.realTime as number;
const cpuUserMode = metadata.cpuUserMode as number;
const cpuKernelMode = metadata.cpuKernelMode as number;
console.log(
`Got time data realTime: ${realTime}, cpuUserMode: ${cpuUserMode}, cpuKernelMode: ${cpuKernelMode} from file ${timeFile}`
);
return {
realTime,
cpuTime: parseFloat((cpuUserMode + cpuKernelMode).toFixed(2))
};
}

async function getBitrates(
filenames: string[]
): Promise<Record<string, number>> {
Expand Down

0 comments on commit 8cb97b0

Please sign in to comment.