【发布时间】:2021-05-10 16:40:57
【问题描述】:
我正在编写软件来播放从 NVR 录制的视频。我已经完成了大部分工作,但还有一项功能允许用户更改播放速度,例如 0.5x、2x、4x、8x ...
我在互联网上搜索了一整天,仍然找不到任何建议。下面是我的摘要代码。
auto pFormatCtx = avformat_alloc_context();
av_dict_set_int(&opts, "rw_timeout", 5000000, 0);
av_dict_set_int(&opts, "tcp_nodelay", 1, 0);
av_dict_set_int(&opts, "stimeout", 10000000, 0);
av_dict_set(&opts, "user_agent", "Mozilla/5.0", 0);
av_dict_set(&opts, "rtsp_transport", "tcp", 0);
av_dict_set(&opts, "rtsp_flags", "prefer_tcp", 0);
av_dict_set_int(&opts, "buffer_size", BUFSIZE, 0);
int err = avformat_open_input(&pFormatCtx, fullRtspUri, NULL, &opts);
if(err < 0)
return;
err = avformat_find_stream_info(pFormatCtx, NULL);
if (err < 0)
return;
pFormatCtx->flags |= AVFMT_FLAG_NONBLOCK;
pFormatCtx->flags |= AVFMT_FLAG_DISCARD_CORRUPT;
pFormatCtx->flags |= AVFMT_FLAG_NOBUFFER;
av_dump_format(pFormatCtx, 0, fullRtspUri, 0);
int videoStreamInd = -1;
for (int i = 0; i < pFormatCtx->nb_streams; i++)
{
AVStream* stream = pFormatCtx->streams[i];
if (stream->codecpar->codec_type == AVMEDIA_TYPE_VIDEO)
{
if (videoStreamInd == -1)
{
videoStreamInd = i;
break;
}
}
}
if (videoStreamInd == -1)
return;
auto videoStream = pFormatCtx->streams[videoStreamInd];
isRunning = true;
while(isRunning)
{
ret = av_read_frame(pFormatCtx, avPacket);
if (ret < 0)
return;
if (avPacket->stream_index != videoStreamInd)
continue;
//Code for render process here............
}
我已通读此 NVR API 文档,看到支持 2x、4x 速度播放,如下所示
Play in 2× Speed:
PLAY rtsp://10.17.133.46:554/ISAPI/streaming/tracks/101?starttime=20170313T230652Z&endtime=20170314T025706Z RTSP/1.0
CSeq:6
Authorization: Digest username="admin",
realm="4419b66d2485",
nonce="a0ecd9b1586ff9461f02f910035d0486",
uri="rtsp://10.17.133.46:554/ISAPI/streaming/tracks/101?starttime=20170313T230652Z&endtime=20170314T025706Z",
response="fb986d385a7d839052ec4f0b2b70c631"
Session:2049381566;timeout=60
Scale:2.000
User-Agent:NKPlayer-1.00.00.081112
RTSP/1.0 200 OK
CSeq: 6
Session: 2049381566
Scale: 2.000
RTP-Info: url=trackID=1;seq=1,url=trackID=2;seq=1
Date: Tue, Mar 14 2017 10:57:24 GMT
如何以 0.5x、2x、4x ... 的速度播放 RTSP 视频? 在这种情况下可以帮助我的每个人,我都非常感激。
【问题讨论】:
-
问题是什么?什么实际上不起作用?
-
可能与我们最近几天讨论的这个问题重复here
-
@micha137:我还没有弄清楚如何以 0.5x、2x、4x 播放 RTSP 视频。
-
@SuRGeoNix:我认为搜索帧功能不是我想要的。谢谢!
标签: c++ ffmpeg rtsp-client