[FFmpeg-user] Can I add a codec for compatibility and automatically keep the original?

Moritz Barsnick barsnick at gmx.net
Mon Nov 13 15:43:44 EET 2023


Hi,

On Sat, Nov 11, 2023 at 11:12:07 +0100, bbb wrote:
> when I have a file using advanced subtitles, I often want to keep those for
> most devices but also add a basic subtitle format that is supported by my
> TV.
>
> So far, I've been converting the subtitles and after that, mapping the
> different subtitle format from the original and the output file into a final
> file in a second operation. Surely it would also be possible to map the
> original subtitles twice and then copy all codecs and convert only that of
> the second subtitle stream.

Sure you can. You map the relevant input stream twice, and copy the
first one while converting the second one.

Something like:

$ ffmpeg -i video.ext -map 0:v -map 0:a -map 0:s -map 0:s -c:v copy -c:a copy -c:s:0 copy -c:s:1 srt output.ext

(Or perhaps convert the first one, if it's important for your TV.)

> I am planning to work on an automation (that works on a directory without
> knowing the number of streams in each file) and wondering, if ffmpeg maybe
> already has the kind of feature that I am looking for.

I believe ffmpeg cannot automate the work on the number of streams. For
the above scenario, you have to identify the streams first before
constructing the command line. (So there's no "-map_if_exists 0:s"...)

Cheers,
Moritz


More information about the ffmpeg-user mailing list