Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions server/src/db/ChannelDB.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ function updateRequestToChannel(updateReq: SaveChannelRequest): ChannelUpdate {
guideFlexTitle: updateReq.guideFlexTitle,
transcodeConfigId: updateReq.transcodeConfigId,
streamMode: updateReq.streamMode,
subtitlesEnabled: booleanToNumber(updateReq.subtitlesEnabled),
} satisfies ChannelUpdate;
}

Expand Down Expand Up @@ -198,6 +199,7 @@ function createRequestToChannel(saveReq: SaveChannelRequest): NewChannel {
fillerRepeatCooldown: saveReq.fillerRepeatCooldown,
guideFlexTitle: saveReq.guideFlexTitle,
streamMode: saveReq.streamMode,
subtitlesEnabled: saveReq.subtitlesEnabled ? 1 : 0,
transcodeConfigId: saveReq.transcodeConfigId,
} satisfies NewChannel;
}
Expand Down
1 change: 1 addition & 0 deletions server/src/db/converters/channelConverters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export const dbChannelToApiChannel = ({
transcoding: nilToUndefined(channel.transcoding),
duration: channel.duration,
stealth: channel.stealth === 1,
subtitlesEnabled: channel.subtitlesEnabled === 1,
onDemand: {
enabled: isDefined(lineup.onDemandConfig),
},
Expand Down
2 changes: 2 additions & 0 deletions server/src/db/schema/Channel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export interface ChannelTable extends WithUuid, WithCreatedAt, WithUpdatedAt {
startTime: number;
stealth: ColumnType<number, number | undefined>;
streamMode: ColumnType<ChannelStreamMode, ChannelStreamMode | undefined>;
subtitlesEnabled: Generated<number>;
transcoding: JSONColumnType<ChannelTranscodingSettings | null, string | null>;
transcodeConfigId: string;
watermark: JSONColumnType<ChannelWatermark | null, string | null>;
Expand All @@ -54,6 +55,7 @@ const ChannelTableKeys: (keyof ChannelTable)[] = [
'startTime',
'stealth',
'streamMode',
'subtitlesEnabled',
'transcoding',
'transcodeConfigId',
'updatedAt',
Expand Down
4 changes: 2 additions & 2 deletions server/src/ffmpeg/FfmpegStreamFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -686,8 +686,8 @@ export class FfmpegStreamFactory extends IFFMPEG {
return isNonEmptyString(this.ffmpegSettings.vaapiDevice)
? this.ffmpegSettings.vaapiDevice
: isLinux()
? '/dev/dri/renderD128'
: undefined;
? '/dev/dri/renderD128'
: undefined;
}

private getVaapiDriver() {
Expand Down
25 changes: 19 additions & 6 deletions server/src/ffmpeg/ffmpeg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ export type HlsOptions = {
streamBaseUrl: string;
segmentNameFormat: string;
streamNameFormat: string;
subtitleNameFormat: string;
deleteThreshold: Nullable<number>;
appendSegments: boolean;
};
Expand Down Expand Up @@ -94,6 +95,7 @@ export const defaultHlsOptions: DeepRequired<HlsOptions> = {
segmentNameFormat: 'data%05d.ts',
streamNameFormat: 'stream.m3u8',
streamBaseUrl: 'hls/',
subtitleNameFormat: 'stream_vtt.m3u8',
deleteThreshold: 3,
appendSegments: false,
};
Expand Down Expand Up @@ -350,8 +352,8 @@ export class FFMPEG implements IFFMPEG {
streamDetails,
startTime,
duration,
realtime,
enableIcon,
realtime,
outputFormat,
ptsOffset ?? null,
);
Expand Down Expand Up @@ -394,8 +396,8 @@ export class FFMPEG implements IFFMPEG {
streamStats,
undefined,
streamStats.duration!,
true,
/*watermark=*/ undefined,
true,
outputFormat,
null,
);
Expand All @@ -417,8 +419,8 @@ export class FFMPEG implements IFFMPEG {
streamStats,
undefined,
duration,
true,
undefined,
true,
outputFormat,
null,
);
Expand All @@ -429,8 +431,8 @@ export class FFMPEG implements IFFMPEG {
streamStats: Maybe<StreamDetails>,
startTime: Maybe<Duration>,
duration: Duration,
realtime: boolean,
watermark: Maybe<Watermark>,
realtime: boolean,
outputFormat: OutputFormat,
ptsOffset: Nullable<number>,
): Promise<Maybe<FfmpegTranscodeSession>> {
Expand All @@ -449,6 +451,11 @@ export class FFMPEG implements IFFMPEG {
find(streamStats?.audioDetails, { selected: true }) ??
find(streamStats?.audioDetails, { default: true }) ??
first(streamStats?.audioDetails);
const subtitleStream =
find(streamStats?.subtitleDetails, { selected: true }) ??
find(streamStats?.subtitleDetails, { default: true }) ??
first(streamStats?.subtitleDetails) ??
undefined;

// Initialize like this because we're not checking whether or not
// the input is hardware decodeable, yet.
Expand Down Expand Up @@ -729,6 +736,12 @@ export class FFMPEG implements IFFMPEG {
iH = iH!;
}

if (this.channel.subtitlesEnabled && subtitleStream) {
console.log('Adding sub opts');
console.log(subtitleStream)
ffmpegArgs.push('-map', `0:${subtitleStream.index}`, '-c:s', 'webvtt', '-var_stream_map', `v:0,a:0,s:0,name:subs`)
}

if (doOverlay && !isNil(watermark?.url)) {
if (watermark.animated) {
ffmpegArgs.push('-ignore_loop', '0', '-stream_loop', '-1');
Expand Down Expand Up @@ -1111,7 +1124,6 @@ export class FFMPEG implements IFFMPEG {
this.logger.info('ffmpeg preemptively killed');
return;
}

return this.createProcess(ffmpegArgs, duration);
}

Expand All @@ -1120,7 +1132,7 @@ export class FFMPEG implements IFFMPEG {
streamDuration?: Duration,
): FfmpegTranscodeSession {
const process = new FfmpegProcess(this.opts, this.ffmpegName, ffmpegArgs);

console.log(process);
// TODO: Do we need a more accurate measure of "streamEndTime" by passing in
// the request start time? Or is this really inaccurate because we still have
// a short amount of time before the stream is actually started...
Expand Down Expand Up @@ -1184,6 +1196,7 @@ export class FFMPEG implements IFFMPEG {
'-master_pl_name',
'master.m3u8',
path.join('streams', hlsOpts.streamBasePath, hlsOpts.streamNameFormat),
path.join('streams', hlsOpts.streamBasePath, hlsOpts.subtitleNameFormat),
];
}

Expand Down
2 changes: 2 additions & 0 deletions server/src/migration/DirectMigrationProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import LegacyMigration9 from './db/LegacyMigration9.ts';
import Migration1730806741 from './db/Migration1730806741.ts';
import Migration1731982492 from './db/Migration1731982492.ts';
import Migration1732969335_AddTranscodeConfig from './db/Migration1732969335_AddTranscodeConfig.ts';
import Migration1736904784_AddSubtitles from './db/Migration1736904784_AddSubtitles.ts';

export const LegacyMigrationNameToNewMigrationName = [
['Migration20240124115044', '_Legacy_Migration00'],
Expand Down Expand Up @@ -87,6 +88,7 @@ export class DirectMigrationProvider implements MigrationProvider {
migration1731982492: Migration1731982492,
migration1732969335: Migration1732969335_AddTranscodeConfig,
migration1735044379: Migration1735044379_AddHlsDirect,
migration1736904784: Migration1736904784_AddSubtitles,
},
wrapWithTransaction,
),
Expand Down
6 changes: 6 additions & 0 deletions server/src/migration/db/Migration1735044379_AddHlsDirect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export default {
.addColumn('transcode_config_id', 'text', (col) =>
col.references('transcode_config.uuid'),
)
.addColumn('subtitles_enabled', 'boolean', (col) => col.notNull().defaultTo(false))
.execute();

await db
Expand All @@ -76,6 +77,7 @@ export default {
'transcoding',
'guideFlexTitle',
'streamMode',
'subtitlesEnabled',
])
.expression(
db
Expand All @@ -99,6 +101,7 @@ export default {
'transcoding',
'guideFlexTitle',
'streamMode',
'subtitlesEnabled',
]),
)
.execute();
Expand Down Expand Up @@ -190,6 +193,7 @@ export default {
.addColumn('transcode_config_id', 'text', (col) =>
col.references('transcode_config.uuid'),
)
.addColumn('subtitles_enabled', 'boolean', (col) => col.notNull().defaultTo(false))
.execute();

await db
Expand All @@ -213,6 +217,7 @@ export default {
'transcoding',
'guideFlexTitle',
'streamMode',
'subtitlesEnabled',
])
.expression(
db
Expand All @@ -236,6 +241,7 @@ export default {
'transcoding',
'guideFlexTitle',
'streamMode',
'subtitlesEnabled',
]),
)
.execute();
Expand Down
Loading