From f7047160a16268828c592dede173cc299f07081a Mon Sep 17 00:00:00 2001 From: Mikael Finstad Date: Fri, 3 Feb 2023 15:47:20 +0800 Subject: [PATCH] workaround ffmpeg dv bug closes #1450 --- src/util/streams.js | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/util/streams.js b/src/util/streams.js index bfb6a85b..dbcd879d 100644 --- a/src/util/streams.js +++ b/src/util/streams.js @@ -111,8 +111,11 @@ export const isMov = (format) => ['ismv', 'ipod', 'mp4', 'mov'].includes(format) function getPerStreamFlags({ stream, outputIndex, outFormat, manuallyCopyDisposition = false, getVideoArgs = () => {} }) { let args = []; + function addArgs(...newArgs) { + args.push(...newArgs); + } function addCodecArgs(codec) { - args = [...args, `-c:${outputIndex}`, codec]; + addArgs(`-c:${outputIndex}`, codec); } if (stream.codec_type === 'subtitle') { @@ -139,6 +142,12 @@ function getPerStreamFlags({ stream, outputIndex, outFormat, manuallyCopyDisposi // ffmpeg cannot encode pcm_bluray if (outFormat !== 'mpegts' && stream.codec_name === 'pcm_bluray') { addCodecArgs('pcm_s24le'); + } else if (outFormat === 'dv' && stream.codec_name === 'pcm_s16le' && stream.sample_rate !== '48000') { + // DV seems to require 48kHz output + // https://trac.ffmpeg.org/ticket/8352 + // I think DV format only supports PCM_S16LE https://github.com/FFmpeg/FFmpeg/blob/b92028346c35dad837dd1160930435d88bd838b5/libavformat/dvenc.c#L450 + addCodecArgs('pcm_s16le'); + addArgs(`-ar:${outputIndex}`, '48000'); // maybe technically not lossless? } else { addCodecArgs('copy'); } @@ -152,7 +161,7 @@ function getPerStreamFlags({ stream, outputIndex, outFormat, manuallyCopyDisposi if (isMov(outFormat)) { if (['0x0000', '0x31637668'].includes(stream.codec_tag) && stream.codec_name === 'hevc') { - args = [...args, `-tag:${outputIndex}`, 'hvc1']; + addArgs(`-tag:${outputIndex}`, 'hvc1'); } } } else { // other stream types @@ -163,7 +172,7 @@ function getPerStreamFlags({ stream, outputIndex, outFormat, manuallyCopyDisposi if (manuallyCopyDisposition && stream.disposition != null) { const activeDisposition = getActiveDisposition(stream.disposition); if (activeDisposition != null) { - args = [...args, `-disposition:${outputIndex}`, String(activeDisposition)]; + addArgs(`-disposition:${outputIndex}`, String(activeDisposition)); } }