Opened 9 years ago
Last modified 3 years ago
#5283 reopened enhancement
Add bitstream filter to remove Closed Captions from h264
Reported by: | Carl Eugen Hoyos | Owned by: | |
---|---|---|---|
Priority: | wish | Component: | avcodec |
Version: | git-master | Keywords: | h264 cc |
Cc: | Blocked By: | ||
Blocking: | Reproduced by developer: | no | |
Analyzed by developer: | no |
Description
http://thread.gmane.org/gmane.comp.video.ffmpeg.user/61438/focus=61440
The sample from ticket #2885 contains Closed Captions, FFmpeg does not allow to remove them without reencoding.
$ ffmpeg -i transformers.ts -vcodec copy out.h264 ffmpeg version N-78869-gdd2ea5c Copyright (c) 2000-2016 the FFmpeg developers built with gcc 4.7 (SUSE Linux) configuration: --enable-gpl libavutil 55. 19.100 / 55. 19.100 libavcodec 57. 27.101 / 57. 27.101 libavformat 57. 27.102 / 57. 27.102 libavdevice 57. 0.101 / 57. 0.101 libavfilter 6. 38.100 / 6. 38.100 libswscale 4. 0.100 / 4. 0.100 libswresample 2. 0.101 / 2. 0.101 libpostproc 54. 0.100 / 54. 0.100 Input #0, mpegts, from 'transformers.ts': Duration: 00:01:59.29, start: 0.578456, bitrate: 9015 kb/s Program 1 Stream #0:0[0x1e1]: Video: h264 (High) ([27][0][0][0] / 0x001B), yuvj420p(pc), 1920x1080 [SAR 1:1 DAR 16:9], Closed Captions, 29.97 fps, 29.97 tbr, 90k tbn, 59.94 tbc Stream #0:1[0x1e2]: Audio: ac3 ([129][0][0][0] / 0x0081), 48000 Hz, 5.1(side), fltp, 384 kb/s Output #0, h264, to 'out.h264': Metadata: encoder : Lavf57.27.102 Stream #0:0: Video: h264 ([27][0][0][0] / 0x001B), yuvj420p, 1920x1080 [SAR 1:1 DAR 16:9], q=2-31, 29.97 fps, 29.97 tbr, 29.97 tbn, 29.97 tbc Stream mapping: Stream #0:0 -> #0:0 (copy) Press [q] to stop, [?] for help frame= 3575 fps=0.0 q=-1.0 Lsize= 118242kB time=00:01:59.25 bitrate=8122.6kbits/s speed= 580x video:118291kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown
$ ffmpeg -i out.h264 ffmpeg version N-78869-gdd2ea5c Copyright (c) 2000-2016 the FFmpeg developers built with gcc 4.7 (SUSE Linux) configuration: --enable-gpl libavutil 55. 19.100 / 55. 19.100 libavcodec 57. 27.101 / 57. 27.101 libavformat 57. 27.102 / 57. 27.102 libavdevice 57. 0.101 / 57. 0.101 libavfilter 6. 38.100 / 6. 38.100 libswscale 4. 0.100 / 4. 0.100 libswresample 2. 0.101 / 2. 0.101 libpostproc 54. 0.100 / 54. 0.100 [h264 @ 0x3a8c280] Stream #0: not enough frames to estimate rate; consider increasing probesize Input #0, h264, from 'out.h264': Duration: N/A, bitrate: N/A Stream #0:0: Video: h264 (High), yuvj420p(pc), 1920x1080 [SAR 1:1 DAR 16:9], Closed Captions, 29.97 fps, 29.97 tbr, 1200k tbn, 59.94 tbc At least one output file must be specified
Change History (7)
comment:1 by , 7 years ago
comment:2 by , 3 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
It is actually possible, just like with primaries/trc/matrix OF THE SOURCE that is in prefix type (39 for HEVC) of SEI.
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.
ffmpeg -i input.mkv -c copy -bsf:v "filter_units=remove_types=6" output.mkv
Now, that is not perfect, since there may be other stuff in SEI.
Indeed, ffmpeg -i transformers_EIA608_H264.h264 -c copy -bsf:v trace_headers -f null -
will show last_payload_type_byte number 4 (that means ITU_T_T35) and itu_t_t35_country_code is 181, next 2 bytes are 49 then GA94 MKTAG,
[trace_headers @ 000002128da9cb00] 48 itu_t_t35_payload_byte[3] 01000111 = 71 [trace_headers @ 000002128da9cb00] 56 itu_t_t35_payload_byte[4] 01000001 = 65 [trace_headers @ 000002128da9cb00] 64 itu_t_t35_payload_byte[5] 00111001 = 57 [trace_headers @ 000002128da9cb00] 72 itu_t_t35_payload_byte[6] 00110100 = 52
and then 3. Just like here https://en.wikipedia.org/wiki/CEA-708#Picture_User_Data
https://github.com/FFmpeg/FFmpeg/blob/870bfe16a12bf09dca3a4ae27ef6f81a2de80c40/libavcodec/sei.h#L31
I suppose the same can be done for HEVC, it uses 39 SEI though.
follow-up: 4 comment:3 by , 3 years ago
Resolution: | fixed |
---|---|
Status: | closed → reopened |
comment:4 by , 3 years ago
Replying to Carl Eugen Hoyos:
So you seriously want the filter that will remove all GA94 T.35 packets?
follow-up: 6 comment:5 by , 3 years ago
The ticket asks for a way to remove closed-captions, and nothing more. It is a perfectly valid request; there may be sensitive data in the closed captions, for example.
This ticket should not be closed until there is a way to remove exactly closed-captions.
comment:6 by , 3 years ago
Replying to Nicolas George:
The ticket asks for a way to remove closed-captions, and nothing more. It is a perfectly valid request; there may be sensitive data in the closed captions, for example.
This ticket should not be closed until there is a way to remove exactly closed-captions.
As I said there is a way to do it by removing SEI. I suppose ffmpeg should be able to remove EVEN specifically GA94 T.35 SEI, but I do not know the command (HDR10+ metadata is also stored in T.35 AFAIK, so it will remove that too, so a better narrow command is needed, I will admot as such).
comment:7 by , 3 years ago
And also may be interesting to implement this: https://superuser.com/questions/1356674/how-to-change-offset-of-eia-608-subtitles-in-an-mp4
I'm very surprised to see that this feature does not exist in ffmpeg. I was almost sure I could do that with ffmpeg so I was looking to docs to see how to do that. Then found out it's actually not possible.
I found link to this issue in some forums where other people were asking how to do this in ffmpeg. So it's something that people actually need and ask around.
No response to this issue for years since it was reported. So looks like no hope to see it implemented :(
I really need this function so badly, would appreciate a lot if any dev interested in implementing it :\