srt 音视频数据是基于mpegts 封装的,ffmpeg 数据流程
1. mpegts 封装格式会后面系列文章中讲叙,在ffmpeg 中的封装实现接口如下:mpegtsenc.c
AVOutputFormat ff_mpegts_muxer = {
.name = "mpegts",
.long_name = NULL_IF_CONFIG_SMALL("MPEG-TS (MPEG-2 Transport Stream)"),
.mime_type = "video/MP2T",
.extensions = "ts,m2t,m2ts,mts",
.priv_data_size = sizeof(MpegTSWrite),
.audio_codec = AV_CODEC_ID_MP2,
.video_codec = AV_CODEC_ID_MPEG2VIDEO,
.init = mpegts_init,
.write_packet = mpegts_write_packet,
.write_trailer = mpegts_write_end,
.deinit = mpegts_deinit,
.check_bitstream = mpegts_check_bitstream,
.flags = AVFMT_ALLOW_FLUSH | AVFMT_VARIABLE_FPS | AVFMT_NODIMENSIONS,
.priv_class = &mpegts_muxer_class,
};
解封封装:FFmpeg-n4.3.3/libavformat/mpegts.c
AVInputFormat ff_mpegts_demuxer = {
.name = "mpegts",
.long_name = NULL_IF_CONFIG_SMALL("MPEG-TS (MPEG-2 Transport Stream)"),
.priv_data_size = sizeof(MpegTSContext),
.read_probe = mpegts_probe,
.read_header = mpegts_read_header,
.read_packet = mpegts_read_packet,
.read_close = mpegts_read_close,
.read_timestamp = mpegts_get_dts,
.flags = AVFMT_SHOW_IDS | AVFMT_TS_DISCONT,
.priv_class = &mpegts_class,
};
srt 协议实现: ffmpeg 主要调用libsrt 实现srt 与服务器交互并实现音视频封及网络发送:
后面系列文章对srt 分析:
const URLProtocol ff_libsrt_protocol = {
.name = "srt",
.url_open = libsrt_open,
.url_read = libsrt_read,
.url_write = libsrt_write,
.url_close = libsrt_close,
.url_get_file_handle = libsrt_get_file_handle,
.priv_data_size = sizeof(SRTContext),
.flags = URL_PROTOCOL_FLAG_NETWORK,
.priv_data_class = &libsrt_class,
};