ffmpeg avio_open2()无法打开输出rtsp流

问题描述 投票:0回答:1

我使用ffmpeg H264编码,然后输出RTSP流。初始化时遇到一些问题。当我通过avio_open2函数打开输出地址时,我返回错误-1330794744,这是无效的协议。我在哪里设置错误?

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;
}
c ffmpeg h.264
1个回答
0
投票

与RTMP定义为基于FLV的纯协议不同,RTSP同时是一种格式和协议。 FFmpeg在分配输出上下文时将自动创建io上下文,因此您不再需要手动调用avio_open。

只需评论avio_open2,它应该可以正常工作。

© www.soinside.com 2019 - 2024. All rights reserved.