Transcode HLS m3u8 to MP4 and include text track

ffmpegvideo

Is it possible with FFMPEG to convert a m3u8 to a MP4 and keep the captions (text) track?

When looking at the Apple stream, https://devimages.apple.com.edgekey.net/streaming/examples/bipbop_4x3/bipbop_4x3_variant.m3u8 I see that the video stream makes mention of Closed Captions, but I can't seem to find a way to extract them.

Stream #0:0: Video: h264 (Main) ([27][0][0][0] / 0x001B), yuv420p(tv, smpte1
70m/smpte170m/bt709), 400x300, Closed Captions, 29.92 fps, 29.92 tbr, 90k tbn, 1
80k tbc

The multiple attempts I have made transcode to mp4 but it drops the captions.

I have used VLC on the manifest and it has "subtitles" but after transcode the mp4 doesn't.

Used the command:
ffmpeg -i https://devimages.apple.com.edgekey.net/streaming/examples/bipbop_4x3/bipbop_4x3_variant.m3u8 -c copy -bsf:a aac_adtstoasc out.mp4

Best Answer

I did manage to pull together enough pieces on information to complete this. It is a combination of 3 commands.

Using ffmpeg version 2.8.4

First, the playlist segments need to be merged into a single MPEG-TS file:

ffmpeg -i [playlist_url].m3u8 -c copy [filename].ts

Next, we need to extract the Closed Captions from the file:

ffmpeg -f lavfi -i "movie=[filename_from_last_step].ts[out0+subcc]" [filename].srt

Note: I could only get it to work if the ts file and the cmd's current path matched.

Lastly, you merge the ts and srt file and transcode to MP4:

ffmpeg -i [filename_from_first_step].ts -i [captions].srt -c:v copy -bsf:a aac_adtstoasc -c:s mov_text [out_file_name].mp4

This will give you a MP4 with the captions embedded, as well as a stand-alone srt file if your player doesn't support embedded captions.

Related Question