Skip to content

Commit

Permalink
Only skip flag for mts videos
Browse files Browse the repository at this point in the history
  • Loading branch information
Lukasdotcom committed Nov 14, 2024
1 parent 1e651dc commit a2c9561
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 14 deletions.
7 changes: 6 additions & 1 deletion server/src/interfaces/media.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,12 @@ export interface ImageBuffer {
}

export interface VideoCodecSWConfig {
getCommand(target: TranscodeTarget, videoStream: VideoStreamInfo, audioStream: AudioStreamInfo): TranscodeCommand;
getCommand(
target: TranscodeTarget,
videoStream: VideoStreamInfo,
audioStream: AudioStreamInfo,
format?: VideoFormat,
): TranscodeCommand;
}

export interface VideoCodecHWConfig extends VideoCodecSWConfig {
Expand Down
6 changes: 3 additions & 3 deletions server/src/services/media.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ describe(MediaService.name, () => {
'/original/path.ext',
'upload/thumbs/user-id/as/se/asset-id-preview.jpeg',
expect.objectContaining({
inputOptions: ['-sws_flags accurate_rnd+full_chroma_int'],
inputOptions: ['-skip_frame nointra', '-sws_flags accurate_rnd+full_chroma_int'],
outputOptions: [
'-fps_mode vfr',
'-frames:v 1',
Expand Down Expand Up @@ -438,7 +438,7 @@ describe(MediaService.name, () => {
'/original/path.ext',
'upload/thumbs/user-id/as/se/asset-id-preview.jpeg',
expect.objectContaining({
inputOptions: ['-sws_flags accurate_rnd+full_chroma_int'],
inputOptions: ['-skip_frame nointra', '-sws_flags accurate_rnd+full_chroma_int'],
outputOptions: [
'-fps_mode vfr',
'-frames:v 1',
Expand Down Expand Up @@ -475,7 +475,7 @@ describe(MediaService.name, () => {
'/original/path.ext',
'upload/thumbs/user-id/as/se/asset-id-preview.jpeg',
expect.objectContaining({
inputOptions: ['-sws_flags accurate_rnd+full_chroma_int'],
inputOptions: ['-skip_frame nointra', '-sws_flags accurate_rnd+full_chroma_int'],
outputOptions: [
'-fps_mode vfr',
'-frames:v 1',
Expand Down
13 changes: 9 additions & 4 deletions server/src/services/media.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ export class MediaService extends BaseService {
const thumbnailPath = StorageCore.getImagePath(asset, AssetPathType.THUMBNAIL, image.thumbnail.format);
this.storageCore.ensureFolders(previewPath);

const { audioStreams, videoStreams } = await this.mediaRepository.probe(asset.originalPath);
const { format, audioStreams, videoStreams } = await this.mediaRepository.probe(asset.originalPath);
const mainVideoStream = this.getMainStream(videoStreams);
if (!mainVideoStream) {
throw new Error(`No video streams found for asset ${asset.id}`);
Expand All @@ -248,9 +248,14 @@ export class MediaService extends BaseService {

const previewConfig = ThumbnailConfig.create({ ...ffmpeg, targetResolution: image.preview.size.toString() });
const thumbnailConfig = ThumbnailConfig.create({ ...ffmpeg, targetResolution: image.thumbnail.size.toString() });

const previewOptions = previewConfig.getCommand(TranscodeTarget.VIDEO, mainVideoStream, mainAudioStream);
const thumbnailOptions = thumbnailConfig.getCommand(TranscodeTarget.VIDEO, mainVideoStream, mainAudioStream);
const previewOptions = previewConfig.getCommand(TranscodeTarget.VIDEO, mainVideoStream, mainAudioStream, format);
const thumbnailOptions = thumbnailConfig.getCommand(
TranscodeTarget.VIDEO,
mainVideoStream,
mainAudioStream,
format,
);
this.logger.error(format.formatName);
await this.mediaRepository.transcode(asset.originalPath, previewPath, previewOptions);
await this.mediaRepository.transcode(asset.originalPath, thumbnailPath, thumbnailOptions);

Expand Down
22 changes: 16 additions & 6 deletions server/src/utils/media.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { SystemConfigFFmpegDto } from 'src/dtos/system-config.dto';
import { CQMode, ToneMapping, TranscodeHWAccel, TranscodeTarget, VideoCodec } from 'src/enum';
import { CQMode, ToneMapping, TranscodeHWAccel, TranscodeTarget, VideoCodec, VideoContainer } from 'src/enum';

Check failure on line 2 in server/src/utils/media.ts

View workflow job for this annotation

GitHub Actions / Test & Lint Server

'VideoContainer' is defined but never used
import {
AudioStreamInfo,
BitrateDistribution,
TranscodeCommand,
VideoCodecHWConfig,
VideoCodecSWConfig,
VideoFormat,
VideoStreamInfo,
} from 'src/interfaces/media.interface';

Expand Down Expand Up @@ -77,9 +78,14 @@ export class BaseConfig implements VideoCodecSWConfig {
return handler;
}

getCommand(target: TranscodeTarget, videoStream: VideoStreamInfo, audioStream?: AudioStreamInfo) {
getCommand(
target: TranscodeTarget,
videoStream: VideoStreamInfo,
audioStream?: AudioStreamInfo,
format?: VideoFormat,
) {
const options = {
inputOptions: this.getBaseInputOptions(videoStream),
inputOptions: this.getBaseInputOptions(videoStream, format),
outputOptions: [...this.getBaseOutputOptions(target, videoStream, audioStream), '-v verbose'],
twoPass: this.eligibleForTwoPass(),
progress: { frameCount: videoStream.frameCount, percentInterval: 5 },
Expand All @@ -101,7 +107,7 @@ export class BaseConfig implements VideoCodecSWConfig {
}

// eslint-disable-next-line @typescript-eslint/no-unused-vars
getBaseInputOptions(videoStream: VideoStreamInfo): string[] {
getBaseInputOptions(videoStream: VideoStreamInfo, format?: VideoFormat): string[] {
return this.getInputThreadOptions();
}

Expand Down Expand Up @@ -377,8 +383,12 @@ export class ThumbnailConfig extends BaseConfig {
return new ThumbnailConfig(config);
}

getBaseInputOptions(): string[] {
return ['-sws_flags accurate_rnd+full_chroma_int'];
getBaseInputOptions(videoStream: VideoStreamInfo, format?: VideoFormat): string[] {
if (format?.formatName === 'mpegts') {

Check failure on line 387 in server/src/utils/media.ts

View workflow job for this annotation

GitHub Actions / Test & Lint Server

This `if` statement can be replaced by a ternary expression
return ['-sws_flags accurate_rnd+full_chroma_int'];
} else {
return ['-skip_frame nointra', '-sws_flags accurate_rnd+full_chroma_int'];
}
}

getBaseOutputOptions() {
Expand Down

0 comments on commit a2c9561

Please sign in to comment.