首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Libavformat记录RTP流太快(FPS太高)

Libavformat记录RTP流太快(FPS太高)
EN

Stack Overflow用户
提问于 2022-04-12 12:41:44
回答 1查看 63关注 0票数 0

我正在尝试用libavformat记录一个RTP流,但是录制的视频的FPS非常高,我得到了数千个FPS,如果不是10000。我试图将FPS设置为30,做了以下修改:

代码语言:javascript
复制
AVFormatContext *src; // Assume src is set here to demuxer's context
AVStream *source_stream = src->streams[i];
AVStream *dest_stream = avformat_new_stream(dest, NULL); // dest is muxer's context here
const AVCodec *pCodec = avcodec_find_decoder(source_stream->codecpar->codec_id);
AVCodecContext *avctx = avcodec_alloc_context3(pCodec);
avctx->time_base = av_make_q(1, 30000);
avcodec_parameters_to_context(avctx, source_stream->codecpar);
avcodec_parameters_from_context(dest_stream->codecpar, avctx);
dest_stream->sample_aspect_ratio = source_stream->sample_aspect_ratio;
dest_stream->time_base = avctx->time_base;
dest_stream->avg_frame_rate = av_make_q(30, 1);
dest_stream->r_frame_rate = source_stream->r_frame_rate;
dest_stream->disposition = source_stream->disposition;

然后,在录制阶段,在读取新数据包时执行以下操作:

代码语言:javascript
复制
packet->pts = av_rescale_q(packet->pts, src_stream->time_base, dest_stream->time_base);
packet->dts = av_rescale_q(packet->dts, src_stream->time_base, dest_stream->time_base);
packet->duration = dest_stream->time_base.den / dest_stream->time_base.num / dest_stream->avg_frame_rate.num * dest_stream->avg_frame_rate.den;
av_interleaved_write_frame(dest, packet);

我得到的错误日志是以重复的方式获得的:

代码语言:javascript
复制
[mp4 @ 0x7fc514001d00] Application provided duration: ... / timestamp: ... is out of range for mov/mp4 format
[mp4 @ 0x7fc514001d00] pts has no value

我使用的libav版本如下:

代码语言:javascript
复制
ffmpeg version 4.3.3 Copyright (c) 2000-2021 the FFmpeg developers
  built with gcc 7 (Ubuntu 7.2.0-8ubuntu3)
  configuration:
  libavutil      56. 51.100 / 56. 51.100
  libavcodec     58. 91.100 / 58. 91.100
  libavformat    58. 45.100 / 58. 45.100
  libavdevice    58. 10.100 / 58. 10.100
  libavfilter     7. 85.100 /  7. 85.100
  libswscale      5.  7.100 /  5.  7.100
  libswresample   3.  7.100 /  3.  7.100

P.S:升级ffmpeg版本是行不通的。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-04-14 12:55:56

我做了如下修改,如前面提到的这里,现在它工作得很好:

代码语言:javascript
复制
packet.pts = av_rescale_q_rnd(packet.pts, in_stream->time_base, out_stream->time_base, AV_ROUND_NEAR_INF|AV_ROUND_PASS_MINMAX);
packet.dts = av_rescale_q_rnd(packet.dts, in_stream->time_base, out_stream->time_base, AV_ROUND_NEAR_INF|AV_ROUND_PASS_MINMAX);
packet.duration = av_rescale_q(packet.duration, in_stream->time_base, out_stream->time_base);
// https://ffmpeg.org/doxygen/trunk/structAVPacket.html#ab5793d8195cf4789dfb3913b7a693903
packet.pos = -1;
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71842936

复制
相关文章

相似问题

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