refactor(server): modularize getFfmpegOptions (#3138)

* refactored `getFfmpegOptions`

refactor transcoding, make separate service

* fixed enum casing

* use `Logger` instead of `console.log`

* review suggestions

* use enum for `getHandler`

* fixed formatting

* Update server/src/domain/media/media.util.ts

Co-authored-by: Jason Rasmussen <jrasm91@gmail.com>

* Update server/src/domain/media/media.util.ts

Co-authored-by: Jason Rasmussen <jrasm91@gmail.com>

* More specific imports, renamed codec classes

* simplified code

* removed unused import

* added tests

* added base implementation for bitrate and threads

---------

Co-authored-by: Jason Rasmussen <jrasm91@gmail.com>
This commit is contained in:
Mert
2023-07-08 22:43:11 -04:00
committed by GitHub
parent 27018e4ab6
commit 8349a28ed8
33 changed files with 1131 additions and 345 deletions

View File

@@ -746,6 +746,21 @@ export const AssetTypeEnum = {
export type AssetTypeEnum = typeof AssetTypeEnum[keyof typeof AssetTypeEnum];
/**
*
* @export
* @enum {string}
*/
export const AudioCodec = {
Mp3: 'mp3',
Aac: 'aac',
Opus: 'opus'
} as const;
export type AudioCodec = typeof AudioCodec[keyof typeof AudioCodec];
/**
*
* @export
@@ -2411,24 +2426,30 @@ export interface SystemConfigFFmpegDto {
* @memberof SystemConfigFFmpegDto
*/
'threads': number;
/**
*
* @type {VideoCodec}
* @memberof SystemConfigFFmpegDto
*/
'targetVideoCodec': VideoCodec;
/**
*
* @type {AudioCodec}
* @memberof SystemConfigFFmpegDto
*/
'targetAudioCodec': AudioCodec;
/**
*
* @type {TranscodePolicy}
* @memberof SystemConfigFFmpegDto
*/
'transcode': TranscodePolicy;
/**
*
* @type {string}
* @memberof SystemConfigFFmpegDto
*/
'preset': string;
/**
*
* @type {string}
* @memberof SystemConfigFFmpegDto
*/
'targetVideoCodec': string;
/**
*
* @type {string}
* @memberof SystemConfigFFmpegDto
*/
'targetAudioCodec': string;
/**
*
* @type {string}
@@ -2447,22 +2468,8 @@ export interface SystemConfigFFmpegDto {
* @memberof SystemConfigFFmpegDto
*/
'twoPass': boolean;
/**
*
* @type {string}
* @memberof SystemConfigFFmpegDto
*/
'transcode': SystemConfigFFmpegDtoTranscodeEnum;
}
export const SystemConfigFFmpegDtoTranscodeEnum = {
All: 'all',
Optimal: 'optimal',
Required: 'required',
Disabled: 'disabled'
} as const;
export type SystemConfigFFmpegDtoTranscodeEnum = typeof SystemConfigFFmpegDtoTranscodeEnum[keyof typeof SystemConfigFFmpegDtoTranscodeEnum];
/**
*
@@ -2749,6 +2756,22 @@ export const TimeGroupEnum = {
export type TimeGroupEnum = typeof TimeGroupEnum[keyof typeof TimeGroupEnum];
/**
*
* @export
* @enum {string}
*/
export const TranscodePolicy = {
All: 'all',
Optimal: 'optimal',
Required: 'required',
Disabled: 'disabled'
} as const;
export type TranscodePolicy = typeof TranscodePolicy[keyof typeof TranscodePolicy];
/**
*
* @export
@@ -3027,6 +3050,21 @@ export interface ValidateAccessTokenResponseDto {
*/
'authStatus': boolean;
}
/**
*
* @export
* @enum {string}
*/
export const VideoCodec = {
H264: 'h264',
Hevc: 'hevc',
Vp9: 'vp9'
} as const;
export type VideoCodec = typeof VideoCodec[keyof typeof VideoCodec];
/**
* APIKeyApi - axios parameter creator

View File

@@ -3,7 +3,7 @@
notificationController,
NotificationType,
} from '$lib/components/shared-components/notification/notification';
import { api, SystemConfigFFmpegDto, SystemConfigFFmpegDtoTranscodeEnum } from '@api';
import { api, AudioCodec, SystemConfigFFmpegDto, TranscodePolicy, VideoCodec } from '@api';
import SettingButtonsRow from '../setting-buttons-row.svelte';
import SettingInputField, { SettingInputFieldType } from '../setting-input-field.svelte';
import SettingSelect from '../setting-select.svelte';
@@ -113,9 +113,9 @@
desc="Opus is the highest quality option, but has lower compatibility with old devices or software."
bind:value={ffmpegConfig.targetAudioCodec}
options={[
{ value: 'aac', text: 'aac' },
{ value: 'mp3', text: 'mp3' },
{ value: 'opus', text: 'opus' },
{ value: AudioCodec.Aac, text: 'aac' },
{ value: AudioCodec.Mp3, text: 'mp3' },
{ value: AudioCodec.Opus, text: 'opus' },
]}
name="acodec"
isEdited={!(ffmpegConfig.targetAudioCodec == savedConfig.targetAudioCodec)}
@@ -126,9 +126,9 @@
desc="VP9 has high efficiency and web compatibility, but takes longer to transcode. HEVC performs similarly, but has lower web compatibility. H.264 is widely compatible and quick to transcode, but produces much larger files."
bind:value={ffmpegConfig.targetVideoCodec}
options={[
{ value: 'h264', text: 'h264' },
{ value: 'hevc', text: 'hevc' },
{ value: 'vp9', text: 'vp9' },
{ value: VideoCodec.H264, text: 'h264' },
{ value: VideoCodec.Hevc, text: 'hevc' },
{ value: VideoCodec.Vp9, text: 'vp9' },
]}
name="vcodec"
isEdited={!(ffmpegConfig.targetVideoCodec == savedConfig.targetVideoCodec)}
@@ -167,22 +167,22 @@
/>
<SettingSelect
label="TRANSCODE"
label="TRANSCODE POLICY"
desc="Policy for when a video should be transcoded."
bind:value={ffmpegConfig.transcode}
name="transcode"
options={[
{ value: SystemConfigFFmpegDtoTranscodeEnum.All, text: 'All videos' },
{ value: TranscodePolicy.All, text: 'All videos' },
{
value: SystemConfigFFmpegDtoTranscodeEnum.Optimal,
value: TranscodePolicy.Optimal,
text: 'Videos higher than target resolution or not in the desired format',
},
{
value: SystemConfigFFmpegDtoTranscodeEnum.Required,
value: TranscodePolicy.Required,
text: 'Only videos not in the desired format',
},
{
value: SystemConfigFFmpegDtoTranscodeEnum.Disabled,
value: TranscodePolicy.Disabled,
text: "Don't transcode any videos, may break playback on some clients",
},
]}