feat(metadata): add audio-related system metadata fields

This commit is contained in:
yiling
2026-05-26 15:09:06 +08:00
parent bc566fb53a
commit 2a04c49b95
6 changed files with 87 additions and 2 deletions
@@ -50,6 +50,10 @@ describe('Transcode Activities', () => {
bitRate: 1000,
frameRate: 30,
hasAudio: true,
audioCodec: 'aac',
audioChannels: 2,
audioSampleRate: 48000,
audioBitDepth: 16,
mimeType: 'video/mp4',
})
@@ -62,6 +66,10 @@ describe('Transcode Activities', () => {
expect(transcodeService.getVideoInfo).toHaveBeenCalledWith('/tmp/v.mp4')
expect(result.duration).toBe(10)
expect(result.metadata?.originalWidth).toBe(1920)
expect(result.metadata?.audioCodec).toBe('aac')
expect(result.metadata?.audioChannels).toBe(2)
expect(result.metadata?.audioSampleRate).toBe(48000)
expect(result.metadata?.audioBitDepth).toBe(16)
})
it('should call getImageInfo for image assets', async () => {
+15 -2
View File
@@ -49,15 +49,28 @@ export async function getMediaInfoActivity(params: {
bitRate: info.bitRate,
frameRate: info.frameRate,
hasAudio: info.hasAudio,
audioCodec: info.audioCodec,
audioChannels: info.audioChannels,
audioSampleRate: info.audioSampleRate,
audioBitDepth: info.audioBitDepth,
format: {},
}
await metadataService.updateAssetMetadata(params.assetId, [
const metadataUpdates: { key: string; value: string | number }[] = [
{ key: 'resolution_width', value: info.originalWidth },
{ key: 'resolution_height', value: info.originalHeight },
{ key: 'duration', value: info.duration },
{ key: 'bitRate', value: info.bitRate / 1000 },
{ key: 'frame_rate', value: info.frameRate },
])
]
if (info.audioCodec) metadataUpdates.push({ key: 'audio_codec', value: info.audioCodec })
if (info.audioChannels !== undefined)
metadataUpdates.push({ key: 'audio_channels', value: info.audioChannels })
if (info.audioSampleRate !== undefined)
metadataUpdates.push({ key: 'audio_sample_rate', value: info.audioSampleRate })
if (info.audioBitDepth !== undefined)
metadataUpdates.push({ key: 'audio_bit_depth', value: info.audioBitDepth })
await metadataService.updateAssetMetadata(params.assetId, metadataUpdates)
} else if (isImage) {
const info = await transcodeService.getImageInfo(params.filePath)
mediaInfo.metadata = {
+8
View File
@@ -49,6 +49,10 @@ describe('TranscodeService', () => {
},
{
codec_type: 'audio',
codec_name: 'aac',
channels: 2,
sample_rate: '48000',
bits_per_raw_sample: '16',
},
],
})
@@ -66,6 +70,10 @@ describe('TranscodeService', () => {
expect(info.duration).toBe(10.5)
expect(info.frameRate).toBe(30)
expect(info.hasAudio).toBe(true)
expect(info.audioCodec).toBe('aac')
expect(info.audioChannels).toBe(2)
expect(info.audioSampleRate).toBe(48000)
expect(info.audioBitDepth).toBe(16)
expect(child_process.exec).toHaveBeenCalledWith(
expect.stringContaining('ffprobe'),
+12
View File
@@ -17,6 +17,10 @@ export interface MediaMetadata {
bitRate: number
frameRate: number
hasAudio: boolean
audioCodec?: string
audioChannels?: number
audioSampleRate?: number
audioBitDepth?: number
mimeType: string
}
@@ -64,6 +68,14 @@ export class TranscodeService {
bitRate: parseFloat(info.format.bit_rate),
frameRate,
hasAudio: !!audioStream,
audioCodec: audioStream?.codec_name,
audioChannels: audioStream?.channels,
audioSampleRate: audioStream?.sample_rate ? parseInt(audioStream.sample_rate) : undefined,
audioBitDepth: audioStream?.bits_per_raw_sample
? parseInt(audioStream.bits_per_raw_sample)
: audioStream?.bits_per_sample
? parseInt(audioStream.bits_per_sample)
: undefined,
mimeType: '',
}
}