使用FFmpeg

时间:2018-02-27 13:21:24

标签: c ffmpeg video-streaming rtp

我需要一些正在处理的项目的帮助。目前,我正在尝试实现一个应该通过RTP协议接收视频流的程序,但我似乎无法找到解决它无法正常工作的原因。

我的计划到目前为止:

#include <stdio.h>
#include <libavformat/avformat.h>
#include <libswscale/swscale.h>

#define HOST "127.0.0.1"
#define PORT "20000"
#define NETWORK_ADDRESS "rtp://@"HOST":"PORT

int main()
{
    /** Register all muxers, demuxers and üprotocolls*/
    av_register_all();
    /** Global initialization of network protocolls */
    avformat_network_init();

    /** Open video file incoming from newtwork */
    AVFormatContext *pFormatCtxt = NULL;
    av_dict_set(&pFormatCtxt, "protocol_whitelist", "rtp", 0);
    if ( avformat_open_input( &pFormatCtxt, "stream.sdp", NULL, NULL ) != 0 )
        return -1;

    printf("Video file opened.\n");

    /** Retrieve stream information */
    if( avformat_find_stream_info( pFormatCtxt, NULL ) < 0 )
    return -1;
    .
    .
    .
}

使用终端命令生成.sdp文件:

 ffmpeg -re -i GoP2_output_10fps.avi -vn -ac 1 -c:a copy -f rtp rtp://127.0.0.1:20000 > stream.sdp

根据这些说明here,我得到以下内容:

v=0
o=- 0 0 IN IP4 127.0.0.1
s=No Name
c=IN IP4 127.0.0.1
t=0 0
a=tool:libavformat 57.83.100
m=video 20000 RTP/AVP 96
b=AS:2418
a=rtpmap:96 MP4V-ES/90000
a=fmtp:96 profile-level-id=1;    config=000001B001000001B58913000001000000012000C48D8800553284A01443000001B24C61766335362E36302E313030

要使用此SO讨论here中使用av_dict_set(&pFormatCtxt, "protocol_whitelist", "rtp", 0)的RTP协议列入白名单。

现在白名单后,程序执行在avformat_open_input()函数调用后停止并输出分段错误。 我理解这个错误意味着我试图访问我不应该访问的内存,但我不明白为什么会发生这种情况以及如何从这里开始。

由于我对ffmpeg这个话题很陌生并且自己找不到解决方案,我希望有人知道他们的方式能为我提供一些帮助吗?

我的操作系统是:Ubuntu 16.04

0 个答案:

没有答案