Home/News | About | Download | Documentation | Forum | Bug Reports | Contact | Donations | Consulting | Projects | Legal | Security | FATE


This forum has not been maintained for a long time and will probably get deleted in the near future.
For faster responses to your questions, please use StackOverflow instead and tag your questions with "FFmpeg".
If you need a backup of the posts from this forum, please contact me directly.

How to burn subtitles into the video

A collection of useful tutorials for some common tasks.

Re: How to burn subtitles into the video

Postby nille » Thu Aug 30, 2012 9:37 am

Why are you reencode everything if you only want to convert mkv to mp4?
Code: Select all
ffmpeg -i input.mkv -acodec copy -vcodec copy output.mp4
is enough to convert mkv to mp4

And no, you can't store you subtitle in the mp4 container. But you can burn in the subtitle into the video.
nille
 
Posts: 7
Joined: Thu Jul 26, 2012 7:52 am

Re: How to burn subtitles into the video

Postby TechnoPhil » Thu Aug 30, 2012 9:53 am

Thank you for your answer!
I need to reencode because i want to compress audio/video tracks for mobile devices! Thats why, this is not possible what i would like to do with mp4 container!
Understood that mp4 can't contain the subtitle track, so how can i burn subtitles into the video?

Thanks you and sorry for my bad english! ;)
TechnoPhil
 
Posts: 12
Joined: Thu Aug 30, 2012 6:40 am
Location: San Marino

Re: How to burn subtitles into the video

Postby nille » Thu Aug 30, 2012 10:45 am

In which subtitle format are your subtitles? If ass then you can reencode and burn in everything with

Code: Select all
ffmpeg -i input.mkv -report -acodec copy -vcodec libx264 -sameq -vf ass=subtitlefile.ass output.mp4


Place in the same folder, where your input file is, the subtitle.ass file. If in you mkv container are fonts, make sure you has install these fonts in you system.

and about you English if you say where you from maybe i can help you in your native language because my English is horrible to :p
nille
 
Posts: 7
Joined: Thu Jul 26, 2012 7:52 am

Re: How to burn subtitles into the video

Postby TechnoPhil » Thu Aug 30, 2012 11:45 am

Ok, i understood!
Now we have to extract the "subtitlefile.ass" directtly from the mkv video anche then we can use it in the mp4 file.
Am i correct? How can i do that?

p.s I am from San Marino, i speak italian! :D
TechnoPhil
 
Posts: 12
Joined: Thu Aug 30, 2012 6:40 am
Location: San Marino

Re: How to burn subtitles into the video

Postby nille » Thu Aug 30, 2012 12:10 pm

i use for this the mkvtools

with mkvmerge -i input.mkv you can get all important ids for extract the subtitle and ( important the fonts )

as example.
Code: Select all
mkvextact tracks input.mkv 3:subtitle.ass


for the fonts
Code: Select all
mkvextract attachments input.mkv 1 2 3 4 5 6 7 8 9 10

Note: That extract 10 attachments in the mkv. if there are more fonts you has to add more ids

if you are using linux you can edit the font.conf that he search in your current directory for the fonts.

for this edit /etc/fonts.conf and add
Code: Select all
<dir>./</dir>


if you are using windows, make sure ffmpeg can find your fontconfig config or he cant burn in you subtitle.

PS: if you need help you can PM me an we can talk in skype or smt like this. and about the language i cant Italian sorry :/
nille
 
Posts: 7
Joined: Thu Jul 26, 2012 7:52 am

Re: How to burn subtitles into the video

Postby burek » Fri Aug 31, 2012 8:47 am

"-sameq" does not mean "same quality", like many people think, rather "same quantization factor", which doesn't give you the same quality in the output, since you will add subtitles and quantization matrix will surely change.

use -crf and -preset instead, like this:
Code: Select all
ffmpeg -i input.mkv -acodec copy -vcodec libx264 -crf 23 -preset medium -vf ass=subtitlefile.ass output.mp4


also, use "x264 --help" to get the description for those options, or check this link: X264 Settings

P.S.

To copy subtitle track to the output (if the output format supports it)

to copy streams, from the input to the output, you can use:
"-c copy" to copy all streams
"-c:a copy" to copy all AUDIO streams
"-c:v copy" to copy all VIDEO streams
"-c:d copy" to copy all DATA streams
"-c:s copy" to copy all SUBTITLE streams
"-c:t copy" to copy all ATTACHMENT streams
("-c:X" is a new way of stream selection in ffmpeg and it is an alias for "Xcodec", which means -c:v=vcodec, -c:a=acodec, -c:s=scodec, etc.)

so, in your case:
"ffmpeg -i $i -map 0.0 -map 0.3 -s 1280x720 -vcodec libx264 -b:v 3000k -bt 5000k -acodec ac3 -ac 6 -ar 44100 -b:a 256k -threads 4 -scodec copy $newname;"

For more info, see this: Stream specifiers
burek
 
Posts: 864
Joined: Mon May 09, 2011 10:16 pm
Location: Serbia

Re: How to burn subtitles into the video

Postby TechnoPhil » Fri Aug 31, 2012 10:10 am

@burek

thank you for your help, but MP4 does not support subtitles streams!
We have to burn one subtitle track directly on the video track!
TechnoPhil
 
Posts: 12
Joined: Thu Aug 30, 2012 6:40 am
Location: San Marino

Re: How to burn subtitles into the video

Postby bluebike » Sat Sep 29, 2012 10:23 pm

Actually. After reading all this discussion (and doing some google research).
I have no idea of how to do simple task:

Input: mpeg transport stream (.ts) with DVB-subtitles (bitmap subtitles)
Output: mp4 (or something else) with those subtitles burned in to picture???

There is this dvbsubs module, but what then...
bluebike
 
Posts: 1
Joined: Sat Sep 29, 2012 10:15 pm

Re: How to burn subtitles into the video

Postby burek » Mon Oct 01, 2012 10:05 am

try:
Code: Select all
ffmpeg -i input.ts -map ... -acodec ... -vcodec ... -vf ass=subtitlefile.ass output.mp4

(-map option MUST contain subtitle stream also, or use "-map 0" to map all input streams to output)
burek
 
Posts: 864
Joined: Mon May 09, 2011 10:16 pm
Location: Serbia

Re: How to burn subtitles into the video

Postby jinghao666 » Tue Feb 05, 2013 7:19 am

you will do this
Code: Select all
ffmpeg -i video.avi -vf ass=subtitle.ass out.avi

before this,you must --enable libass. And you will config the libass --enable-fontconfig.
jinghao666
 
Posts: 2
Joined: Tue Feb 05, 2013 7:13 am

PreviousNext

Return to Tutorials

Who is online

Users browsing this forum: No registered users and 1 guest