Skip to content

Commit

Permalink
encore profile generation
Browse files Browse the repository at this point in the history
  • Loading branch information
oshinongit committed Nov 3, 2023
1 parent a700a1b commit 8c9237f
Show file tree
Hide file tree
Showing 9 changed files with 275 additions and 118 deletions.
43 changes: 43 additions & 0 deletions examples/encore/encoreExample.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { EncorePipelineConfiguration } from '../../src/pipelines/encore/encore-pipeline-configuration';
import { EncorePipeline } from '../../src/pipelines/encore/encore-pipeline';
import createJob from '../../src/create-job';
import fs from 'fs';

async function transcodeInputsAndAnalyze() {

const configuration: EncorePipelineConfiguration = {
apiAddress: "https://api-encore.stage.osaas.io",
token: "",
instanceId: "dummy",
profilesUrl: "profilesUrl",
outputFolder: "/usercontent/demo",
baseName: "_demo",
inputs: ["https://testcontent.eyevinn.technology/mp4/stswe-tvplus-promo.mp4"],
duration: 120,
priority: 0,
encorePollingInterval_ms: 30000,
encoreInstancePostCreationDelay_ms: 10000
};

const inlineProfile = fs.readFileSync('encoreProfile.yml', 'utf8');

const resolutions = [{
width: 1280,
height: 720,
range: {
min: 500000,
max: 600000
}
}];

const bitrates = [
500000,
600000,
800000
]

const pipeline: EncorePipeline = new EncorePipeline(configuration);
await pipeline.transcode(configuration.inputs[0], { width: 1280, height: 720}, 600000, "output", undefined, inlineProfile, resolutions, bitrates);
}

transcodeInputsAndAnalyze();
17 changes: 17 additions & 0 deletions examples/encore/encoreProfile.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: X264Encode
description: Program profile
scaling: bicubic
encodes:
- type: X264Encode
suffix: _x264_
twoPass: true
height:
width:
params:
b:v:
maxrate:
minrate:
r: 25
fps_mode: cfr
pix_fmt: yuv420p
force_key_frames: expr:not(mod(n,96))
12 changes: 12 additions & 0 deletions examples/encore/pipeline.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
encore:
apiAddress: https://api-encore.stage.osaas.io,
token: null,
instanceId: dummy,
profilesUrl: profilesUrl,
outputFolder: /usercontent/demo,
baseName: _demo,
inputs: ['https://testcontent.eyevinn.technology/mp4/stswe-tvplus-promo.mp4'],
duration: 120,
priority: 0,
encorePollingInterval_ms: 30000,
encoreInstancePostCreationDelay_ms: 10000,
28 changes: 0 additions & 28 deletions examples/encoreExample.ts

This file was deleted.

1 change: 0 additions & 1 deletion src/analysis/brute-force.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ export default async function analyzeBruteForce(directory: string, reference: st
if (options.pipelineVariables) {
// Create all combinations of bitrate, resolution, and variables
Object.entries(options.pipelineVariables).forEach(([variableName, values]) => {
//console.log(`variableName: ${variableName}`);
pairs = pairs.flatMap(pair =>
values.map( value => {
const variables = pair.ffmpegOptionVariables ? {...pair.ffmpegOptionVariables} : {};
Expand Down
49 changes: 49 additions & 0 deletions src/encoreYamlGenerator.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import * as fs from 'fs';
import YAML from 'yaml';
import { Resolution } from '../src/models/resolution';

export class EncoreYAMLGenerator {

createProfile(inlineProfile: string, resolutions: Resolution[], bitRates: number[]): string {

const inlineProfileObject = YAML.parse(inlineProfile);
let profiles: string[] = [];

resolutions.forEach(resolution => {
bitRates.forEach(bitRate => {
const encoding = this.modifyEncoreProfileAttributes(inlineProfileObject.encodes[0], resolution, bitRate);
profiles.push(encoding)
})
});

let i = 0;
profiles.forEach(encodingProfile => {
inlineProfileObject.encodes[i] = encodingProfile;
i++;
})

const profile = YAML.stringify(inlineProfileObject);
this.saveToFile("test_output_profile.yml", profile);

return profile
}

modifyEncoreProfileAttributes(profileEncodesObject: any, resolution: Resolution, bitRate: number): string {

const data = profileEncodesObject;

data.height = resolution.height;
data.width = resolution.width;
data.params['b:v'] = bitRate;
data.params['maxrate'] = resolution.range?.max;
data.params['minrate'] = resolution.range?.min;

const updatedYAML = YAML.stringify(data);

return updatedYAML;
}

saveToFile(filePath: string, yaml: string) {
fs.writeFileSync(filePath, yaml);
}
}
17 changes: 17 additions & 0 deletions src/load-pipeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import fs from 'fs';
import YAML from 'yaml';
import LocalPipeline from './pipelines/local/local-pipeline';
import AWSPipeline from './pipelines/aws/aws-pipeline';
import { EncorePipeline } from './pipelines/encore/encore-pipeline';
import { Pipeline } from './pipelines/pipeline';
import logger from './logger';
import { LocalPipelineConfiguration } from './pipelines/local/local-pipeline-configuration';
Expand Down Expand Up @@ -30,6 +31,20 @@ export type PipelineProfile = {
pythonPath: string;
ffmpegEncoder: 'libx264' | 'h264_videotoolbox';
};

encore?: {
apiAddress: string;
token: string;
instanceId: string;
profilesUrl: string;
outputFolder: string;
baseName: string;
inputs: Array<string>;
duration: number;
priority: number;
encorePollingInterval_ms: number;
encoreInstancePostCreationDelay_ms: number
}
};

/**
Expand All @@ -53,6 +68,8 @@ async function loadPipeline(pipelineFilename: string, encodingProfile?: string):
return new AWSPipeline({ ...pipelineProfile.aws, mediaConvertSettings: encodingProfileData });
} else if (pipelineProfile.local !== undefined) {
return new LocalPipeline({ ...pipelineProfile.local, ffmpegOptions: encodingProfileData });
} else if (pipelineProfile.encore !== undefined) {
return new EncorePipeline(pipelineProfile.encore);
} else {
throw new Error(`Invalid pipeline: ${JSON.stringify(pipelineProfile)}`);
}
Expand Down
2 changes: 1 addition & 1 deletion src/pipelines/encore/encore-pipeline-configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ export type EncorePipelineConfiguration = {
apiAddress: string;
token: string;
instanceId: string;
profile: string;
profilesUrl: string;
outputFolder: string;
baseName: string;
inputs: Array<string>;
Expand Down
Loading

0 comments on commit 8c9237f

Please sign in to comment.