katewishing

Subbing webms with ffmpeg

May 2nd, 2014
241
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.13 KB | None | 0 0
  1. SUBBING WEBMS WITH FFMPEG
  2.  
  3. Step 0: If you’re using Windows, you need to set up fonts.conf first.
  4. In the folder that contains ffmpeg.exe (bin folder), create a
  5. new folder named fonts. In that fonts folder, use a text editor
  6. to create a file named fonts.conf with the content here:
  7. http://pastebin.com/DpD24trj
  8.  
  9.  
  10. Step 1: Run this command to extract the subs and fonts, replacing
  11. %input% with the name of your source video:
  12. ffmpeg -dump_attachment:t "" -i %input% output.ass
  13.  
  14. Step 2: Add this option to your normal encoding line:
  15. -vf ass="output.ass"
  16. Note that you can only have one -vf option, so if you are
  17. already using it to scale, add the new filter with a comma:
  18. -vf scale=-1:504,ass="output.ass"
  19. You also must place -ss after -i for correct subtitle timing.
  20. Your final command should look something like this:
  21.  
  22. ffmpeg -i input.mkv -ss 00:15:04 -t 3 -an -b:v 1200k -vf scale=-1:504,ass="output.ass" output.webm
  23.  
  24. It may take a while due to the accurate seeking, but eventually
  25. you should get a .webm with correctly styled hardsubs.
  26.  
  27.  
  28.  
  29.  
  30. APPENDIX (you can skip this)
  31.  
  32. Using batch files: Dumping the subtitles and fonts will fill your bin folder with a
  33. bunch of extra files that you need to delete afterwards. Instead of manually typing
  34. the commands and deleting the files each time, it’s easier to create a .bat file that
  35. will do it for you. Here is an example of a basic .bat for subbing .webms:
  36.  
  37. set input="C:\chinese cartoon.mkv"
  38.  
  39. ffmpeg -dump_attachment:t "" -i %input% output.ass
  40. ffmpeg -i %input% -ss 00:15:04 -t 3 -an -b:v 1200k -vf scale=-1:504,ass="output.ass" output.webm
  41.  
  42. del output.ass
  43. for %%f in (*.ttf) do (
  44. del "%%f"
  45. )
  46.  
  47. for %%f in (*.otf) do (
  48. del "%%f"
  49. )
  50.  
  51. Customize this (adding 2-pass and so on), save it as something.bat in your ffmpeg bin
  52. folder and run it.
  53.  
  54.  
  55. Fast seeking: Normally, you need to use slow, accurate seeking (-ss after -i) because
  56. fast seeking (-ss before -i) resets the internal clock to 0, so your subtitles will not be
  57. timed correctly. If you’re too impatient for accurate seeking and willing to risk bugs,
  58. one hack solution is to add the setpts and -itsoffset filter to your encoding line:
  59. ffmpeg -ss 00:01:20 -itsoffset 00:01:20 -i input.mkv -t 3 -vf setpts=PTS-%sec%,ass="output.ass" tmp.webm
  60. Replace %sec% with the number of seconds from the start to your offset point (ss).
  61. Afterwards, you need to run this to correct the video length (it’s lossless):
  62. ffmpeg -i tmp.webm -c:v copy output.webm
  63.  
  64.  
  65. Choosing a non-default subtitle track: First you need to find the stream
  66. number of the desired subtitle track.
  67. One way is to read the output of ffmpeg -i file.mkv
  68. (e.g.: Stream #0:7 ... title: Commentary -- So commentary is stream 7.)
  69. Or you could check Properties -> MediaInfo in MPC-HC.
  70. (e.g.: ID: 8 ... Title: Commentary -- Subtract 1 from the ID: Again, commentary is stream 7.)
  71.  
  72. Now specify stream 7 (always 0:7) with -map in your font/sub extracting command:
  73. ffmpeg -dump_attachment:t "" -i %input% -map 0:7 output.ass
Advertisement
Add Comment
Please, Sign In to add comment