Skip to content

Commit

Permalink
Remove ability to disable ffmpeg transcoding; Fixes #440 (#444)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisbenincasa authored May 20, 2024
1 parent 342a54c commit 06c456a
Show file tree
Hide file tree
Showing 10 changed files with 122 additions and 187 deletions.
2 changes: 1 addition & 1 deletion server/src/api/videoApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ export const videoRouter: RouterPluginAsyncCallback = async (fastify) => {
return res
.type('application/x-mpegURL')
.send(
await req.serverCtx.m3uService.buildChannelM3U(
req.serverCtx.m3uService.buildChannelM3U(
req.protocol,
req.hostname,
req.params.id,
Expand Down
5 changes: 2 additions & 3 deletions server/src/dao/legacy_migration/legacyDbMigration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -362,9 +362,8 @@ export class LegacyDbMigrator {
numThreads: ffmpegSettings['threads'] as number,
concatMuxDelay: ffmpegSettings['concatMuxDelay'] as number,
enableLogging: ffmpegSettings['logFfmpeg'] as boolean,
enableTranscoding: ffmpegSettings[
'enableFFMPEGTranscoding'
] as boolean,
// This is ignored now
enableTranscoding: true,
audioVolumePercent: ffmpegSettings[
'audioVolumePercent'
] as number,
Expand Down
26 changes: 2 additions & 24 deletions server/src/ffmpeg/ffmpeg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import { isNonEmptyString } from '../util/index.js';
const spawn = child_process.spawn;

const MAXIMUM_ERROR_DURATION_MS = 60000;
const REALLY_RIDICULOUSLY_HIGH_FPS_FOR_TUNARRS_USECASE = 120;

const STILLIMAGE_SUPPORTED_ENCODERS = [
'mpeg2video',
Expand Down Expand Up @@ -111,20 +110,6 @@ export class FFMPEG extends (events.EventEmitter as new () => TypedEventEmitter<
serverOptions().port
}/images/generic-error-screen.png`;
this.ffmpegName = 'unnamed ffmpeg';
if (!this.opts.enableTranscoding) {
// this ensures transcoding is completely disabled even if
// some settings are true
this.opts = {
...this.opts,
normalizeAudio: false,
normalizeAudioCodec: false,
normalizeVideoCodec: false,
errorScreen: 'kill',
normalizeResolution: false,
audioVolumePercent: 100,
maxFPS: REALLY_RIDICULOUSLY_HIGH_FPS_FOR_TUNARRS_USECASE,
};
}
this.channel = channel;
this.ffmpegPath = opts.ffmpegExecutablePath;

Expand Down Expand Up @@ -339,7 +324,7 @@ export class FFMPEG extends (events.EventEmitter as new () => TypedEventEmitter<
}

spawnError(title: string, subtitle?: string, duration?: number) {
if (!this.opts.enableTranscoding || this.opts.errorScreen == 'kill') {
if (this.opts.errorScreen === 'kill') {
this.logger.error('error: ' + title + ' ; ' + subtitle);
this.emit('error', {
code: -1,
Expand Down Expand Up @@ -369,19 +354,12 @@ export class FFMPEG extends (events.EventEmitter as new () => TypedEventEmitter<
}

spawnOffline(duration: number) {
if (!this.opts.enableTranscoding) {
this.logger.info(
'The channel has an offline period scheduled for this time slot. FFMPEG transcoding is disabled, so it is not possible to render an offline screen. Ending the stream instead',
);
this.emit('end', { code: -1, cmd: `offline stream disabled.` });
return;
}

const streamStats = {
videoWidth: this.wantedW,
videoHeight: this.wantedH,
duration: duration,
};

return this.spawn(
{ errorTitle: 'offline' },
streamStats,
Expand Down
14 changes: 4 additions & 10 deletions server/src/services/m3uService.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { sortBy } from 'lodash-es';
import { ChannelDB } from '../dao/channelDb.js';
import { FileCacheService } from './fileCacheService.js';
import { getSettings } from '../dao/settings.js';

/**
* Manager and Generate M3U content
Expand Down Expand Up @@ -80,13 +79,12 @@ export class M3uService {
return this.replaceHostOnM3u(host, data);
}

async buildChannelM3U(
buildChannelM3U(
protocol: string,
host: string,
channel: string | number,
sessionId: number,
) {
const settings = await getSettings();
// Maximum number of streams to concatinate beyond channel starting
// If someone passes this number then they probably watch too much television
const maxStreamsToPlayInARow = 100;
Expand All @@ -101,13 +99,9 @@ export class M3uService {
// `#EXT-X-STREAM-INF:BANDWIDTH=1123000`,
];

const ffmpegSettings = settings.ffmpegSettings();

if (ffmpegSettings.enableTranscoding) {
lines.push(
`${protocol}://${host}/stream?channel=${channel}&first=0&m3u8=1&session=${sessionId}`,
);
}
lines.push(
`${protocol}://${host}/stream?channel=${channel}&first=0&m3u8=1&session=${sessionId}`,
);

lines.push(
`${protocol}://${host}/stream?channel=${channel}&first=1&m3u8=1&session=${sessionId}`,
Expand Down
8 changes: 3 additions & 5 deletions server/src/stream/plex/plexPlayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,10 @@ import { Writable } from 'stream';
import { isContentBackedLineupIteam } from '../../dao/derived_types/StreamLineup.js';
import { PlexServerSettings } from '../../dao/entities/PlexServerSettings.js';
import { FFMPEG, FfmpegEvents } from '../../ffmpeg/ffmpeg.js';
import { Player } from '../player.js';
import { PlexTranscoder } from './plexTranscoder.js';
import { PlayerContext } from '../player.js';
import { TypedEventEmitter } from '../../types/eventEmitter.js';
import { LoggerFactory } from '../../util/logging/LoggerFactory.js';
import { Player, PlayerContext } from '../player.js';
import { PlexTranscoder } from './plexTranscoder.js';

const USED_CLIENTS: Record<string, boolean> = {};
export class PlexPlayer extends Player {
Expand Down Expand Up @@ -99,9 +98,8 @@ export class PlexPlayer extends Player {
) {
streamDuration = lineupItem.streamDuration / 1000;
}
const deinterlace = ffmpegSettings.enableTranscoding; //for now it will always deinterlace when transcoding is enabled but this is sub-optimal

const stream = await plexTranscoder.getStream(deinterlace);
const stream = await plexTranscoder.getStream(/* deinterlace=*/ true);
if (this.killed) {
return;
}
Expand Down
5 changes: 1 addition & 4 deletions server/src/stream/programPlayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,10 +158,7 @@ export class ProgramPlayer extends Player {
channel: StreamContextChannel,
type: string,
): Maybe<Watermark> {
if (
!ffmpegSettings.enableTranscoding ||
ffmpegSettings.disableChannelOverlay
) {
if (ffmpegSettings.disableChannelOverlay) {
return;
}

Expand Down
1 change: 1 addition & 0 deletions types/src/schemas/settingsSchemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export const FfmpegSettingsSchema = z.object({
numThreads: z.number().default(4),
concatMuxDelay: z.number().default(0),
enableLogging: z.boolean().default(false),
// DEPRECATED
enableTranscoding: z.boolean().default(true),
audioVolumePercent: z.number().default(100),
videoEncoder: z.string().default('mpeg2video'),
Expand Down
12 changes: 3 additions & 9 deletions web/src/components/channel_config/ChannelTranscodingConfig.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -338,9 +338,7 @@ export default function ChannelTranscodingConfig() {
name="transcoding.targetResolution"
render={() => (
<Select<ResolutionOptionValues>
disabled={
isNil(ffmpegSettings) || !ffmpegSettings.enableTranscoding
}
disabled={isNil(ffmpegSettings)}
label="Channel Resolution"
value={targetResString}
onChange={(e) => handleResolutionChange(e)}
Expand All @@ -364,9 +362,7 @@ export default function ChannelTranscodingConfig() {
<Controller
control={control}
name="transcoding.videoBitrate"
disabled={
isNil(ffmpegSettings) || !ffmpegSettings.enableTranscoding
}
disabled={isNil(ffmpegSettings)}
rules={{ pattern: globalOrNumber }}
render={({ field, formState: { errors } }) => (
<TextField
Expand All @@ -391,9 +387,7 @@ export default function ChannelTranscodingConfig() {
<Controller
control={control}
name="transcoding.videoBufferSize"
disabled={
isNil(ffmpegSettings) || !ffmpegSettings.enableTranscoding
}
disabled={isNil(ffmpegSettings)}
rules={{ pattern: globalOrNumber }}
render={({ field, formState: { errors } }) => (
<TextField
Expand Down
Loading

0 comments on commit 06c456a

Please sign in to comment.