FFMPEG encode audio and forced subtitles at same time?

2k views Asked by At

I'm using latest static build of ffmpeg windows.

My input file (.mkv) is:

[video] - 1080, V_MPEG4/ISO/AVC, 14.6 Mbps, ID#0
[audio] - DTS 5.1, 1510 Kbps, ID#1
[subtitles] - S_TEXT/ASS Lossless English, ID#14

My problem is this: I convert the audio, so that my target player, a XB1 console (media support faq), is able to play audio/video. However sometimes its rather difficult to hear or parts may be in foreign language, so I want to force the english subtitles into the mix at the same time I convert the audio.

Currently for the audio, I use the following command

ffmpeg -i input.mkv -codec copy -acodec ac3 output.mkv

Can I somehow tie in the forced subtitles (onto the video) in order to save an extra process of taking the output.mkv and trying to force subtitles on?

Edit: I've tried using the following command to extract subtitles to be able to edit them

ffmpeg -i Movie.mkv -map 0:s:14 subs.srt

However i get the error: Stream map '0:s:14' matches no streams

Edit2: attempted to extract subtitles and succeeded with

ffmpeg -i input.mkv -map 0:14 -c copy subtitles.ass

but still looking to force the subtitles, nonetheless!

Also - a little bonus to this question - can I somehow extract the .ass file and edit it to only produce subtitles for foreign parts - so english audio doesn't have subtitles during the movie but foreign audio does have subtitles?

Cheers

Edit3:

When I try to use both of the commands at once (my earlier mentioned audio converter & one from the ffmpeg wiki)

ffmpeg -i input.mkv -codec copy -acodec ac3 -vf "ass=subs.ass" output.mkv

I get the following error from ffmpeg,

Filtergraph 'ass=subs.ass' was defined for video output stream 0:0 but codec copy was selected.
Filtering and streamcopy cannot be used together.
1

There are 1 answers

0
Gyan On

Since your media player does not support subtitles, the text has to be burnt onto the video image. For that, use

ffmpeg -i input.mkv -vf "ass=subs.ass" -c:v libx264 -crf 20 -c:a ac3 output.mkv

This will re-encode the video, since text is being added. The CRF value controls the video quality. Lower values produce better quality but larger files. 18 to 28 is a decent range to try.