使用ffmpeg获取rtsp视频流。视频流的分辨率为2688*1520,帧率为25fps。最简单的流程是使用ffmpeg拉取rtsp视频流,然后直接推送rtmp流,但在推流过程中出现了流分割故障,代码如下:
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);
}为什么会发生段故障?是不是分辨率太大了?有什么解决方案吗?调整图像大小?谢谢!
发布于 2020-12-22 16:51:09
另外,当我使用摄像头的子流时,这个问题不会发生。子流对应的分辨率为704*576,帧率为25fps。
https://stackoverflow.com/questions/65405623
复制相似问题