From 1a574c02b270735f2c3ecb04b548536b13041274 Mon Sep 17 00:00:00 2001 From: Mikael Finstad Date: Thu, 21 Dec 2023 16:25:09 +0800 Subject: [PATCH] convert more subtitle codecs #418 --- src/util/streams.js | 6 ++++++ src/util/streams.test.js | 30 ++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/src/util/streams.js b/src/util/streams.js index 1e1784c5..5687f6b0 100644 --- a/src/util/streams.js +++ b/src/util/streams.js @@ -131,6 +131,12 @@ function getPerStreamFlags({ stream, outputIndex, outFormat, manuallyCopyDisposi } else if (outFormat === 'webm' && stream.codec_name === 'mov_text') { // Only WebVTT subtitles are supported for WebM. addCodecArgs('webvtt'); + } else if (outFormat === 'srt') { // not technically lossless but why not + addCodecArgs('srt'); + } else if (outFormat === 'ass') { // not technically lossless but why not + addCodecArgs('ass'); + } else if (outFormat === 'webvtt') { // not technically lossless but why not + addCodecArgs('webvtt'); } else { addCodecArgs('copy'); } diff --git a/src/util/streams.test.js b/src/util/streams.test.js index 8e354b21..a503caf5 100644 --- a/src/util/streams.test.js +++ b/src/util/streams.test.js @@ -111,3 +111,33 @@ test('getStreamIdsToCopy, includeAllStreams false', () => { expect(streamIdsToCopy).toEqual([2, 1, 7]); expect(excludedStreamIds).toEqual([0, 3, 4, 5, 6]); }); + +test('srt output', () => { + expect(getMapStreamsArgs({ + allFilesMeta: { [path]: { streams: [{ index: 0, codec_type: 'subtitle', codec_tag: '0x67337874', codec_name: 'mov_text' }] } }, + copyFileStreams: [{ path, streamIds: [0] }], + outFormat: 'srt', + })).toEqual([ + '-map', '0:0', '-c:0', 'srt', + ]); +}); + +test('webvtt output', () => { + expect(getMapStreamsArgs({ + allFilesMeta: { [path]: { streams: [{ index: 0, codec_type: 'subtitle', codec_tag: '0x67337874', codec_name: 'mov_text' }] } }, + copyFileStreams: [{ path, streamIds: [0] }], + outFormat: 'webvtt', + })).toEqual([ + '-map', '0:0', '-c:0', 'webvtt', + ]); +}); + +test('ass output', () => { + expect(getMapStreamsArgs({ + allFilesMeta: { [path]: { streams: [{ index: 0, codec_type: 'subtitle', codec_tag: '0x67337874', codec_name: 'mov_text' }] } }, + copyFileStreams: [{ path, streamIds: [0] }], + outFormat: 'ass', + })).toEqual([ + '-map', '0:0', '-c:0', 'ass', + ]); +});