用于音频流的RTP服务器

时间:2013-10-23 08:58:19

标签: c++ visual-c++ ffmpeg rtp

我正处于我的项目中,我正在尝试使用VC ++中的ffmpeg通过RTP发送音频数据。 但我无法做到这一点。 我的启动代码是:

setRTPOutputAddr("127.0.0.1");
    setRTPOutputPort(9985);
    av_register_all();
    avformat_network_init();
    formatCtx= avformat_alloc_context();

    //av_dump_format(formatCtx,0,"rtp",1);
            avio_open_dyn_buf(&ioctx);
            avio_open(&formatCtx->pb, "rtp", AVIO_FLAG_WRITE);
            //av_dump_format(formatCtx,0,"rtp",1);
            formatCtx->pb = ioctx;

            rtpCtx = avformat_alloc_context();
            rtpCtx->oformat = av_guess_format("rtp",0,0);
            AVStream *fakeVideo = 0;
            fakeVideo = avformat_new_stream(rtpCtx,0);
            avcodec_get_context_defaults3(fakeVideo->codec, NULL);
            fakeVideo->codec->codec_id = AV_CODEC_ID_MPEG2TS;
            rtpCtx->audio_codec_id = AV_CODEC_ID_NONE;
            rtpCtx->video_codec_id = AV_CODEC_ID_MPEG2TS;
            // avformat_write_header(rtpCtx,0);

            char *url = new char[1024];
            sprintf(url,"rtp://%s:%d",rtpOutputAddr,rtpOutputPort);
            printf("will output to url:%s\n",url);
            avio_open(&rtpCtx->pb,url,AVIO_FLAG_WRITE);
            avformat_write_header(rtpCtx, NULL);
            delete url;


            if (avio_open(&formatCtx->pb, "rtp", AVIO_FLAG_WRITE) < 0)
            {
                    fprintf(stderr, "Could not open '%s'\n", formatCtx->filename);
        return -1;
    }
            else
            {

            printf("succeed \n");
            }


Error Here:    avformat_write_header(formatCtx, NULL); //program Crashes

有人知道我在哪里做错了吗?

谢谢!

0 个答案:

没有答案