Skip to content

Instantly share code, notes, and snippets.

@innat
Last active February 21, 2024 02:32
Show Gist options
  • Star 24 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save innat/7d5511941970e8b448453980f47f9ec3 to your computer and use it in GitHub Desktop.
Save innat/7d5511941970e8b448453980f47f9ec3 to your computer and use it in GitHub Desktop.
Remove hard subtitles from video file || Integrate subtitles into a video file || Generate .srt file from a video file.

Download FFmpeg for Windows

Steps

  • Download FFmpeg
  • Extract it and save it to C drive ( choose any location - it's optional )
  • Set environment variable - copy the location of bin folder which is inside the extracted file and set the location on system path variable.
  • Done!

Remove Hard Subtitles

Let's say you have a english video file name demo.mkv and it has horrible subtitile problem like chines or a language that you can't understand , than you can simply remove subtitle usign ffmpeg framework. We are talking about built-in subtitiles not .srt file. To do so , follow the following steps :

  • Install FFmepg on your pc and set path variable if needed.
  • Go to your file location and open command prompt or terminal there.
  • After that run the following command - ffmpeg -i video.mkv -vcodec copy -acodec copy -sn video-no-subs.mkv

Integrate Hard Subtitle

Now if any case you want to integrate a srt file on a video player. Then follow below step -

  • Download desire subtitle (language) from online
  • let's assume demo.mkv and downloaded file named sub.srt
  • put both file in one location and open terminal from that location and run following command
  • First convert the subtitles to .ass format: ffmpeg -i sub.srt subs.ass
  • To mux subtitles into a video file run - ffmpeg -i demo.mkv -i sub.ass -codec copy -map 0 -map 1 output.mkv

Extract Subtitile for Video file

Now in these case , a video file with an embeded subtitile and you want to make it srt file or other work a soft subtitile file. We cas do it by following command

  • ffmpeg -i demo.mkv -map 0:s:0 sub.srt

That's it.

@IcedShake
Copy link

You've misused the hard subtitle term entirely. What you're doing here is removing/adding soft subtitles, which is toggleable in some video players. Hard subtitles integrates it into the video stream itself which makes it impossible to remove.

@ykutaykuta
Copy link

Hard sub is the subtitle which is burnt to the video permanently. That means you can’t separate them from the video and whenever you want to watch the video you will see the subtitles as well. They are part of the video so you cannot show/hide them in a player.
What you're doing here is removing/adding Soft sub from File sub
https://trac.ffmpeg.org/wiki/HowToBurnSubtitlesIntoVideo this show you how to hardcode subtitles

Copy link

ghost commented Mar 26, 2022

Agree on the terminology being wrong, but this is one of the best guides I found for this problem!

@dab2020
Copy link

dab2020 commented May 29, 2022

Agree on the terminology being wrong, but this is one of the best guides I found for this problem!

Agreed

@Bmo2001
Copy link

Bmo2001 commented Jul 11, 2022

Agree on the terminology being wrong, but this is one of the best guides I found for this problem!

Agreed

@AnonymousWebHacker
Copy link

AnonymousWebHacker commented Sep 12, 2022

No need to convert srt to acc, Besides, you can add metadata , to indicate the identifier of the subtitle

ffmpeg -i demo.mp4 -f srt -i subs_file_spanish.srt -map 0:0 -c:v copy -c:a copy -c:s mov_text -metadata:s:s:0 language=spanish out.mp4

By the way, mp4 videos support 1 audio, 2 subtitles, that is, you can convert to mp4 videos with 2 internally embedded subtitles, more than 2 audios or more subtitles, if forced to mkv

And thanks for the guide. :)

See more here:
https://github.com/AnonymousWebHacker/ffmpeg-doc/blob/main/README.md

@Raphencoder
Copy link

Any tips to rm hard coded subtitle ?
The link provided before is no longer maintained

@innat
Copy link
Author

innat commented Aug 3, 2023

@Raphencoder consult with chatgpt! :)

@Raphencoder
Copy link

What command that is working did you get with chatgpt ?

@innat
Copy link
Author

innat commented Aug 3, 2023

I didn't. I recommended. I read somewhere that it can handle complex LateX code and is able to render nicely. So, it can give valuable information or instruction or tips to rm hard coded subtitle.

@aurovrata
Copy link

I confirm, the instructions for removing hardcoded (baked) subtitles does not work. The subtitles remain.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment