Preserve CEA-708 Captions When Transcoding with FFmpeg
When transcoding video files using FFmpeg, preserving CEA-708 closed captions is crucial for maintaining accessibility and regulatory compliance. This article provides a straightforward guide on how to carry over, copy, and write CEA-708 captions during the transcoding process, ensuring your subtitle data remains intact in the output file whether it is embedded in the video stream or stored as a separate track.
Preserving Embedded CEA-708 Captions (A53 Data)
In many broadcast formats, CEA-708 captions are embedded directly inside the video stream as A53 user data. When you transcode the video (for example, re-encoding from MPEG-2 to H.264 or H.265), this metadata can be discarded by default.
To preserve embedded captions when transcoding using the
libx264 or libx265 encoders, you must enable
the -a53cc flag.
Command Example:
ffmpeg -i input.mp4 -c:v libx264 -a53cc 1 -c:a copy output.mp4-c:v libx264: Transcodes the video to H.264.-a53cc 1: Explicitly instructs the encoder to read the A53 closed captions from the input video and write them into the output video’s SEI (Supplemental Enhancement Information) user data.-c:a copy: Copies the audio stream without re-encoding to preserve original quality and save processing time.
Preserving Captions as a Separate Subtitle Stream
If your CEA-708 captions are stored as a dedicated subtitle track within a container (such as an MXF or MKV file) rather than embedded in the video packets, you must ensure FFmpeg maps and copies that stream to the output.
Command Example:
ffmpeg -i input.mxf -map 0 -c:v libx264 -c:a copy -c:s copy output.mkv-map 0: Selects all streams (video, audio, and subtitles) from the input file. By default, FFmpeg only selects one video and one audio stream.-c:s copy: Copies the subtitle stream data stream exactly as-is without attempting to re-encode it.
Verifying the Output
To confirm that the CEA-708 captions were successfully preserved in
the transcoded file, use ffprobe to inspect the
streams:
ffprobe -loglevel error -show_entries stream=codec_name,properties -of default=noprint_wrappers=1 output.mp4Look for the presence of a subtitle stream, or check if the video stream properties indicate the presence of closed captions. Alternatively, you can play the output video in a media player like VLC and check the subtitle menu to verify the captions display correctly.