我使用ffmpeg H264编码,然后输出RTSP流。当我初始化时,我遇到了一些问题。我通过avio_open2函数打开输出地址时,返回错误-1330794744,协议(protocol)无效。我在哪里设置错误?
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;
}
最佳答案
与将RTMP定义为基于FLV的纯协议(protocol)不同,RTSP既是一种格式,又是一种协议(protocol)。 FFmpeg 在分配输出上下文时会自动创建 io 上下文,所以你不需要再手动调用 avio_open 了。
只需评论 avio_open2,它应该可以正常工作。
关于c - ffmpeg avio_open2() 无法打开输出 rtsp 流,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49168678/