4

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

2 Answers 2

5

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.

2
  • Thanks for the formula! It works on a stream I needed to download. But I am not entirely sure what is the second bracket of [filename_from_last_step].ts[out0+subcc] for?
    – jackxujh
    Commented Oct 2, 2019 at 6:21
  • @jackxujh closed captions are embedded in the video frames, [out0+subcc] allows ffmpeg to extract them and treat it a independent track.
    – Justin
    Commented Dec 26, 2019 at 22:00
1

If Closed Captions means a CEA-608 or 708 stream, then those are weirdly packetized i.e. embedded within the video stream, and ffmpeg cannot copy or encode them.

You can try to use CCextractor to extract them. If it does not work on the stream. Download the individual segments, concat them and try with that.

Once extracted, you can encode them using -c:s mov_text into the MP4.

1
  • Point 1 and 3 are dead on, but point 2 can be done with ffmpeg as I finally found a bug with the solution.
    – Justin
    Commented Feb 11, 2016 at 18:38

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .