javascripthtmlffmpegm3u8airplay

How to view subtitles vtt when AirPlay a mp4 file?


Target is view html subtitles in vtt format in TV when AirPlay is running.

html code:

<video preload="metadata" x-webkit-airplay="allow" src="a.mp4">
    <track kind="subtitles" default="" src="en.vtt" srclang="en">
    <track kind="subtitles" src="de.vtt" srclang="de">
    <track kind="subtitles" src="es.vtt" srclang="es">
    <track kind="subtitles" src="fr.vtt" srclang="fr">
</video>

The problem is when AirPlay is enabled video and audio plays on TV, but no subtitles showed.

I tried to include vtt/srt subtitles into the mp4 metadata with ffmpeg and subtitles working with VLC but not working when AirPlay this files

ffmpeg -i 8499.mp4 -i 8499.en.vtt -map 0:v -map 0:a -c copy -map 1 -c:s:0 mov_text -metadata:s:s:0 language=en 8499.en.mp4
ffmpeg -i 8499.mp4 -i 8499.en.srt -map 0:v -map 0:a -c copy -map 1 -c:s:0 srt -metadata:s:s:0 language=en 8499.en.mp4

Also tried to send a .m3u8 with no luck. Any of you know how is the basic format for a simple .m3u8 with a .mp4 and .vtt working when AirPlay?

Which is the standard subtitles solution for AirPlay?


Solution

  • I'm not surprised that iOS doesn't Airplay the VTT subtitles from <video> to an Airplay sink.

    iOS (and probably tvOS as well) only supports 1 embedded subtitle/captioning format: MP4 Timed Text / MPEG-4 Part 17. Sometimes it is called Quicktime Timed Text. Safari also supports VTT (but not SRT) for <video>, but that is only in Safari.

    One of your ffmpeg examples is close. If you want to Airplay MP4 files with subtitles/captions you must start with an SRT subtitle file as the input. Not an MP4 Timed Text file (which are far less common than SRT). Using mov_text will encode it.

    This is an example I found in another answer relating to this question.

    ffmpeg -i infile.mp4 -i infile.srt -c copy -c:s mov_text outfile.mp4

    Note: the order of -c commands matters if you use -c copy. You must specify any source stream changes after it