|
|
@ -69,21 +69,31 @@ bool Cffmpeg_decode::open_input_file() {
|
|
|
|
//========================解码============================
|
|
|
|
//========================解码============================
|
|
|
|
AVDictionary *avdic = NULL;
|
|
|
|
AVDictionary *avdic = NULL;
|
|
|
|
// 如果设置失败,则设置UDP传输
|
|
|
|
// 如果设置失败,则设置UDP传输
|
|
|
|
if (m_rtsp_transport == "udp")
|
|
|
|
// if (m_rtsp_transport == "udp")
|
|
|
|
av_dict_set(&avdic, "rtsp_transport", "udp", 0);
|
|
|
|
// av_dict_set(&avdic, "rtsp_transport", "udp", 0);
|
|
|
|
else
|
|
|
|
// else
|
|
|
|
av_dict_set(&avdic, "rtsp_transport", "tcp", 0);
|
|
|
|
// av_dict_set(&avdic, "rtsp_transport", "tcp",
|
|
|
|
|
|
|
|
// 0);//注:设置tcp会导致吊舱拉流中断
|
|
|
|
|
|
|
|
// av_dict_set(&avdic, "rtsp_transport", "udp", 0);
|
|
|
|
// 设置缓存大小,1080p可将值调大
|
|
|
|
// 设置缓存大小,1080p可将值调大
|
|
|
|
av_dict_set(&avdic, "buffer_size", "4096000", 0);
|
|
|
|
av_dict_set(&avdic, "buffer_size", "2048000", 0);
|
|
|
|
// 设置超时断开连接时间,单位微秒//listen_timeout
|
|
|
|
// 设置超时断开连接时间,单位微秒//listen_timeout
|
|
|
|
// av_dict_set(&avdic, "listen_timeout", "200000", 0);
|
|
|
|
// av_dict_set(&avdic, "listen_timeout", "200000", 0);
|
|
|
|
av_dict_set(&avdic, "stimeout", "3000000", 0); // 设置超时3秒
|
|
|
|
av_dict_set(&avdic, "stimeout", "5000000", 0); // 设置超时5秒
|
|
|
|
av_dict_set(&avdic, "max_delay", "300000", 0); // 设置最大时延300ms
|
|
|
|
av_dict_set(&avdic, "max_delay", "300000", 0); // 设置最大时延300ms
|
|
|
|
av_dict_set(&avdic, "tune", "zerolatency", 0); // 实时编码
|
|
|
|
av_dict_set(&avdic, "tune", "zerolatency", 0); // 实时编码
|
|
|
|
av_dict_set(&avdic, "preset", "faster", 0); // ultrafast
|
|
|
|
av_dict_set(&avdic, "preset", "faster", 0); // ultrafast
|
|
|
|
av_dict_set(&avdic, "threads", "auto", 0); // 自动开启线程数
|
|
|
|
av_dict_set(&avdic, "threads", "auto", 0); // 自动开启线程数
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// av_dict_set(&avdic, "rtsp_flags", "prefer_tcp", 0); // 保持TCP连接
|
|
|
|
|
|
|
|
// av_dict_set(&avdic, "timeout", "500000", 0); // 超时时间设置为500ms
|
|
|
|
|
|
|
|
// av_dict_set(&avdic, "probesize", "50000000", 0); // 增加探针大小,1MB
|
|
|
|
|
|
|
|
// av_dict_set(&avdic, "analyzeduration", "5000000", 0); //
|
|
|
|
|
|
|
|
// 增加分析持续时间,5秒
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 打开输入流之前,设置非阻塞模式
|
|
|
|
inputFormatCtx->flags |= AVFMT_FLAG_NONBLOCK;
|
|
|
|
inputFormatCtx->flags |= AVFMT_FLAG_NONBLOCK;
|
|
|
|
|
|
|
|
// inputFormatCtx->probesize = 50000000;
|
|
|
|
|
|
|
|
|
|
|
|
// 打开输入流
|
|
|
|
// 打开输入流
|
|
|
|
if (avformat_open_input(&inputFormatCtx, _url.toUtf8().data(), NULL, &avdic) <
|
|
|
|
if (avformat_open_input(&inputFormatCtx, _url.toUtf8().data(), NULL, &avdic) <
|
|
|
@ -186,8 +196,17 @@ void Cffmpeg_decode::run() {
|
|
|
|
// 推流使用
|
|
|
|
// 推流使用
|
|
|
|
firstDts = AV_NOPTS_VALUE; // 初始化第一帧的DTS
|
|
|
|
firstDts = AV_NOPTS_VALUE; // 初始化第一帧的DTS
|
|
|
|
startTime = av_gettime();
|
|
|
|
startTime = av_gettime();
|
|
|
|
|
|
|
|
int ret11 = 0;
|
|
|
|
// 读取数据包
|
|
|
|
// 读取数据包
|
|
|
|
while (av_read_frame(inputFormatCtx, inputPacket) >= 0) {
|
|
|
|
while ((ret11 = av_read_frame(inputFormatCtx, inputPacket)) >= 0) {
|
|
|
|
|
|
|
|
// ret = av_read_frame(inputFormatCtx, inputPacket);
|
|
|
|
|
|
|
|
// if (ret < 0 || ret == AVERROR(EAGAIN) || ret == AVERROR_EOF) {
|
|
|
|
|
|
|
|
// qDebug() << "ret:" << QString::number(ret);
|
|
|
|
|
|
|
|
// av_packet_unref(inputPacket);
|
|
|
|
|
|
|
|
// frm_cnt++;
|
|
|
|
|
|
|
|
// continue;
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
if (IsstopPlay) {
|
|
|
|
if (IsstopPlay) {
|
|
|
|
qDebug() << "video play stop";
|
|
|
|
qDebug() << "video play stop";
|
|
|
|
break;
|
|
|
|
break;
|
|
|
@ -295,6 +314,9 @@ void Cffmpeg_decode::run() {
|
|
|
|
if (m_saveVideoFlag) {
|
|
|
|
if (m_saveVideoFlag) {
|
|
|
|
saveDone();
|
|
|
|
saveDone();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ret11 == AVERROR_EOF && errno == 0) {
|
|
|
|
|
|
|
|
qDebug() << "ret:";
|
|
|
|
|
|
|
|
}
|
|
|
|
// QCoreApplication::processEvents();
|
|
|
|
// QCoreApplication::processEvents();
|
|
|
|
qDebug() << "All video play done";
|
|
|
|
qDebug() << "All video play done";
|
|
|
|
}
|
|
|
|
}
|
|
|
|