首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用ffmpeg拉取rtsp视频流,然后直接推送rtmp流,但出现了分段错误

使用ffmpeg拉取rtsp视频流,然后直接推送rtmp流,但出现了分段错误
EN

Stack Overflow用户
提问于 2020-12-22 16:46:53
回答 1查看 46关注 0票数 0

使用ffmpeg获取rtsp视频流。视频流的分辨率为2688*1520,帧率为25fps。最简单的流程是使用ffmpeg拉取rtsp视频流,然后直接推送rtmp流,但在推流过程中出现了流分割故障,代码如下:

代码语言:javascript
复制
    AVPacket packet;
    av_init_packet(&packet);
    int start_time = 0;
    start_time=av_gettime();
    int frame_index = 0;
    while(1){
            // AVPacket packet;

            AVStream* rtsp_stream;
            AVStream* rtmp_stream;
            ret_f = av_read_frame(av_fc_input, &packet);
            if (ret_f < 0)
            {
                    break;
            }
            INFO_LOG("av_read_frame to packet success");
            rtsp_stream = av_fc_input->streams[packet.stream_index];
            rtmp_stream = av_fc_output->streams[packet.stream_index];

            if(rtsp_stream->codecpar->codec_type == AVMEDIA_TYPE_VIDEO){
                    AVRational time_base = rtsp_stream->time_base;
                    AVRational time_base_q = AV_TIME_BASE_Q;
                    int64_t pts_time = av_rescale_q(packet.dts, time_base, time_base_q);
                    int64_t now_time = av_gettime() - start_time;
                    if(pts_time > now_time)
                            av_usleep(pts_time - now_time);
            }
            INFO_LOG("get input and output");

            packet.pts = av_rescale_q_rnd(packet.pts, rtsp_stream->time_base, rtmp_stream->time_base, AVRounding(AV_ROUND_NEAR_INF|AV_ROUND_PASS_MINMAX));
            packet.dts = av_rescale_q_rnd(packet.dts, rtsp_stream->time_base, rtmp_stream->time_base, AVRounding(AV_ROUND_NEAR_INF |AV_ROUND_PASS_MINMAX));
            packet.duration = av_rescale_q(packet.duration, rtsp_stream->time_base, rtmp_stream->time_base);

            packet.pos = -1;

            INFO_LOG("packet parameter edit success");
            if(packet.stream_index == video_stream){
                    ERROR_LOG("Send %d video frames to out URL", frame_index);
                    ++frame_index;
            }

            INFO_LOG("frame index ++ success");

            ret_f = av_interleaved_write_frame(av_fc_output, &packet);
            if (ret_f < 0)
            {
                    ERROR_LOG("Error muxing packers");
                    break;
            }

            INFO_LOG("write packet to av_fc_output success");

            av_packet_unref(&packet);
            // usleep(40*1000);
    }

为什么会发生段故障?是不是分辨率太大了?有什么解决方案吗?调整图像大小?谢谢!

EN

回答 1

Stack Overflow用户

发布于 2020-12-22 16:51:09

另外,当我使用摄像头的子流时,这个问题不会发生。子流对应的分辨率为704*576,帧率为25fps。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65405623

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档