Skip to content

Commit

Permalink
interface with create-job
Browse files Browse the repository at this point in the history
  • Loading branch information
oshinongit committed Oct 17, 2023
1 parent 8e64f8b commit f8eb1f3
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 33 deletions.
48 changes: 23 additions & 25 deletions examples/encoreExample.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,26 @@
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 { JobDescription } from '../src/create-job';
import createJob from '../src/create-job';

async function transcodeInputsAndAnalyze() {
const configuration: EncorePipelineConfiguration = {
apiAddress: "https://api-encore.stage.osaas.io",
token: "",
instanceId: "dummy",
profile: "program",
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 configuration: EncorePipelineConfiguration = {
apiAddress: "https://api-encore.stage.osaas.io",
token: "",
instanceId: "dummy",
profile: "program",
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 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);

}

transcodeInputsAndAnalyze();
const job: JobDescription = {
name: "myJob",
pipeline: configuration,
encodingProfile: "null",
reference: "null"
}

createJob(job);
23 changes: 17 additions & 6 deletions src/create-job.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,18 @@ import logger from './logger';
import { Resolution } from './models/resolution';
import analyzeWalkTheHull from './analysis/walk-the-hull';
import { LocalPipelineConfiguration } from './pipelines/local/local-pipeline-configuration';

import { EncorePipelineConfiguration } from './pipelines/encore/encore-pipeline-configuration';
import { instanceOfEncorePipelineConfiguration, instanceOfLocalPipelineConfiguration } from './interfaceGuards';
import { EncorePipeline, delay } from './pipelines/encore/encore-pipeline';
import { EncoreInstance } from './models/encoreInstance';

/** Describes a ABR-analysis job and can be used to create jobs using the createJob()-function. */
export type JobDescription = {
/** This will name the folder in which to put the files. */
name: string;

/** Path to a YAML-file that defines the pipeline, or an inline local pipeline configuration. See `examples/pipeline.yml` for an example AWS-pipeline. */
pipeline: string | LocalPipelineConfiguration;
pipeline: string | LocalPipelineConfiguration | EncorePipelineConfiguration;

/** Path to a JSON-file that defines how the reference should be encoded. When using AWS, this is a MediaConvert configuration.
* For local pipelines, this is key-value pairs that will be passed as command line arguments to FFmpeg.
Expand Down Expand Up @@ -111,15 +114,23 @@ export type JobDescription = {
* @param description An object that describes the job to create.
*/
export default async function createJob(description: JobDescription, pipelineData?: any, encodingProfileData?: any, concurrency: boolean = true) {
logger.info(`Creating job ${description.name}.`);
logger.info(`Creating job ${description.name}`);

let pipeline: Pipeline | undefined = undefined;
let pipeline: any | undefined = undefined;
if (pipelineData && encodingProfileData) {
pipeline = await loadPipelineFromObjects(pipelineData, encodingProfileData);
} else if(typeof description.pipeline === 'object') {
} else if(instanceOfLocalPipelineConfiguration(description.pipeline)) {
pipeline = new LocalPipeline({...description.pipeline, ...description.encodingProfile as Record<string,string>} );
} else {
} else if(typeof description.pipeline === 'string'){
pipeline = await loadPipeline(description.pipeline, description.encodingProfile as string);
} else if(instanceOfEncorePipelineConfiguration(description.pipeline)){
pipeline = new EncorePipeline(description.pipeline);
const configuration: EncorePipelineConfiguration = description.pipeline;
const instance: EncoreInstance = await pipeline.createEncoreInstance(configuration.apiAddress, configuration.token, configuration.instanceId, configuration.profile);
await delay(configuration.encoreInstancePostCreationDelay_ms); // Delay required to allow instance to be created before calling it
await pipeline.runTranscodeThenAnalyze(instance);
logger.info(`Finishing Encore Pipeline Job ${description.name}.`);
return
}

if (pipeline === undefined) {
Expand Down
17 changes: 17 additions & 0 deletions src/interfaceGuards.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { EncorePipelineConfiguration } from "./pipelines/encore/encore-pipeline-configuration";
import { LocalPipelineConfiguration } from "./pipelines/local/local-pipeline-configuration";
import logger from './logger';

export function instanceOfLocalPipelineConfiguration(object: any): object is LocalPipelineConfiguration {
return (typeof object === 'object' &&
'ffmpegPath' in object && 'pythonPath' in object && 'easyVmafPath' in object &&
'ffmpegEncoder' in object && 'ffmpegOptions' in object);
}

export function instanceOfEncorePipelineConfiguration(object: any): object is EncorePipelineConfiguration {
return (typeof object === 'object' &&
'apiAddress' in object && 'token' in object && 'instanceId' in object &&
'profile' in object && 'outputFolder' in object && 'baseName' in object &&
'inputs' in object && 'duration' in object && 'priority' in object &&
'encorePollingInterval_ms' in object && 'encoreInstancePostCreationDelay_ms' in object);
}
6 changes: 4 additions & 2 deletions src/pipelines/encore/encore-pipeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ export class EncorePipeline implements Pipeline {
});

logger.info(`File to download: ${filename}`);
const destinationPath: string = `./mediaTransferDir/${filename}`;
const destinationPath: string = `${filename}`;
const stream = fs.createWriteStream(destinationPath);
const { body } = await fetch(request);
await finished(Readable.fromWeb(body).pipe(stream));
Expand All @@ -303,13 +303,15 @@ export class EncorePipeline implements Pipeline {
await this.downloadFile(input, referenceFilename);
await this.pollUntilAllJobsCompleted(instance, jobIds);

fs.readdir("./mediaTransferDir", (err, files) => {
fs.readdir("./", (err, files) => {
files.forEach(file => {
if(file.includes(".mp4") && !file.includes("reference")){
logger.info(`Running analyzeQuality: ${file}`);
//this.analyzeQuality(`./mediaTransferDir/${referenceFilename}`, `./mediaTransferDir/${distorted}`, "oliverEncore/output.json", QualityAnalysisModel.HD)
}
});
});
//add delete instance here
}
}
}
Expand Down

0 comments on commit f8eb1f3

Please sign in to comment.