Skip to content

Commit

Permalink
fix: Still images being detected as audio #68
Browse files Browse the repository at this point in the history
  • Loading branch information
Julusian committed Dec 6, 2023
1 parent 1aab992 commit 03f1de9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/__tests__/ffmpeg.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ function runForFFmpegRelease(ffprobePath: string, ffmpegPath: string) {
},
}

it('png', async () => {
test('png', async () => {
const doc = createBareDoc('grey.png')
await generateInfo(defaultConfig, doc)
expect(doc.cinf).toBe('"GREY" STILL 45678 20231206123456 0 0/1\r\n')
Expand Down
15 changes: 12 additions & 3 deletions src/ffmpeg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,16 +91,25 @@ type Timebase = [number, number]

function generateCinf(config: Record<string, any>, doc: MediaDocument, json: any) {
const dur = parseFloat(json.format.duration) || 1 / 24
const stillLimit = 0.1

let audioTb: Timebase | null = null
let videoTb: Timebase | null = null
let stillTb: Timebase | null = null
let audioDur = 0

for (const stream of json.streams) {
if (stream.codec_type === 'audio') {
if (!audioTb) audioTb = (stream.time_base || '1/25').split('/')
if (!audioTb) {
audioTb = (stream.time_base || '1/25').split('/')
audioDur = parseFloat(stream.duration)
}
} else if (stream.codec_type === 'video') {
if (stream.codec_time_base === '0/1') {
if (
Number(stream.duration ?? '0') < stillLimit ||
stream.disposition.attached_pic === 1 ||
stream.codec_name === 'gif'
) {
if (!stillTb) stillTb = [0, 1]
} else {
if (!videoTb) {
Expand All @@ -120,7 +129,7 @@ function generateCinf(config: Record<string, any>, doc: MediaDocument, json: any
if (videoTb) {
type = ' MOVIE '
tb = videoTb
} else if (stillTb && !audioTb) {
} else if ((stillTb && !audioTb) || (stillTb && audioTb && audioDur < stillLimit)) {
type = ' STILL '
tb = stillTb
} else {
Expand Down

0 comments on commit 03f1de9

Please sign in to comment.