How to disable subtitles decoding in ffmpeg
Asked Answered
G

4

38

I'm trying to convert some video file containing video, audio and subtitles streams into another format using FFMpeg. However, ffmpeg complains about the subtitles format - it cannot decode the stream. Since I don't need this subtitles stream, I'd like to know how can I disable subtitles stream decoding during conversion?

Gouache answered 26/8, 2012 at 16:27 Comment(1)
removing subtitles is also useful to avoid multiplexing dash complaints. Though VLC shows some metadata as subtitles, to remove that with ffmpeg you'll need -map_metadata -1Kriemhild
G
74

I've finally found an answer.

There is such option as -sn which disables subtitles decoding from input stream. Also there are analogous options for audio and video decoding: -an and -vn respectively.

It also turned out that there is another way to achieve this. One may use the -map option to select which streams are to be decoded. So omitting the subtitles stream among the -map options does the job.

For example, if one has a movie file with 3 streams:

  • Stream 0: video
  • Stream 1: audio
  • Stream 2: subtitles

the converting command for FFmpeg may look as follows:

ffmpeg -i <input file> -sn -vcodec <video codec> -acodec <audio codec>  <output file>

or

ffmpeg -i <input file> -vcodec <video codec> -acodec <audio codec> -map 0:0 -map 0:1  <output file>

The former command line deselects the subtitles stream (probably all of them, if there are several) while the latter one selects only the necessary streams to decode.

Gouache answered 29/8, 2012 at 9:49 Comment(2)
+1 The first approach (-sn option) totally works, thanks. (Tried it on an mkv file.)Merrile
Works great! If you need to simply remove the subs from a video file without re-encoding it then this works very fast: ffmpeg -i video.mkv -vcodec copy -acodec copy -sn video-no-subs.mkvBeaird
H
14

To remove subtitle stream without re-encoding video and audio shortest command would be:

ffmpeg -i input.mkv -sn -c copy output.mkv

Haunting answered 16/6, 2020 at 20:3 Comment(0)
E
10

Use negative mapping to omit subtitles and keep everything else:

ffmpeg -i input.mkv -map 0 -map -0:s -c copy output.mkv
  • -map 0 selects all streams. This is recommended because the default stream selection behavior only chooses 1 stream per stream type.
  • -map -0:s is a negative mapping that deselects all subtitle streams.
  • -c copy enables stream copy mode which only re-muxes and avoids re-encoding.
Equestrienne answered 16/6, 2020 at 21:18 Comment(0)
M
0

building off @llogan's comment.

You can use this to batch mode all .mkv files in the current folder. It will write output to temp file remove original and mv temp outfile to original filename's path.

find -name "*.mkv" -exec bash -c 'ffmpeg -y -i "{}" -map 0 -map -0:s -c copy "${0/.mkv}-nosubs.mkv" && rm "{}" && mv "${0/.mkv}-nosubs.mkv" "{}"' {} \;

Or specific folder of stuff

video_path=''
find "$video_path" -name "*.mkv" -exec bash -c 'ffmpeg -y -i "{}" -map 0 -map -0:s -c copy "${0/.mkv}-nosubs.mkv" && rm "{}" && mv "${0/.mkv}-nosubs.mkv" "{}"' {} \;
Matter answered 15/10, 2022 at 21:19 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.