m0_61770108 2024-07-08 15:15 采纳率: 13.5%
浏览 5
已结题

FFmpeg中使用av_seek_frame()回退报错

FFmpeg中使用av_seek_frame()回退报错
使用场景:比如正在写入第30秒的视频,使用av_seek_frame跳转到第10秒再进行写入
报错如下:
[rtsp @ 000002532a4e9040] Application provided invalid, non monotonically increasing dts to muxer in stream 1: 14204959 >= 13978655

  • 写回答

3条回答 默认 最新

  • 百锦再@新空间代码工作室 全栈领域优质创作者 2024-07-08 15:15
    关注

    Gpt辅助回答,我来为你把关

    // 示例代码
    AVFormatContext *formatCtx;
    AVStream *videoStream;
    AVCodecContext *codecCtx;
    AVCodec *codec;

    // 初始化FFmpeg av_register_all();
    avformat_network_init();

    // 打开输入流 avformat_open_input(&
    formatCtx, "
    input.mp4"
    , NULL, NULL);
    avformat_find_stream_info(formatCtx, NULL);

    // 寻找视频流 videoStream = av_find_best_stream(formatCtx, AVMEDIA_TYPE_VIDEO, -1, -1, &
    codec, 0);

    // 初始化解码器 codecCtx = avcodec_alloc_context3(codec);
    avcodec_parameters_to_context(codecCtx, videoStream->
    codecpar);
    avcodec_open2(codecCtx, codec, NULL);

    // 找到要跳转到的时间 int64_t timestamp = 10 * AV_TIME_BASE;
    // 10秒 int streamIndex = videoStream->
    index;

    // 跳转 av_seek_frame(formatCtx, streamIndex, timestamp, AVSEEK_FLAG_BACKWARD);

    // 在这里继续写入视频

    在使用av_seek_frame时,需要确保传入的时间戳是递增的,也就是说要确保跳转到的时间戳比当前时间戳要小。如果时间戳不是递增的,就会出现类似“Application provided invalid, non monotonically increasing dts to muxer”这样的错误。因此在使用av_seek_frame前,需要先判断要跳转的时间是否合法,确保时间戳是递增的。


    有问题你别着急,评论留言都可以,看到马上就回复,尽量及时补充齐
    评论 编辑记录

报告相同问题?

问题事件

  • 已结题 (查看结题原因) 7月9日
  • 创建了问题 7月8日

悬赏问题

  • ¥15 Opencv(C++)异常
  • ¥15 VScode上配置C语言环境
  • ¥15 汇编语言没有主程序吗?
  • ¥15 这个函数为什么会爆内存
  • ¥15 无法装系统,grub成了顽固拦路虎
  • ¥15 springboot aop 应用启动异常
  • ¥15 matlab有关债券凸性久期的代码
  • ¥15 lvgl v8.2定时器提前到来
  • ¥15 qtcp 发送数据时偶尔会遇到发送数据失败?用的MSVC编译器(标签-qt|关键词-tcp)
  • ¥15 cam_lidar_calibration报错