Reputation: 13
I use ffmpeg H264 encoding, and then output the RTSP flow. When I initialize, I encounter some problems. When I open the output address through the avio_open2 function, I return the error -1330794744, which is invalid agreement. Where am I set the error?
av_register_all();
avformat_network_init();
avformat_alloc_output_context2(&ofmt_ctx, NULL, "rtsp", rtsp_url);
if (!ofmt_ctx)
{
printf("Could not deduce output format from file extension: using MPEG.\n");
avformat_alloc_output_context2(&ofmt_ctx, NULL, "mpeg", rtsp_url);
}
if (!ofmt_ctx) return;
this->out_fmt = ofmt_ctx->oformat;
if (!this->out_fmt)
{
printf("Error creating outformat.\n");
return;
}
video_st = add_stream(ofmt_ctx, &video_codec, CODEC_ID_H264, rate);
if (video_st)
{
open_video(ofmt_ctx, video_codec, video_st);
}
int ret = avio_open2(&ofmt_ctx->pb, "rtsp://127.0.0.1:8854/live.sdp", AVIO_FLAG_WRITE, NULL, NULL);
if (ret < 0)
{
printf("Could not open outfile '%s'.", rtsp_url);
return;
}
Upvotes: 0
Views: 3093
Reputation: 33
Unlike RTMP defined as a pure protocol based on FLV, RTSP is a format and a protocol meanwhile. FFmpeg will automatically create the io context when allocating output context, so you don't need to call avio_open manually anymore.
Just comment avio_open2, and it should work fine.
Upvotes: 1