且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

合并的音频和视频RTP数据转换成MP4文件

更新时间:2023-01-18 15:48:10

您不需要创建单独的音频和视频文件,给他们混流为MP4(或容器)。但是,在你的程序,你需要做H.264和PCMU帧出RTP数据流,并将它们转移到FFMPEG。

You don't need to create separate audio and video files to mux them to MP4 (or any container). But in your program you need to make H.264 and PCMU frames out of the RTP packets and transfer them to FFMPEG.

因此​​,在总结,你的程序的伪code应该是这样的,

So in summary you program's pseudo code should look like this,

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 an Audio frame

    //Send the frame to muxer av_interleaved_write_frame
}

希望这些帮助。在ffmpeg的源$ C ​​$ C可MUXER例子会有所帮助。
https://github.com/FFmpeg/FFmpeg/blob/master /doc/examples/muxing.c