diff options
author | Chocobozzz <me@florianbigard.com> | 2023-05-05 10:53:04 +0200 |
---|---|---|
committer | Chocobozzz <chocobozzz@cpy.re> | 2023-05-09 08:57:34 +0200 |
commit | e7d8e2b245491c0a8e008fb570037506d729ff04 (patch) | |
tree | d850a7f82cc02946f2e87b306d0b281cef5eb73d /server/lib | |
parent | dd3f99434cc3cb7226d33ffcd888c91d0ce150a9 (diff) | |
download | PeerTube-e7d8e2b245491c0a8e008fb570037506d729ff04.tar.gz PeerTube-e7d8e2b245491c0a8e008fb570037506d729ff04.tar.zst PeerTube-e7d8e2b245491c0a8e008fb570037506d729ff04.zip |
Fix audio transcoding copy
Diffstat (limited to 'server/lib')
-rw-r--r-- | server/lib/transcoding/transcoding-quick-transcode.ts | 51 |
1 files changed, 1 insertions, 50 deletions
diff --git a/server/lib/transcoding/transcoding-quick-transcode.ts b/server/lib/transcoding/transcoding-quick-transcode.ts index b7f921890..53f12cd06 100644 --- a/server/lib/transcoding/transcoding-quick-transcode.ts +++ b/server/lib/transcoding/transcoding-quick-transcode.ts | |||
@@ -1,16 +1,6 @@ | |||
1 | import { FfprobeData } from 'fluent-ffmpeg' | 1 | import { FfprobeData } from 'fluent-ffmpeg' |
2 | import { CONFIG } from '@server/initializers/config' | 2 | import { CONFIG } from '@server/initializers/config' |
3 | import { VIDEO_TRANSCODING_FPS } from '@server/initializers/constants' | 3 | import { canDoQuickAudioTranscode, canDoQuickVideoTranscode, ffprobePromise } from '@shared/ffmpeg' |
4 | import { getMaxBitrate } from '@shared/core-utils' | ||
5 | import { | ||
6 | ffprobePromise, | ||
7 | getAudioStream, | ||
8 | getMaxAudioBitrate, | ||
9 | getVideoStream, | ||
10 | getVideoStreamBitrate, | ||
11 | getVideoStreamDimensionsInfo, | ||
12 | getVideoStreamFPS | ||
13 | } from '@shared/ffmpeg' | ||
14 | 4 | ||
15 | export async function canDoQuickTranscode (path: string, existingProbe?: FfprobeData): Promise<boolean> { | 5 | export async function canDoQuickTranscode (path: string, existingProbe?: FfprobeData): Promise<boolean> { |
16 | if (CONFIG.TRANSCODING.PROFILE !== 'default') return false | 6 | if (CONFIG.TRANSCODING.PROFILE !== 'default') return false |
@@ -20,42 +10,3 @@ export async function canDoQuickTranscode (path: string, existingProbe?: Ffprobe | |||
20 | return await canDoQuickVideoTranscode(path, probe) && | 10 | return await canDoQuickVideoTranscode(path, probe) && |
21 | await canDoQuickAudioTranscode(path, probe) | 11 | await canDoQuickAudioTranscode(path, probe) |
22 | } | 12 | } |
23 | |||
24 | export async function canDoQuickAudioTranscode (path: string, probe?: FfprobeData): Promise<boolean> { | ||
25 | const parsedAudio = await getAudioStream(path, probe) | ||
26 | |||
27 | if (!parsedAudio.audioStream) return true | ||
28 | |||
29 | if (parsedAudio.audioStream['codec_name'] !== 'aac') return false | ||
30 | |||
31 | const audioBitrate = parsedAudio.bitrate | ||
32 | if (!audioBitrate) return false | ||
33 | |||
34 | const maxAudioBitrate = getMaxAudioBitrate('aac', audioBitrate) | ||
35 | if (maxAudioBitrate !== -1 && audioBitrate > maxAudioBitrate) return false | ||
36 | |||
37 | const channelLayout = parsedAudio.audioStream['channel_layout'] | ||
38 | // Causes playback issues with Chrome | ||
39 | if (!channelLayout || channelLayout === 'unknown' || channelLayout === 'quad') return false | ||
40 | |||
41 | return true | ||
42 | } | ||
43 | |||
44 | export async function canDoQuickVideoTranscode (path: string, probe?: FfprobeData): Promise<boolean> { | ||
45 | const videoStream = await getVideoStream(path, probe) | ||
46 | const fps = await getVideoStreamFPS(path, probe) | ||
47 | const bitRate = await getVideoStreamBitrate(path, probe) | ||
48 | const resolutionData = await getVideoStreamDimensionsInfo(path, probe) | ||
49 | |||
50 | // If ffprobe did not manage to guess the bitrate | ||
51 | if (!bitRate) return false | ||
52 | |||
53 | // check video params | ||
54 | if (!videoStream) return false | ||
55 | if (videoStream['codec_name'] !== 'h264') return false | ||
56 | if (videoStream['pix_fmt'] !== 'yuv420p') return false | ||
57 | if (fps < VIDEO_TRANSCODING_FPS.MIN || fps > VIDEO_TRANSCODING_FPS.MAX) return false | ||
58 | if (bitRate > getMaxBitrate({ ...resolutionData, fps })) return false | ||
59 | |||
60 | return true | ||
61 | } | ||