Adding CEA Captions To MP4 Stream.
Create an srt file
1 00:00:00,000 --> 00:00:10,000 Random sentence 1 2 00:00:10,000 --> 00:00:20,000 Random sentence 2 3 00:00:20,000 --> 00:00:30,000 Random sentence 3 ... 54 00:08:50,000 --> 00:09:00,000 Random sentence 54
Convert the .srt file to .scc
pip install pycaption
Write a simple python script to make the conversion.
import sys from pycaption import SRTReader, SCCWriter def convert_srt_to_scc(input_srt, output_scc): with open(input_srt, 'r') as srt_file: srt_content = srt_file.read() captions = SRTReader().read(srt_content) scc_content = SCCWriter().write(captions) with open(output_scc, 'w') as scc_file: scc_file.write(scc_content) if __name__ == "__main__": if len(sys.argv) != 3: print("Usage: python srt_to_scc.py input.srt output.scc") sys.exit(1) input_srt = sys.argv[1] output_scc = sys.argv[2] convert_srt_to_scc(input_srt, output_scc)
Convert the file with.
python srt_to_scc.py input.srt output.scc
Now use ffmpeg to add the captions to the mp4.
ffmpeg -i BigBuckBunny.mp4 -i output.scc -c copy -scodec mov_text -metadata:s:s:0 language=eng output.mp4
Done