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

标签 c ffmpeg h.264

我使用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/

相关文章:

Android ffmpeg 应用视频效果需要时间

c++ - QT多媒体,H264电影黑屏

c++ - 'C' 程序 : multidimensional array issue

c++ - LPCSTR 没有 'long' 并且 UINT_PTR 没有指针?

php - ffmpeg 将任何用户视频文件转换为在手机上运行 h264 mp4

node.js - FFMPEG : Conversion Failed Error when trying trying to create facebook stream from image and audio?

winforms - DirectShow/WinForms 中的硬件加速视频

video - H.264 级别,适用于 1920x1080 60 视频

c - C99 标准中的默认参数提升

c - 基本C,输出不正确