我正在接收音频和视频RTP数据通过套接字连接。现在,我想将视频和音频RTP数据合并到MP4文件中。我怎样才能做到这一点?我是否需要将视频RTP分别保存到h264和音频RTP中,然后将它们合并到MP4文件中?或者可以将音视频RTP直接合并到MP4文件中?
提前感谢!
发布于 2015-07-04 14:15:12
您不需要创建单独的音频和视频文件来将它们修改为MP4 (或任何容器)。但是在您的程序中,您需要将H.264和PCMU帧从RTP数据包中提取出来,并将它们传输到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
https://stackoverflow.com/questions/31205505
复制相似问题