Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- SUBBING WEBMS WITH FFMPEG
- Step 0: If you’re using Windows, you need to set up fonts.conf first.
- In the folder that contains ffmpeg.exe (bin folder), create a
- new folder named fonts. In that fonts folder, use a text editor
- to create a file named fonts.conf with the content here:
- http://pastebin.com/DpD24trj
- Step 1: Run this command to extract the subs and fonts, replacing
- %input% with the name of your source video:
- ffmpeg -dump_attachment:t "" -i %input% output.ass
- Step 2: Add this option to your normal encoding line:
- -vf ass="output.ass"
- Note that you can only have one -vf option, so if you are
- already using it to scale, add the new filter with a comma:
- -vf scale=-1:504,ass="output.ass"
- You also must place -ss after -i for correct subtitle timing.
- Your final command should look something like this:
- ffmpeg -i input.mkv -ss 00:15:04 -t 3 -an -b:v 1200k -vf scale=-1:504,ass="output.ass" output.webm
- It may take a while due to the accurate seeking, but eventually
- you should get a .webm with correctly styled hardsubs.
- APPENDIX (you can skip this)
- Using batch files: Dumping the subtitles and fonts will fill your bin folder with a
- bunch of extra files that you need to delete afterwards. Instead of manually typing
- the commands and deleting the files each time, it’s easier to create a .bat file that
- will do it for you. Here is an example of a basic .bat for subbing .webms:
- set input="C:\chinese cartoon.mkv"
- ffmpeg -dump_attachment:t "" -i %input% output.ass
- ffmpeg -i %input% -ss 00:15:04 -t 3 -an -b:v 1200k -vf scale=-1:504,ass="output.ass" output.webm
- del output.ass
- for %%f in (*.ttf) do (
- del "%%f"
- )
- for %%f in (*.otf) do (
- del "%%f"
- )
- Customize this (adding 2-pass and so on), save it as something.bat in your ffmpeg bin
- folder and run it.
- Fast seeking: Normally, you need to use slow, accurate seeking (-ss after -i) because
- fast seeking (-ss before -i) resets the internal clock to 0, so your subtitles will not be
- timed correctly. If you’re too impatient for accurate seeking and willing to risk bugs,
- one hack solution is to add the setpts and -itsoffset filter to your encoding line:
- ffmpeg -ss 00:01:20 -itsoffset 00:01:20 -i input.mkv -t 3 -vf setpts=PTS-%sec%,ass="output.ass" tmp.webm
- Replace %sec% with the number of seconds from the start to your offset point (ss).
- Afterwards, you need to run this to correct the video length (it’s lossless):
- ffmpeg -i tmp.webm -c:v copy output.webm
- Choosing a non-default subtitle track: First you need to find the stream
- number of the desired subtitle track.
- One way is to read the output of ffmpeg -i file.mkv
- (e.g.: Stream #0:7 ... title: Commentary -- So commentary is stream 7.)
- Or you could check Properties -> MediaInfo in MPC-HC.
- (e.g.: ID: 8 ... Title: Commentary -- Subtract 1 from the ID: Again, commentary is stream 7.)
- Now specify stream 7 (always 0:7) with -map in your font/sub extracting command:
- ffmpeg -dump_attachment:t "" -i %input% -map 0:7 output.ass
Advertisement
Add Comment
Please, Sign In to add comment