Hard-subbing without vlc player (ffmpeg)

Опубликовано: 16 Октябрь 2024
на канале: Cerbyo
3,310
32

1:02 Quickstart
ffmpeg -i input.mkv -c:a copy -c:s copy -vf subtitles=input.mkv output.mkv
Considerations:
-those extra streams, information files (c:t) are actually just font files in this case. if you have those fonts installed on your computer already, they are not needed in any capacity. SO you could extract and install them 1 by 1 if you so choose.
-ffmpeg includes the highest quality audio and video stream by default, and discards the others unless we specify to include them via the general -map 0 or by specifying each via -map 0:0 (where the second 0 corresponds to whatever stream it actually is, so -map 0:2 or whatever). So if you were doing a hardsub, but wanted to keep the the multiple audio dubs for example you should take note.
This can get fairly dicey as we can specify operations per stream such as: Say I have 2 audio streams in channel 0:3 and 0:4 and I want to include them:

ffmpeg -i input.mkv -map 0:3 -map 0:4 -c:s:0 copy -c:s:1 copy output.mkv

-c:s:0 copy means copy the first audio stream (cause of the 0), corresponding to the first audio map specified, which is 0:3. Then -c:s:1, just means the second audio map specified which is 0:4 will be copied. 0 means 1 in many cases, just keep that in mind. And just to re-iterate the above: the order you listed the -map streams is the order they are mapped in.

btw its control+c to stop a command prompt command.
@5:30, I neglected to mention that usually output containers apply certain presets on our codecs if we don't otherwise specify copy or a specific setting. So if we didn't specify -c:a copy or that we want it as .flac, it would actually apply a preset and re-encode the flac as a lossey audio codec probably vorbis given I chose the .mkv as my output container. Something to be aware of.
Oh and Toss
-preset veryfast
or
-preset slow
right before the output.mkv depending on whether you want to sacrifice speed for filesize and vice versa. Only winners go -preset veryslow.

So you might be saying: well I have all my sub streams outside of my video what do I do?
ffmpeg -i input.mkv -i subfile1.srt -i subfile2.srt -c copy output_with_many_substreams.mkv

So in the above command we had 2 sub files (named subfile1 & subfile2) and one movie called input.mkv we wanted to put them into. Just use whatever name you have for your files, and add more -i subfile3 etc...as needed. -c copy just copies all streams over without re-encode: audio, video, sub etc. In other words we are rewrapping. Change the extensions as well based on what your files are. The video's example had a .ass file instead of .srt, so use whatever urs is. You can change the commands based on what you think is right for ur situation, and then just check the streams to confirm what re-encoded and what copied like we did in the video by checking the streams at the start of the operation.

Alternatively you can try -filter_complex
ffmpeg -i video.mkv -filter_complex "subtitles=subtitle.srt,subtitle2.srt" output.mkv
But I haven't tried that yet and am doing my own guessing, so no promises if it works.

You might be saying: nothings working! Well make sure there are no spaces in your filenames and if there are, put them in " ". i.e: "I named my file with spaces harhar".mkv
Make sure your syntax is right, check what the error message says and try to read/follow it, use a simplified command with simplified filenames to debug, try it on different input videos incase the metadata of ur movie is corrupted, update to the newest ffmpeg version if its saying you don't have the necessary library.
You might be saying: this is too hard! Well then go forth my friend, into the loving embrace of vlc player tutorial videos. dot dot dot. dot. Anyways this is enough for the purpose of the video (hardsubbing a video), but there are other things you will want to know when it comes to modifying streams. I'll cover those in the full ffmpeg tutorial I'm working on.