Skip to content

Commit

Permalink
Some fixes; forcing keyframes based on hls_time, etc
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisbenincasa committed Feb 20, 2024
1 parent 7f74f2f commit 6443d9e
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 10 deletions.
5 changes: 4 additions & 1 deletion server/ffmpeg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,9 @@ export class FFMPEG extends (events.EventEmitter as new () => TypedEventEmitter<
filledOpts.hlsTime.toString(),
'-hls_list_size',
filledOpts.hlsListSize.toString(),
'-force_key_frames',
// Force a key frame every N secodns
`expr:gte(t,n_forced*${filledOpts.hlsTime})`,
'-hls_delete_threshold',
'3', // Num unreferenced segments
'-hls_flags',
Expand Down Expand Up @@ -360,7 +363,7 @@ export class FFMPEG extends (events.EventEmitter as new () => TypedEventEmitter<
console.log(
`video framerate = ${streamStats?.videoFramerate}, max = ${this.opts.maxFPS} `,
);
if (streamStats?.videoFramerate ?? 0 >= this.opts.maxFPS + 0.000001) {
if ((streamStats?.videoFramerate ?? 0) >= this.opts.maxFPS + 0.000001) {
videoComplex += `;${currentVideo}fps=${this.opts.maxFPS}[fpchange]`;
currentVideo = '[fpchange]';
}
Expand Down
7 changes: 5 additions & 2 deletions server/tasks/cleanupSessionsTask.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { chain, forEach, isEmpty, keys } from 'lodash-es';
import { chain, filter, forEach, isEmpty, keys } from 'lodash-es';
import { sessionManager } from '../stream/sessionManager.js';
import { Maybe } from '../types.js';
import { Task, TaskId } from './task.js';
Expand All @@ -12,7 +12,10 @@ export class CleanupSessionsTask extends Task<void> {

// eslint-disable-next-line @typescript-eslint/require-await
protected async runInternal(): Promise<Maybe<void>> {
const sessions = sessionManager.allSessions();
const sessions = filter(
sessionManager.allSessions(),
(session) => session.started,
);

if (isEmpty(sessions)) {
return;
Expand Down
3 changes: 2 additions & 1 deletion server/tsconfig.build.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"exclude": [
"./build/**/*",
"./**/*.test.ts",
"./**/*.ignore.ts"
"./**/*.ignore.ts",
"./streams/**/*.ts"
]
}
3 changes: 2 additions & 1 deletion server/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
],
"exclude": [
"./build/**/*",
"./**/*.ignore.ts"
"./**/*.ignore.ts",
"./streams/**/*.ts"
]
}
23 changes: 18 additions & 5 deletions web2/src/pages/settings/FfmpegSettingsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
FormHelperText,
FormControlLabel,
InputLabel,
Link as MuiLink,
MenuItem,
Stack,
Select,
Expand Down Expand Up @@ -47,7 +48,7 @@ const supportedMaxFPS = [
{ value: '30', string: '30 frames per second' },
{ value: '50', string: '50 frames per second' },
{ value: '59.94', string: '59.94 frames per second' },
{ value: '60', string: '60 frames per secondsecond' },
{ value: '60', string: '60 frames per second' },
{ value: '120', string: '120 frames per second' },
];

Expand Down Expand Up @@ -565,7 +566,7 @@ export default function FfmpegSettingsPage() {
<Grid item sm={16} md={8}>
<TextField
id="video-bitrate"
label="Video Bitrate"
label="Video Bitrate (Kbps)"
value={videoBitrate}
onChange={handleVideoBitrate}
fullWidth
Expand All @@ -575,11 +576,23 @@ export default function FfmpegSettingsPage() {
<Grid item sm={16} md={8}>
<TextField
id="video-buffer-size"
label="Video Buffer Size"
label="Video Buffer Size (kb)"
value={videoBufferSize}
onChange={handleVideoBufferSize}
fullWidth
sx={{ my: 1 }}
helperText={
<>
Buffer size effects how frequently ffmpeg reconsiders the
output bitrate.{' '}
<MuiLink
target="_blank"
href="https://trac.ffmpeg.org/wiki/Limiting%20the%20output%20bitrate#Whatdoes-bufsizedo"
>
Read more
</MuiLink>
</>
}
/>
</Grid>
</Grid>
Expand Down Expand Up @@ -750,7 +763,7 @@ export default function FfmpegSettingsPage() {
<Grid item sm={16} md={8}>
<TextField
id="audio-bitrate"
label="Audio Bitrate"
label="Audio Bitrate (Kbps)"
value={audioBitrate}
onChange={handleAudioBitrate}
sx={{ my: 1 }}
Expand All @@ -760,7 +773,7 @@ export default function FfmpegSettingsPage() {
<Grid item sm={16} md={8}>
<TextField
id="audio-buffer-size"
label="Audio Buffer Size"
label="Audio Buffer Size (kb)"
value={audioBufferSize}
onChange={handleAudioBufferSize}
sx={{ my: 1 }}
Expand Down

0 comments on commit 6443d9e

Please sign in to comment.