The swiss army knife of lossless video/audio editing
auto-convert mov_text to srt
Mikael Finstadd4cf3aac2307
diff --git a/src/util/streams.js b/src/util/streams.jsindex 4bc7cd9f..9c6b0682 100644--- a/src/util/streams.js+++ b/src/util/streams.js@@ -22,11 +22,27 @@ function getPerStreamQuirksFlags({ stream, outputIndex, outFormat, manuallyCopyD// mp4/mov only supports mov_text, so convert it https://stackoverflow.com/a/17584272/6519037// https://github.com/mifi/lossless-cut/issues/418- if (stream.codec_type === 'subtitle') {+ if (stream.codec_type === 'subtitle' && stream.codec_name !== 'mov_text') {args = [...args, `-c:${outputIndex}`, 'mov_text'];}}+ if (outFormat === 'matroska') {+ // matroska doesn't support mov_text, so convert it to SRT (popular codec)+ // https://github.com/mifi/lossless-cut/issues/418+ // https://www.reddit.com/r/PleX/comments/bcfvev/can_someone_eli5_subtitles/+ if (stream.codec_type === 'subtitle' && stream.codec_name === 'mov_text') {+ args = [...args, `-c:${outputIndex}`, 'srt'];+ }+ }++ if (outFormat === 'webm') {+ // Only WebVTT subtitles are supported for WebM.+ if (stream.codec_type === 'subtitle' && stream.codec_name === 'mov_text') {+ args = [...args, `-c:${outputIndex}`, 'webvtt'];+ }+ }+// when concat'ing, disposition doesn't seem to get automatically transferred by ffmpeg, so we must do it manuallyif (manuallyCopyDisposition && stream.disposition != null) {const activeDisposition = getActiveDisposition(stream.disposition);diff --git a/src/util/streams.test.js b/src/util/streams.test.jsindex 235f39af..605ca2f4 100644--- a/src/util/streams.test.js+++ b/src/util/streams.test.js@@ -11,14 +11,14 @@ const streams1 = [{ index: 7, codec_type: 'subtitle', codec_tag: '0x0000', codec_name: 'subrip' },];-const path = '/path/file.mp4';-const outFormat = 'mp4';-// Some files haven't got a valid video codec tag set, so change it to hvc1 (default by ffmpeg is hev1 which doesn't work in QuickTime)// https://github.com/mifi/lossless-cut/issues/1032// https://stackoverflow.com/questions/63468587/what-hevc-codec-tag-to-use-with-fmp4-hvc1-or-hev1// https://stackoverflow.com/questions/32152090/encode-h265-to-hvc1-codectest('getMapStreamsArgs', () => {+ const path = '/path/file.mp4';+const outFormat = 'mp4';+expect(getMapStreamsArgs({allFilesMeta: { [path]: { streams: streams1 } },copyFileStreams: [{ path, streamIds: streams1.map((stream) => stream.index) }],@@ -35,7 +35,27 @@ test('getMapStreamsArgs', () => {]);});+test('getMapStreamsArgs, subtitles to matroska', () => {+ const path = '/path/file.mkv';+ const outFormat = 'matroska';++ const streams = [+ { index: 0, codec_type: 'subtitle', codec_tag: '0x67337874', codec_name: 'mov_text' },+ ];++ expect(getMapStreamsArgs({+ allFilesMeta: { [path]: { streams } },+ copyFileStreams: [{ path, streamIds: streams.map((stream) => stream.index) }],+ outFormat,+ })).toEqual([+ '-map', '0:0', '-c:0', 'srt',+ ]);+});+test('getMapStreamsArgs, disposition', () => {+ const path = '/path/file.mp4';+ const outFormat = 'mp4';+expect(getMapStreamsArgs({allFilesMeta: { [path]: { streams: streams1 } },copyFileStreams: [{ path, streamIds: [0] }],