Skip to content

Commit

Permalink
test yaml generator
Browse files Browse the repository at this point in the history
  • Loading branch information
oshinongit committed Oct 26, 2023
1 parent a700a1b commit faa21c6
Show file tree
Hide file tree
Showing 4 changed files with 221 additions and 69 deletions.
17 changes: 11 additions & 6 deletions examples/encoreExample.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { EncorePipelineConfiguration } from '../src/pipelines/encore/encore-pipeline-configuration';
import { EncorePipeline, delay } from '../src/pipelines/encore/encore-pipeline';
import { EncoreInstance } from '../src/models/encoreInstance';
import { EncorePipeline } from '../src/pipelines/encore/encore-pipeline';
import { Resolution } from '../src/models/resolution';
import { BitrateResolutionPair } from '../src/models/bitrate-resolution-pair';

async function transcodeInputsAndAnalyze() {

Expand All @@ -16,12 +17,16 @@ async function transcodeInputsAndAnalyze() {
priority: 0,
encorePollingInterval_ms: 30000,
encoreInstancePostCreationDelay_ms: 10000
};
};

const bitrateResolutionPairs: BitrateResolutionPair[] = [
{resolution: { width: 1280, height: 720}, bitrate: 600000},
{resolution: { width: 640, height: 360}, bitrate: 600000},
{resolution: { width: 768, height: 432}, bitrate: 600000}
]

const pipeline: EncorePipeline = new EncorePipeline(configuration);
const instance: EncoreInstance = await pipeline.createEncoreInstance(configuration.apiAddress, configuration.token, configuration.instanceId, configuration.profile);
await delay(pipeline.configuration.encoreInstancePostCreationDelay_ms); // Delay required to allow instance to be created before calling it
await pipeline.runTranscodeThenAnalyze(instance);
await pipeline.transcode(configuration.inputs[0], { width: 1280, height: 720}, 600000, "output", undefined, bitrateResolutionPairs);

}

Expand Down
77 changes: 77 additions & 0 deletions src/encoreYamlGenerator.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import * as fs from 'fs';
import { EncoreEncodeType, EncoreProgramProfile } from './models/encoreProfileTypes';

export class EncoreYAMLGenerator {
generateYAML(profile: EncoreProgramProfile): string {
const yamlContent = `
name: ${profile.name}
description: ${profile.description}
scaling: ${profile.scaling}
encodes:
${profile.encodes
.map((encode) => `
- type: ${encode.type}
suffix: ${encode.suffix}
twoPass: ${encode.twoPass}
height: ${encode.height}
params:${Object.entries(encode.params)
.map(([key, value]) => `
${key}: ${value}`)
.join('')}
`)
.join('')}
`;

return yamlContent;
}

createEncodeObject(
type: string,
suffix: string,
twoPass: boolean,
height: number,
params: { [key: string]: string }
): EncoreEncodeType {
return {
type,
suffix,
twoPass,
height,
params,
};
}

saveToFile(profile: EncoreProgramProfile, filePath: string) {
const generatedYAML = this.generateYAML(profile);
fs.writeFileSync(filePath, generatedYAML);
}
}


// Example usage:
function example() {
const yamlGenerator = new EncoreYAMLGenerator();

const encodeObject = yamlGenerator.createEncodeObject('X264Encode', '_x264_3100', true, 1080, {
'b:v': '3100k',
maxrate: '4700k',
bufsize: '6200k',
r: '25',
fps_mode: 'cfr',
pix_fmt: 'yuv420p',
force_key_frames: 'expr:not(mod(n,96))',
preset: 'medium',
});

const encodeObjects: EncoreEncodeType[] = [];
encodeObjects.push(encodeObject);

const programProfile: EncoreProgramProfile = {
name: 'encoreProgram',
description: 'Program profile',
scaling: 'bicubic',
encodes: encodeObjects,
};

yamlGenerator.saveToFile(programProfile, 'encoreProfile.yml');
}
14 changes: 14 additions & 0 deletions src/models/encoreProfileTypes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
export type EncoreEncodeType = {
type: string;
suffix: string;
twoPass: boolean;
height: number;
params: { [key: string]: string };
}

export type EncoreProgramProfile = {
name: string;
description: string;
scaling: string;
encodes: EncoreEncodeType[];
}
Loading

0 comments on commit faa21c6

Please sign in to comment.