<div dir="ltr"><div>    i'm trying capture rtsp stream (h264) to local file and there is 3 problem.</div><div>1) sometimes (usually at the stream starts) i got pts,dts values of packet incorrect (non monotonically increasing)</div><div>2) output file has no seeking information</div><div>3) output file speed seems 1.5x lower than rtsp source</div><div>any avice please<br></div><div></div><div><br></div><div>    AVFormatContext* inFormatCtx = avformat_alloc_context();<br>    if (avformat_open_input(&inFormatCtx,m_RTSPPath.toLocal8Bit().data(),nullptr,nullptr))  return;<br></div><div>    if (avformat_find_stream_info(inFormatCtx,nullptr) < 0)  return;<br><br>    int videoStreamIdx = av_find_best_stream(inFormatCtx,AVMEDIA_TYPE_VIDEO,-1,-1,nullptr,0);<br>    if (videoStreamIdx == -1) return;<br><br>    AVStream *inVideoStream = inFormatCtx->streams[videoStreamIdx];<br>    av_dump_format(inFormatCtx,videoStreamIdx,nullptr,0);<br>    av_read_play(inFormatCtx);<br><br>    AVFormatContext *outFormatCtx = nullptr;<br>    QString filename = m_archivePath + "/" + QDateTime::currentDateTime().toString(m_dateTimeFormat);<br><br>    if (avformat_alloc_output_context2(&outFormatCtx,nullptr,"avi",filename.toLocal8Bit().data()))  return;<br><br>    AVStream *outVideoStream = avformat_new_stream(outFormatCtx,nullptr);</div><div></div><div>    if (avcodec_parameters_copy(outVideoStream->codecpar,inVideoStream->codecpar) < 0)  return;<br><br>    if (!(outFormatCtx->oformat->flags & AVFMT_NOFILE) &&<br>       (avio_open(&outFormatCtx->pb,filename.toLocal8Bit().data(),AVIO_FLAG_WRITE)<0)) return;<br></div><div><br>    if (avformat_write_header(outFormatCtx,nullptr) < 0) return;<br></div><div>   <br>    AVPacket packet;<br>    int count = 10000;<br>    while (count--) {<br>        if (av_read_frame(inFormatCtx,&packet) < 0) continue;<br><div></div><div><br></div>        if (videoStreamIdx != packet.stream_index) {<br>            av_packet_unref(&packet);<br>            continue;<br>        }<br><br>        qInfo()<<"<<<<<<<"<<packet.stream_index<<packet.pts<<packet.dts;<br><br>        packet.pts = av_rescale_q_rnd(packet.pts,<br>                                      inVideoStream->time_base,<br>                                      outVideoStream->time_base,<br>                                      static_cast<AVRounding>(AV_ROUND_NEAR_INF|AV_ROUND_PASS_MINMAX));<br>        packet.dts = av_rescale_q_rnd(packet.dts,<br>                                      inVideoStream->time_base,<br>                                      outVideoStream->time_base,<br>                                      static_cast<AVRounding>(AV_ROUND_NEAR_INF|AV_ROUND_PASS_MINMAX));<br>        packet.duration = av_rescale_q(packet.duration,<br>                                       inVideoStream->time_base,<br>                                       outVideoStream->time_base);<br>        packet.stream_index = outVideoStream->id;<br><br>        qInfo()<<">>>>>>>"<<packet.stream_index<<packet.pts<<packet.dts;<br><br>        if (av_interleaved_write_frame(outFormatCtx,&packet) < 0) continue;<br>        }<br>        av_packet_unref(&packet);<br>    }<br><br>    av_write_trailer(outFormatCtx);</div></div>