ffmpeg重采样中swr_convert和swr_get_out_samples的用法

在做mux的时候关于重采样可以用fifo,或者audiofifo做缓存处理,当做demux的时候关于重采样就可以用到上面的swr_convert和swr_get_out_samples做配合处理。先看下这两个函数的注释:

[cpp] view plain copy

  1. /** Convert audio.
  2. *
  3. * in and in_count can be set to 0 to flush the last few samples out at the
  4. * end.
  5. *
  6. * If more input is provided than output space, then the input will be buffered.
  7. * You can avoid this buffering by using swr_get_out_samples() to retrieve an
  8. * upper bound on the required number of output samples for the given number of
  9. * input samples. Conversion will run directly without copying whenever possible.
  10. *
  11. * @param s         allocated Swr context, with parameters set
  12. * @param out       output buffers, only the first one need be set in case of packed audio
  13. * @param out_count amount of space available for output in samples per channel
  14. * @param in        input buffers, only the first one need to be set in case of packed audio
  15. * @param in_count  number of input samples available in one channel
  16. *
  17. * @return number of samples output per channel, negative value on error
  18. */
  19. int swr_convert(struct SwrContext *s, uint8_t **out, int out_count,
  20. const uint8_t **in , int in_count);

[cpp] view plain copy

  1. /**
  2. * Find an upper bound on the number of samples that the next swr_convert
  3. * call will output, if called with in_samples of input samples. This
  4. * depends on the internal state, and anything changing the internal state
  5. * (like further swr_convert() calls) will may change the number of samples
  6. * swr_get_out_samples() returns for the same number of input samples.
  7. *
  8. * @param in_samples    number of input samples.
  9. * @note any call to swr_inject_silence(), swr_convert(), swr_next_pts()
  10. *       or swr_set_compensation() invalidates this limit
  11. * @note it is recommended to pass the correct available buffer size
  12. *       to all functions like swr_convert() even if swr_get_out_samples()
  13. *       indicates that less would be used.
  14. * @returns an upper bound on the number of samples that the next swr_convert
  15. *          will output or a negative value to indicate an error
  16. */
  17. int swr_get_out_samples(struct SwrContext *s, int in_samples);

就说如果传入的nb_samles大于了传出的nb_samplse则SwrContext中会有缓存,会导致内存一直暴涨,解决方法,可以看如下代码:

没有缓存的重采样这么处理:

[cpp] view plain copy

  1. ret = swr_convert(swrcontext, pOutputFrame->data,pOutputFrame->nb_samples,
  2. (const uint8_t**)pInputFrame->data,pInputFrame->nb_samples);

有缓存的代码这么处理:

[cpp] view plain copy

  1. //如果还有缓存在swrcontext中,第二个参数要填写0才能获取到,缓存数据
  2. int fifo_size = swr_get_out_samples(swrcontext,0);
  3. if ( fifo_size >= pOutputFrame->nb_samples)
  4. {
  5. ret = swr_convert(swrcontext, pOutputFrame->data,pOutputFrame->nb_samples,
  6. NULL,0);
  7. }

即如果有缓存则先判断是否有缓存在里面,如果有则传入数据为空取出缓存。

ffmpeg重采样中swr_convert和swr_get_out_samples的用法相关推荐

  1. @ini_get php,php中get_cfg_var()和ini_get()的用法及区别_php技巧_脚本之家

    本文实例讲述了php中get_cfg_var()和ini_get()的用法及区别.分享给大家供大家参考.具体分析如下: php里get_cfg_var()和ini_get()都是取得配置值的函数,当你 ...

  2. java7 javascript引擎_Java7中脚本引擎的一般用法,共三种方法获得JavaScript引擎:名称、文件扩展名、MIME类型 | 学步园...

    package com.sino.java7; import javax.script.ScriptEngine; import javax.script.ScriptEngineManager; i ...

  3. Oracle中INSTR和SUBSTR的用法

    2019独角兽企业重金招聘Python工程师标准>>> Oracle中INSTR和SUBSTR的用法 Oracle中INSTR的用法: INSTR方法的格式为 INSTR(源字符串, ...

  4. python threading join_Python中threading模块join函数用法实例分析

    本文实例讲述了Python中threading模块join函数用法.分享给大家供大家参考.具体分析如下: join的作用是众所周知的,阻塞进程直到线程执行完毕.通用的做法是我们启动一批线程,最后joi ...

  5. sklearn中cross_val_score、cross_val_predict的用法比较

    sklearn中cross_val_score.cross_val_predict的用法比较_程大海的博客-CSDN博客_cross_val_predict

  6. MapInfo中常用查询函数及用法

    MapInfo中常用查询函数及用法: 函数用途 语法 备注 图层中选点 Str$(obj)="point": Str(String)表示字符串:point表示点: 图层中选线 St ...

  7. 【Java学习笔记之二十九】Java中的equals和==的用法及区别

    Java中的"equals"和"=="的用法及区别 在初学Java时,可能会经常碰到下面的代码: 1 String str1 = new String(&quo ...

  8. jquery中this与$(this)的用法区别.

    2019独角兽企业重金招聘Python工程师标准>>> jquery中this与$(this)的用法区别.先看以下代码: $("#textbox").hover( ...

  9. C#中static静态变量的用法

    原文:C#中static静态变量的用法 使用 static 修饰符声明属于类型本身而不是属于特定对象的静态成员static修饰符可用于类.字段.方法.属性.运算符.事件和构造函数,但不能用于索引器.析 ...

最新文章

  1. Java网络编程基础(三)---基于UDP编程
  2. java对于文件传输时---编码格式的一些设置方法
  3. 标识为普通SQL语法
  4. 省钱有简单的祛痘方法 - 健康程序员,至尚生活!
  5. Systemd 入门教程:命令篇、实战篇
  6. 37. 两个链表的第一个公共节点(C++版本)
  7. 光圈和景深对摄影的影响
  8. 4173: 数学 欧拉函数 思路题
  9. ros讯飞语音交互学习记录
  10. MLP-Mixer详解
  11. 速读原著-TCP/IP(互联网与实现)
  12. Linux下查看网络流量常用方法
  13. java安卓模拟器和电脑通信_PC电脑和Android模拟器访问及模拟器之间tcp/udp通信
  14. QR分解的三种实现方法
  15. #让我们用python跑回归#Fama-French三因素模型(一)
  16. Linux 中安装宋体字体
  17. 关于MATLAB中直接计算cos90不等于0的解决办法
  18. Python 办公小助手:读取 PDF 中表格并重命名
  19. 对于编码器与解码器的理解
  20. Howdoo欢迎Mitel成为内容发布支持者

热门文章

  1. 从《天行九歌》到海盗问题
  2. Android studio 放大字体
  3. 对于信息传播的一点理解
  4. AI研究生的文学情怀,厦大硕士毕业生文言致谢聊三年求学路
  5. 排列组合问题之捆绑法和插空法
  6. ER图练习(住院病人信息管理系统)
  7. Okttp模拟PC浏览器发送http请求
  8. js复制图片文字图文分享到微信/QQ,插件clipboard.js的应用案例
  9. Arduino库 <TFT_eSPI> 中文字库的制作与使用
  10. 毕得医药递交科创板注册:年营收6亿 拟募资4.34亿