import { ffprobe, FfprobeData } from 'fluent-ffmpeg'
-import { VideoFileMetadata } from '@shared/models/videos'
+import { forceNumber } from '@shared/core-utils'
+import { VideoFileMetadata, VideoResolution } from '@shared/models/videos'
/**
*
// Audio
// ---------------------------------------------------------------------------
+const imageCodecs = new Set([
+ 'ansi', 'apng', 'bintext', 'bmp', 'brender_pix', 'dpx', 'exr', 'fits', 'gem', 'gif', 'jpeg2000', 'jpgls', 'mjpeg', 'mjpegb', 'msp2',
+ 'pam', 'pbm', 'pcx', 'pfm', 'pgm', 'pgmyuv', 'pgx', 'photocd', 'pictor', 'png', 'ppm', 'psd', 'sgi', 'sunrast', 'svg', 'targa', 'tiff',
+ 'txd', 'webp', 'xbin', 'xbm', 'xface', 'xpm', 'xwd'
+])
+
async function isAudioFile (path: string, existingProbe?: FfprobeData) {
const videoStream = await getVideoStream(path, existingProbe)
+ if (!videoStream) return true
+
+ if (imageCodecs.has(videoStream.codec_name)) return true
- return !videoStream
+ return false
}
async function hasAudioStream (path: string, existingProbe?: FfprobeData) {
return {
absolutePath: data.format.filename,
audioStream,
- bitrate: parseInt(audioStream['bit_rate'] + '', 10)
+ bitrate: forceNumber(audioStream['bit_rate'])
}
}
}
async function getVideoStreamDimensionsInfo (path: string, existingProbe?: FfprobeData) {
const videoStream = await getVideoStream(path, existingProbe)
- if (!videoStream) return undefined
+ if (!videoStream) {
+ return {
+ width: 0,
+ height: 0,
+ ratio: 0,
+ resolution: VideoResolution.H_NOVIDEO,
+ isPortraitMode: false
+ }
+ }
return {
width: videoStream.width,