Skip to content

Commit 11104c8

Browse files
committed
Refactor logic.
1 parent a9e1430 commit 11104c8

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

extension/js/popup.js

+14-8
Original file line numberDiff line numberDiff line change
@@ -169,16 +169,22 @@ export function updateCommand(e) {
169169
inputs.push(audio_stream);
170170
}
171171
inputs.push(...subtitles);
172-
if (extension === 'mp4') {
173-
cmd.value = `${options.ffmpeg_command} ${inputs.map((url) => `-i "${url}"`).join(' ')} ${mapOutputToNumber(inputs)} ${inputs.length > 2 ? '-c:s mov_text' : ''} -c:v copy -c:a copy -bsf:a aac_adtstoasc "${output_path}"`;
174-
} else {
175-
cmd.value = `${options.ffmpeg_command} ${inputs.map((url) => `-i "${url}"`).join(' ')} ${mapOutputToNumber(inputs)} -c:v copy -c:a copy "${output_path}"`;
172+
173+
const command = [
174+
options.ffmpeg_command,
175+
...inputs.map((url) => `-i "${url}"`),
176+
];
177+
if (subtitles.length > 1) {
178+
// Adding -map arguments to ffmpeg makes it select all the streams from that input. https://trac.ffmpeg.org/wiki/Map
179+
command.push(...inputs.map((v, i) => `-map ${i}`));
176180
}
177-
function mapOutputToNumber(array) {
178-
return array.length > 2
179-
? array.map((_value, index) => `-map ${index}`).join(' ')
180-
: '';
181+
command.push('-c:v copy -c:a copy');
182+
if (extension === 'mp4') {
183+
command.push('-c:s mov_text -bsf:a aac_adtstoasc');
181184
}
185+
command.push(`"${output_path}"`);
186+
187+
cmd.value = command.join(' ');
182188
}
183189
cmd.setAttribute('data-url', url);
184190
cmd.dispatchEvent(new Event('input'));

0 commit comments

Comments
 (0)