[Libav-user] RTP server for audio stream
Robert Schmidt
rob.f.schmidt86 at gmail.com
Tue Oct 29 14:19:30 CET 2013
On Wed, Oct 23, 2013 at 8:52 AM, Netcoder1989
<sachinrajput1989 at outlook.com> wrote:
> I'm in the mid of my project where I'm trying to send the audio data over RTP
> using ffmpeg in VC++.
> but I'm unable to do that.:
> setRTPOutputAddr("192.168.100.48");
> 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");
> }
>
>
> avformat_write_header(formatCtx, NULL);
> Getting error here
>
>
> Do any one having any idea why my program crashes here.
Without more information on the type of crash, it's hard to say. I
suspect the issue may be that you don't associate any output format,
streams, etc. with formatCtx, only with rtpCtx. I'm guessing that
avformat_write_header() is attempting to access some part of the
formatCtx structure and encountering an unexpected NULL pointer. If
you run the code under a debugger, you should be able to determine
exactly what field is being accessed and the cause of your crash.
Rob
More information about the Libav-user
mailing list