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