Skip to content

Commit

Permalink
another checkpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisbenincasa committed Oct 2, 2024
1 parent 3e11266 commit c7e4b42
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 15 deletions.
7 changes: 6 additions & 1 deletion server/src/ffmpeg/builder/FfmpegCommandGenerator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ import { setGlobalOptions } from '../../globals';
import { FfmpegCommandGenerator } from './FfmpegCommandGenerator';
import { AudioStream, StillImageStream, VideoStream } from './MediaStream';
import { VideoFormats } from './constants';
import { PixelFormat, PixelFormatYuv420P } from './format/PixelFormat';
import {
PixelFormat,
PixelFormatYuv420P,
PixelFormatYuv420P10Le,
} from './format/PixelFormat';
import { PipelineBuilderFactory } from './pipeline/PipelineBuilderFactory';
import { AudioState } from './state/AudioState';
import { FfmpegState } from './state/FfmpegState';
Expand Down Expand Up @@ -64,6 +68,7 @@ describe('FfmpegCommandGenerator', () => {
frameRate: 20,
videoBitrate: 30_000,
interlaced: true,
pixelFormat: new PixelFormatYuv420P10Le(),
});

const generator = new FfmpegCommandGenerator();
Expand Down
2 changes: 0 additions & 2 deletions server/src/ffmpeg/builder/pipeline/PipelineBuilderFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,6 @@ class PipelineBuilderFactory$Builder {
this.hardwareAccelerationMode,
);

console.log(hardwareCapabilities);

if (isNull(this.videoInputFile)) {
// Audio-only pipeline builder??
throw new Error('Not yet implemented');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { isNil, isNull } from 'lodash-es';
import util from 'node:util';
import { Nullable } from '../../../../types/util';
import { isNonEmptyString } from '../../../../util';
import { VideoFormats } from '../../constants';
Expand Down Expand Up @@ -115,7 +114,7 @@ export class NvidiaPipelineBuilder extends SoftwarePipelineBuilder {
currentState = this.setPad(currentState);

if (currentState.bitDepth === 8 && this.watermarkInputSource) {
console.log('adding pixel filter format for watermark!!!');
this.logger.debug('adding pixel filter format for watermark!!!');
const desiredPixelFormat = new PixelFormatYuv420P();
if (
!isNil(currentState.pixelFormat) &&
Expand Down Expand Up @@ -154,7 +153,6 @@ export class NvidiaPipelineBuilder extends SoftwarePipelineBuilder {
currentState = this.setWatermark(currentState);

let encoder: Nullable<VideoEncoder> = null;
console.log(ffmpegState.encoderHwAccelMode);
if (ffmpegState.encoderHwAccelMode === 'cuda') {
encoder = EncoderFactory.getNvidiaEncoder(videoStream);
}
Expand All @@ -172,7 +170,6 @@ export class NvidiaPipelineBuilder extends SoftwarePipelineBuilder {
this.videoInputFile.filterSteps.push(encoder);
}

this.logger.debug(util.inspect(currentState));
currentState = this.setPixelFormat(currentState);

// args.filterChain.videoFilterSteps.push(...this.videoInputFile.filterSteps);
Expand All @@ -196,7 +193,11 @@ export class NvidiaPipelineBuilder extends SoftwarePipelineBuilder {
let nextState = currentState;
const { desiredState, ffmpegState } = this.context;

console.log('do scale', currentState.scaledSize, desiredState.scaledSize);
this.logger.debug(
'do scale',
currentState.scaledSize,
desiredState.scaledSize,
);
if (currentState.scaledSize.equals(desiredState.scaledSize)) {
return currentState;
}
Expand Down Expand Up @@ -271,10 +272,14 @@ export class NvidiaPipelineBuilder extends SoftwarePipelineBuilder {
let nextState = currentState;
const steps: PipelineFilterStep[] = [];
// TODO ton of stuff to do here
if (!isNull(this.desiredState.pixelFormat)) {
if (this.desiredState.pixelFormat) {
// TODO figure out about available pixel formats
const desiredFormat = this.desiredState.pixelFormat; //.name === PixelFormats.NV12 ? null : this.desiredState.pixelFormat;

if (desiredFormat instanceof PixelFormatNv12) {
// EX
}

// TODO vp9

// TODO color params -- wow there's a lot of stuff to account for!!!
Expand All @@ -284,7 +289,7 @@ export class NvidiaPipelineBuilder extends SoftwarePipelineBuilder {
this.watermarkInputSource &&
currentState.frameDataLocation === 'hardware'
) {
this.logger.debug('%O', currentState);
this.logger.debug('Using software encoder');
const hwDownloadFilter = new HardwareDownloadCudaFilter(
currentState.pixelFormat,
null,
Expand All @@ -293,13 +298,17 @@ export class NvidiaPipelineBuilder extends SoftwarePipelineBuilder {
steps.push(hwDownloadFilter);
}

console.log('pixelFormat', nextState, this.ffmpegState);
this.logger.debug('pixelFormat', nextState, this.ffmpegState);
if (
nextState.frameDataLocation === 'hardware' &&
this.ffmpegState.encoderHwAccelMode === 'none'
) {
if (nextState.pixelFormat?.ffmpegName !== desiredFormat?.ffmpegName) {
// TODO CUDA format filter
this.logger.debug(
"Pixel format %s doesn't equal format %s",
nextState.pixelFormat?.ffmpegName,
desiredFormat?.ffmpegName,
);
const formatFilter = new FormatCudaFilter(desiredFormat);
nextState = formatFilter.nextState(nextState);
steps.push(formatFilter);
Expand Down
20 changes: 17 additions & 3 deletions server/src/util/logging/LoggerFactory.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
import { forEach, isEmpty, isUndefined, nth, toLower, trim } from 'lodash-es';
import {
forEach,
isEmpty,
isString,
isUndefined,
nth,
toLower,
trim,
} from 'lodash-es';
import path, { join } from 'node:path';
import pino, {
Bindings,
Expand Down Expand Up @@ -117,7 +125,7 @@ class LoggerFactoryImpl {
);
}

child(opts: { caller?: ImportMeta; className: string } & Bindings) {
child(opts: { caller?: ImportMeta | string; className: string } & Bindings) {
const { caller, className, ...rest } = opts;

if (this.children[className]) {
Expand All @@ -126,7 +134,13 @@ class LoggerFactoryImpl {

const childOpts = {
...rest,
file: isProduction ? undefined : caller ? getCaller(caller) : undefined,
file: isProduction
? undefined
: caller
? isString(caller)
? caller
: getCaller(caller)
: undefined,
caller: isProduction ? undefined : className, // Don't include this twice in production
};
const newChild = this.rootLogger.child(childOpts);
Expand Down

0 comments on commit c7e4b42

Please sign in to comment.