mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-11-30 21:04:59 +00:00
feat(metadata): add video_codec field and verbose codec name resolution
This commit is contained in:
@@ -110,6 +110,7 @@ declare global {
|
|||||||
duration: number
|
duration: number
|
||||||
bitRate: number
|
bitRate: number
|
||||||
frameRate: number
|
frameRate: number
|
||||||
|
videoCodec?: string
|
||||||
audioCodec?: string
|
audioCodec?: string
|
||||||
audioChannels?: number
|
audioChannels?: number
|
||||||
audioSampleRate?: number
|
audioSampleRate?: number
|
||||||
|
|||||||
@@ -152,6 +152,16 @@ export const systemFields: Prisma.MetadataFieldCreateInput[] = [
|
|||||||
number: { scale: 0 },
|
number: { scale: 0 },
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
key: 'video_codec',
|
||||||
|
scope: 'SYSTEM',
|
||||||
|
readOnly: true,
|
||||||
|
config: {
|
||||||
|
name: 'Video Codec',
|
||||||
|
type: 'text',
|
||||||
|
text: {},
|
||||||
|
},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
key: 'format',
|
key: 'format',
|
||||||
scope: 'SYSTEM',
|
scope: 'SYSTEM',
|
||||||
|
|||||||
@@ -50,7 +50,8 @@ describe('Transcode Activities', () => {
|
|||||||
bitRate: 1000,
|
bitRate: 1000,
|
||||||
frameRate: 30,
|
frameRate: 30,
|
||||||
hasAudio: true,
|
hasAudio: true,
|
||||||
audioCodec: 'aac',
|
videoCodec: 'Advanced Video Coding',
|
||||||
|
audioCodec: 'MPEG-4 Audio',
|
||||||
audioChannels: 2,
|
audioChannels: 2,
|
||||||
audioSampleRate: 48000,
|
audioSampleRate: 48000,
|
||||||
audioBitDepth: 16,
|
audioBitDepth: 16,
|
||||||
@@ -66,7 +67,8 @@ describe('Transcode Activities', () => {
|
|||||||
expect(transcodeService.getVideoInfo).toHaveBeenCalledWith('/tmp/v.mp4')
|
expect(transcodeService.getVideoInfo).toHaveBeenCalledWith('/tmp/v.mp4')
|
||||||
expect(result.duration).toBe(10)
|
expect(result.duration).toBe(10)
|
||||||
expect(result.metadata?.originalWidth).toBe(1920)
|
expect(result.metadata?.originalWidth).toBe(1920)
|
||||||
expect(result.metadata?.audioCodec).toBe('aac')
|
expect(result.metadata?.videoCodec).toBe('Advanced Video Coding')
|
||||||
|
expect(result.metadata?.audioCodec).toBe('MPEG-4 Audio')
|
||||||
expect(result.metadata?.audioChannels).toBe(2)
|
expect(result.metadata?.audioChannels).toBe(2)
|
||||||
expect(result.metadata?.audioSampleRate).toBe(48000)
|
expect(result.metadata?.audioSampleRate).toBe(48000)
|
||||||
expect(result.metadata?.audioBitDepth).toBe(16)
|
expect(result.metadata?.audioBitDepth).toBe(16)
|
||||||
|
|||||||
@@ -49,6 +49,7 @@ export async function getMediaInfoActivity(params: {
|
|||||||
bitRate: info.bitRate,
|
bitRate: info.bitRate,
|
||||||
frameRate: info.frameRate,
|
frameRate: info.frameRate,
|
||||||
hasAudio: info.hasAudio,
|
hasAudio: info.hasAudio,
|
||||||
|
videoCodec: info.videoCodec,
|
||||||
audioCodec: info.audioCodec,
|
audioCodec: info.audioCodec,
|
||||||
audioChannels: info.audioChannels,
|
audioChannels: info.audioChannels,
|
||||||
audioSampleRate: info.audioSampleRate,
|
audioSampleRate: info.audioSampleRate,
|
||||||
@@ -62,6 +63,7 @@ export async function getMediaInfoActivity(params: {
|
|||||||
{ key: 'bitRate', value: info.bitRate / 1000 },
|
{ key: 'bitRate', value: info.bitRate / 1000 },
|
||||||
{ key: 'frame_rate', value: info.frameRate },
|
{ key: 'frame_rate', value: info.frameRate },
|
||||||
]
|
]
|
||||||
|
if (info.videoCodec) metadataUpdates.push({ key: 'video_codec', value: info.videoCodec })
|
||||||
if (info.audioCodec) metadataUpdates.push({ key: 'audio_codec', value: info.audioCodec })
|
if (info.audioCodec) metadataUpdates.push({ key: 'audio_codec', value: info.audioCodec })
|
||||||
if (info.audioChannels !== undefined)
|
if (info.audioChannels !== undefined)
|
||||||
metadataUpdates.push({ key: 'audio_channels', value: info.audioChannels })
|
metadataUpdates.push({ key: 'audio_channels', value: info.audioChannels })
|
||||||
|
|||||||
@@ -43,9 +43,13 @@ describe('TranscodeService', () => {
|
|||||||
streams: [
|
streams: [
|
||||||
{
|
{
|
||||||
codec_type: 'video',
|
codec_type: 'video',
|
||||||
|
codec_name: 'h264',
|
||||||
width: 1920,
|
width: 1920,
|
||||||
height: 1080,
|
height: 1080,
|
||||||
r_frame_rate: '30/1',
|
r_frame_rate: '30/1',
|
||||||
|
tags: {
|
||||||
|
mime_codec_string: 'avc1.4d401e',
|
||||||
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
codec_type: 'audio',
|
codec_type: 'audio',
|
||||||
@@ -53,6 +57,9 @@ describe('TranscodeService', () => {
|
|||||||
channels: 2,
|
channels: 2,
|
||||||
sample_rate: '48000',
|
sample_rate: '48000',
|
||||||
bits_per_raw_sample: '16',
|
bits_per_raw_sample: '16',
|
||||||
|
tags: {
|
||||||
|
mime_codec_string: 'mp4a.40.2',
|
||||||
|
},
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
})
|
})
|
||||||
@@ -70,7 +77,8 @@ describe('TranscodeService', () => {
|
|||||||
expect(info.duration).toBe(10.5)
|
expect(info.duration).toBe(10.5)
|
||||||
expect(info.frameRate).toBe(30)
|
expect(info.frameRate).toBe(30)
|
||||||
expect(info.hasAudio).toBe(true)
|
expect(info.hasAudio).toBe(true)
|
||||||
expect(info.audioCodec).toBe('aac')
|
expect(info.videoCodec).toBe('Advanced Video Coding')
|
||||||
|
expect(info.audioCodec).toBe('MPEG-4 Audio')
|
||||||
expect(info.audioChannels).toBe(2)
|
expect(info.audioChannels).toBe(2)
|
||||||
expect(info.audioSampleRate).toBe(48000)
|
expect(info.audioSampleRate).toBe(48000)
|
||||||
expect(info.audioBitDepth).toBe(16)
|
expect(info.audioBitDepth).toBe(16)
|
||||||
|
|||||||
+136
-1
@@ -10,6 +10,122 @@ import '@/prisma-json-types'
|
|||||||
|
|
||||||
const execAsync = promisify(exec)
|
const execAsync = promisify(exec)
|
||||||
|
|
||||||
|
const dataFormatNames: Record<string, string> = {
|
||||||
|
// additional codecs
|
||||||
|
apch: 'Apple ProRes 422 High Quality',
|
||||||
|
apcn: 'Apple ProRes 422 Standard Definition',
|
||||||
|
apcs: 'Apple ProRes 422 LT',
|
||||||
|
apco: 'Apple ProRes 422 Proxy',
|
||||||
|
ap4h: 'Apple ProRes 4444',
|
||||||
|
jpeg: 'JPEG Image',
|
||||||
|
|
||||||
|
// codecs from https://mp4ra.org/
|
||||||
|
'3gvo': '3GPP Video Orientation',
|
||||||
|
a3d1: 'Multiview Video Coding',
|
||||||
|
a3d2: 'Multiview Video Coding',
|
||||||
|
a3d3: 'Multiview Video Coding',
|
||||||
|
a3d4: 'Multiview Video Coding',
|
||||||
|
a3ds: 'Auro-Cx 3D audio',
|
||||||
|
'ac-3': 'AC-3 audio',
|
||||||
|
'ac-4': 'AC-4 audio',
|
||||||
|
alac: 'Apple lossless audio codec',
|
||||||
|
alaw: 'a-Law',
|
||||||
|
av01: 'AV1 video',
|
||||||
|
avc1: 'Advanced Video Coding',
|
||||||
|
avc2: 'Advanced Video Coding',
|
||||||
|
avc3: 'Advanced Video Coding',
|
||||||
|
avc4: 'Advanced Video Coding',
|
||||||
|
avcp: 'Advanced Video Coding Parameters',
|
||||||
|
dra1: 'DRA Audio',
|
||||||
|
drac: 'Dirac Video Coder',
|
||||||
|
'dts-': 'Dependent base layer for DTS layered audio',
|
||||||
|
'dts+': 'Enhancement layer for DTS layered audio',
|
||||||
|
dtsc: 'DTS Coherent Acoustics audio',
|
||||||
|
dtse: 'DTS Express low bit rate audio, also known as DTS LBR',
|
||||||
|
dtsh: 'DTS-HD High Resolution Audio',
|
||||||
|
dtsl: 'DTS-HD Master Audio',
|
||||||
|
dtsx: 'DTS:X',
|
||||||
|
dvav: 'AVC-based “Dolby Vision”',
|
||||||
|
dvhe: 'HEVC-based “Dolby Vision”',
|
||||||
|
'ec-3': 'Enhanced AC-3 audio',
|
||||||
|
enca: 'Encrypted/Protected audio',
|
||||||
|
encf: 'Encrypted/Protected font',
|
||||||
|
encm: 'Encrypted/Protected metadata stream',
|
||||||
|
encs: 'Encrypted Systems stream',
|
||||||
|
enct: 'Encrypted Text',
|
||||||
|
encv: 'Encrypted/protected video',
|
||||||
|
fdp: 'File delivery hints',
|
||||||
|
fLaC: 'Fres Lossless Audio Codec',
|
||||||
|
g719: 'ITU-T Recommendation G.719 (2008)',
|
||||||
|
g726: 'ITU-T Recommendation G.726 (1990)',
|
||||||
|
hev1: 'High Efficiency Video Coding',
|
||||||
|
hvc1: 'High Efficiency Video Coding',
|
||||||
|
hvt1: 'High Efficiency Video Coding',
|
||||||
|
ixse: 'DVB Track Level Index Track',
|
||||||
|
lhe1: 'Layered High Efficiency Video Coding',
|
||||||
|
lht1: 'Layered High Efficiency Video Coding',
|
||||||
|
lhv1: 'Layered High Efficiency Video Coding',
|
||||||
|
m2ts: 'MPEG-2 transport stream for DMB',
|
||||||
|
m4ae: 'MPEG-4 Audio Enhancement MP4v1/2',
|
||||||
|
mett: 'Text timed metadata that is not XML',
|
||||||
|
metx: 'XML timed metadata',
|
||||||
|
mha1: 'MPEG-H Audio (single stream, uncapsulated)',
|
||||||
|
mha2: 'MPEG-H Audio (multi-stream, unencapsulated)',
|
||||||
|
mhm1: 'MPEG-H Audio (single stream, MHAS encapsulated)',
|
||||||
|
mhm2: 'MPEG-H Audio (multi-stream, MHAS encapsulated)',
|
||||||
|
mjp2: 'Motion JPEG 2000',
|
||||||
|
mlix: 'DVB Movie level index track',
|
||||||
|
mlpa: 'MLP Audio',
|
||||||
|
mp4a: 'MPEG-4 Audio',
|
||||||
|
mp4s: 'MPEG-4 Systems',
|
||||||
|
mp4v: 'MPEG-4 Visual',
|
||||||
|
mvc1: 'Multiview coding',
|
||||||
|
mvc2: 'Multiview coding',
|
||||||
|
mvc3: 'Multiview coding',
|
||||||
|
mvc4: 'Multiview coding',
|
||||||
|
mvd1: 'Multiview coding',
|
||||||
|
mvd2: 'Multiview coding',
|
||||||
|
mvd3: 'Multiview coding',
|
||||||
|
mvd4: 'Multiview coding',
|
||||||
|
oksd: 'OMA Keys',
|
||||||
|
// eslint-disable-next-line @typescript-eslint/naming-convention
|
||||||
|
Opus: 'Opus audio coding',
|
||||||
|
pm2t: 'Protected MPEG-2 Transport',
|
||||||
|
prtp: 'Protected RTP Reception',
|
||||||
|
raw: 'Uncompressed audio',
|
||||||
|
resv: 'Restricted Video',
|
||||||
|
rm2t: 'MPEG-2 Transport Reception',
|
||||||
|
rrtp: 'RTP reception',
|
||||||
|
rsrp: 'SRTP Reception',
|
||||||
|
rtmd: 'Real Time Metadata Sample Entry(XAVC Format)',
|
||||||
|
rtp: 'RTP Hints',
|
||||||
|
s263: 'ITU H.263 video (3GPP format)',
|
||||||
|
samr: 'Narrowband AMR voice',
|
||||||
|
sawb: 'Wideband AMR voice',
|
||||||
|
sawp: 'Extended AMR-WB (AMR-WB+)',
|
||||||
|
sevc: 'EVRC Voice',
|
||||||
|
sm2t: 'MPEG-2 Transport Server',
|
||||||
|
sqcp: '13K Voice',
|
||||||
|
srtp: 'SRTP Hints',
|
||||||
|
ssmv: 'SMV Voice',
|
||||||
|
STGS: 'Subtitle Sample Entry (HMMP)',
|
||||||
|
stpp: 'Subtitles (Timed Text)',
|
||||||
|
svc1: 'Scalable Video Coding',
|
||||||
|
svc2: 'Scalable Video Coding',
|
||||||
|
svcM: 'SVC Metadata',
|
||||||
|
tc64: '64 bit timecode samples',
|
||||||
|
tmcd: '32 bit timecode samples',
|
||||||
|
twos: 'Uncompressed 16-bit audio',
|
||||||
|
tx3g: 'Timed Text stream',
|
||||||
|
ulaw: 'Samples have been compressed using uLaw 2:1.',
|
||||||
|
unid: 'Dynamic Range Control (DRC) data',
|
||||||
|
urim: 'Binary timed metadata identified by URI',
|
||||||
|
'vc-1': 'SMPTE VC-1',
|
||||||
|
vp08: 'VP8 video',
|
||||||
|
vp09: 'VP9 video',
|
||||||
|
wvtt: 'WebVTT',
|
||||||
|
}
|
||||||
|
|
||||||
export interface MediaMetadata {
|
export interface MediaMetadata {
|
||||||
originalWidth: number
|
originalWidth: number
|
||||||
originalHeight: number
|
originalHeight: number
|
||||||
@@ -17,6 +133,7 @@ export interface MediaMetadata {
|
|||||||
bitRate: number
|
bitRate: number
|
||||||
frameRate: number
|
frameRate: number
|
||||||
hasAudio: boolean
|
hasAudio: boolean
|
||||||
|
videoCodec?: string
|
||||||
audioCodec?: string
|
audioCodec?: string
|
||||||
audioChannels?: number
|
audioChannels?: number
|
||||||
audioSampleRate?: number
|
audioSampleRate?: number
|
||||||
@@ -44,6 +161,23 @@ export interface ExtractVideoFramesParams {
|
|||||||
export class TranscodeService {
|
export class TranscodeService {
|
||||||
constructor(private readonly prismaClient: typeof prisma = prisma) {}
|
constructor(private readonly prismaClient: typeof prisma = prisma) {}
|
||||||
|
|
||||||
|
private resolveCodecName(stream: {
|
||||||
|
/* eslint-disable @typescript-eslint/naming-convention */
|
||||||
|
codec_name?: string
|
||||||
|
mime_codec_string?: string
|
||||||
|
tags?: { mime_codec_string?: string }
|
||||||
|
/* eslint-enable @typescript-eslint/naming-convention */
|
||||||
|
}): string | undefined {
|
||||||
|
const mimeCodec = stream.mime_codec_string || stream.tags?.mime_codec_string
|
||||||
|
if (mimeCodec && typeof mimeCodec === 'string') {
|
||||||
|
const shortCodec = mimeCodec.split('.')[0]
|
||||||
|
if (dataFormatNames[shortCodec]) {
|
||||||
|
return dataFormatNames[shortCodec]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return stream.codec_name
|
||||||
|
}
|
||||||
|
|
||||||
async getVideoInfo(inputFile: string): Promise<MediaMetadata> {
|
async getVideoInfo(inputFile: string): Promise<MediaMetadata> {
|
||||||
const { stdout } = await execAsync(
|
const { stdout } = await execAsync(
|
||||||
`ffprobe -v quiet -print_format json -show_format -show_streams "${inputFile}"`,
|
`ffprobe -v quiet -print_format json -show_format -show_streams "${inputFile}"`,
|
||||||
@@ -68,7 +202,8 @@ export class TranscodeService {
|
|||||||
bitRate: parseFloat(info.format.bit_rate),
|
bitRate: parseFloat(info.format.bit_rate),
|
||||||
frameRate,
|
frameRate,
|
||||||
hasAudio: !!audioStream,
|
hasAudio: !!audioStream,
|
||||||
audioCodec: audioStream?.codec_name,
|
videoCodec: this.resolveCodecName(videoStream),
|
||||||
|
audioCodec: audioStream ? this.resolveCodecName(audioStream) : undefined,
|
||||||
audioChannels: audioStream?.channels,
|
audioChannels: audioStream?.channels,
|
||||||
audioSampleRate: audioStream?.sample_rate ? parseInt(audioStream.sample_rate) : undefined,
|
audioSampleRate: audioStream?.sample_rate ? parseInt(audioStream.sample_rate) : undefined,
|
||||||
audioBitDepth: audioStream?.bits_per_raw_sample
|
audioBitDepth: audioStream?.bits_per_raw_sample
|
||||||
|
|||||||
Reference in New Issue
Block a user