[英]Merge audio and video RTP data into mp4 file
我正在通过套接字连接接收音频和视频 RTP 数据。 现在我想将视频和音频 RTP 数据合并到 MP4 文件中。 我怎样才能做到这一点? 我是否需要将视频 RTP 分别保存到 h264 和音频 RTP 到 PCMU 中,然后将它们合并到 MP4 文件中? 或者是否可以直接将音视频 RTP 合并到 MP4 文件中?
提前致谢!
您不需要创建单独的音频和视频文件来将它们混合到 MP4(或任何容器)。 但是在您的程序中,您需要从 RTP 数据包中制作 H.264 和 PCMU 帧并将它们传输到 FFMPEG。
所以总而言之,你程序的伪代码应该是这样的,
Main {
//Setup RTP receiver
//Configure MP4 Muxer of FFMPEG (set input and oputput format), your input is H.264 and PCMU and output is MP4
//avformat_alloc_output_context2
//avformat_new_stream
//Create Thread1 to read audio RTP packets
//Create Thread2 to read video RTP packets
//Complete writing MP4 file
//av_write_trailer
}
Thread1 ()
{
//Receive audio RTP packets
//Form an Audio frame
//Send the frame to muxer av_interleaved_write_frame
}
Thread1 ()
{
//Receive video RTP packets
//Form a video frame
//Send the frame to muxer av_interleaved_write_frame
}
希望这些有帮助。 ffmpeg 源代码中提供的 Muxer 示例会有所帮助。 https://github.com/FFmpeg/FFmpeg/blob/master/doc/examples/muxing.c
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.