szatmary / libcaption

Free open-source CEA608 / CEA708 closed-caption encoder/decoder
MIT License
151 stars 64 forks source link

Resultant MP4 does not have CCs #48

Closed nabeards closed 6 years ago

nabeards commented 6 years ago

I followed similar steps to what's in the add_captions script. I have a file, in.mp4, and an SCC caption file. The resultant FLV has captions, converting to MP4 with ffmpeg does not have captions.

Commands:

> ffmpeg -i in.mp4 -codec copy -f flv in.flv
> flv+scc in.flv captions.scc out.flv
> ffmpeg -i out.flv -codec copy out.mp4

Using ffmpeg 4.0.1, installed via git clone and directions in Readme, running Mac OS 10.12.6.

Any suggestions on how to make the output MP4 have the embedded CCs?

embeddedguy1138 commented 6 years ago

Hi Neil,

Do you know the mp4 is missing the embedded caption data? You do a hexdump of the file and search for the SEI bits to be sure.

The ffmpeg command you are using looks correct and should only be changing the container type from flv to mp4. It shouldn't be modifying the encoded data whatsoever. I tested this out on my system and it works as expected, though I am using a different version than you

ffmpeg version 2.8.15-0ubuntu0.16.04.1 Copyright (c) 2000-2018 the FFmpeg developers

nabeards commented 6 years ago

Thanks for the help! I've got hexdumps of the videos, but I'm not sure what exactly to look for to make sure the SEI bits are there. Can you point me to something that documents the SEI bits?

If I insert these same captions with Subler, they display just fine. I'm hoping to be able to accomplish the same effect using libcaption.

embeddedguy1138 commented 6 years ago

No problem.

The SEI message is a way of passing user metadata (ie captions) through the H.264 NALU. For closed captions, that user metadata is typically going to conform to the CEA-708 standard (https://en.wikipedia.org/wiki/CEA-708).

Typically, an H.264 header with 708 captions in the sei will look something like this:

06 04 1D B5 00 31 47 41 39 34 03 46 FF FC ... 80

I would expect something like this in the hexdump of your FLV file. Assuming ffmpeg is doing its job, you should see the same header appearing in your MP4. I don't know what you are using to play the video after, but I've had a fair share of issues with VLC properly decoding caption data.

I am not familiar with Subler, but it looks like it is using 3gpp timed text (MPEG-4 part 17) and not CEA-608/708.

Hope this helps you some!

nabeards commented 6 years ago

OK, this was a huge help. Here are two lines I see in the FLV (which is working in VLC):

01 00 00 a7 00 00 00 18  06 04 14 b5 00 31 47 41
39 34 03 43 ff fc 94 20  fc 94 2c fc 94 2f ff 80

and the matching lines in the MP4:

50 42 11 e0 00 00 00 18  06 04 14 b5 00 31 47 41
39 34 03 43 ff fc 94 20  fc 94 2c fc 94 2f ff 80

Tested again with VLC 4.0.0 from May 2018 and it does display them now in the MP4. Thank you for your help!!