0

我正处于项目的中期,我试图在 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

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

谢谢!

4

0 回答 0