12

I'm looking to remove the closed captions (EIA-608) from a H.264 video (contained as mkv) without reencoding.

The closest I've got is using ffmpeg:

    ffmpeg -f lavfi -i movie=input.mkv[out+subcc] -map 0:0 output.mkv

In order to separate the video into rawvideo and subrip components and export out the rawvideo. However this results in a file close to 200GB, which isn't really a sustainable solution.

An ffmpeg based solution would be preferable, but I'm fine using whatever software is necessary.

3
  • Not possible at present with ffmpeg - trac.ffmpeg.org/ticket/5283
    – Gyan
    Jan 10, 2018 at 7:08
  • I assume your captions are CEA-608 (and not EIA-618). Please provide a sample file. Your captions may be embedded inside the H.264 stream (via SEI) or your captions may be in a separate stream inside the MKV container. Jan 11, 2018 at 14:59
  • You're right, they are 608, edited the question to correct my error. I've uploaded a brief clip to Mega Jan 12, 2018 at 20:36

3 Answers 3

29

This is actually possible using bitstream filters. As far as I know I discovered this myself, since everywhere I have looked this is supposed to be unsupported.

The first thing to understand is that for EIA-608 and similar closed captioning standards, the captions are embedded directly in the video bitstream as user data. H.264 bitstreams are stored as a sequence of NAL (network abstraction layer) units. Each unit has a type; user data is stored in a NAL unit of the supplemental enhancement information (SEI) type.

It turns out that ffmpeg has a bitstream filter called filter_units, which allows you to pass or reject NAL units by type. So we can use this to remove all the SEI NAL units, which strips out the captions.

The filter documentation for filter_units says that we have to specify the types by number. According to the latest H.264 spec (Table 7-1), SEI units have type 6.

So the following command will remove embedded closed captions:

ffmpeg -i input.mkv -codec copy -bsf:v "filter_units=remove_types=6" output.mkv

This has worked for me on several files without any problems or side effects.

5
  • 1
    Works like a charm. Thank you so much <3 Jul 21, 2018 at 15:14
  • 2
    How can I make ffmpeg to see the EIA subtitles? I'm trying ffmpeg -i and ffprobe but it doesn't show up the subtitle at all!
    – Freedo
    Nov 7, 2018 at 7:31
  • Unknown bitstream filter filter_units with ffmpeg version 3.4.4-1 you need 4+
    – Freedo
    Nov 13, 2018 at 9:53
  • I attempted to remove the CC1/EIA-608 by outputting video & audio into separate files. Running each through MediaInfo, neither showed the closed caption track. So I figured it was successful. Then I muxed the video & audio back together into a new MP4 & found the CC track to still be shown in MediaInfo. The filter_units solution did work for me. Thank you. Mar 2, 2019 at 23:59
  • Amazing! - And it's really really fast.
    – Anders
    Sep 13, 2021 at 15:12
1

I came across this post while attempting to remove closed captions from an MPEG-2 video (from an NTSC DVD). filter_units=remove_types=6 didn't work and actually caused a thick black horizontal bar to appear, presumably because crucial video information was removed since the codecs differ. After some experimentation, I discovered that remove_types=178 worked.

Thought I'd post here for anyone else trying to achieve the same in the future. I would've just commented on the answer but I don't have the reputation necessary to do so.

0

For anyone looking to do this with h265 remove_types=39

It's important to note that for AVC/HEVC, SEI is also used for other information like HDR10+, so using this will result in that metadata being removed, there is an existing open ticket regarding this issue. So if you don't want to lose HDR then it would be best not to remove closed caption.

https://trac.ffmpeg.org/wiki/HowToExtractAndRemoveClosedCaptions

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.