ffmpeg重采样中swr_convert和swr_get_out_samples的用法
ffmpeg重采样中swr_convert和swr_get_out_samples的用法
在做mux的时候关于重采样可以用fifo,或者audiofifo做缓存处理,当做demux的时候关于重采样就可以用到上面的swr_convert和swr_get_out_samples做配合处理。先看下这两个函数的注释:
[cpp] view plain copy
- /** Convert audio.
- *
- * in and in_count can be set to 0 to flush the last few samples out at the
- * end.
- *
- * If more input is provided than output space, then the input will be buffered.
- * You can avoid this buffering by using swr_get_out_samples() to retrieve an
- * upper bound on the required number of output samples for the given number of
- * input samples. Conversion will run directly without copying whenever possible.
- *
- * @param s allocated Swr context, with parameters set
- * @param out output buffers, only the first one need be set in case of packed audio
- * @param out_count amount of space available for output in samples per channel
- * @param in input buffers, only the first one need to be set in case of packed audio
- * @param in_count number of input samples available in one channel
- *
- * @return number of samples output per channel, negative value on error
- */
- int swr_convert(struct SwrContext *s, uint8_t **out, int out_count,
- const uint8_t **in , int in_count);
[cpp] view plain copy
- /**
- * Find an upper bound on the number of samples that the next swr_convert
- * call will output, if called with in_samples of input samples. This
- * depends on the internal state, and anything changing the internal state
- * (like further swr_convert() calls) will may change the number of samples
- * swr_get_out_samples() returns for the same number of input samples.
- *
- * @param in_samples number of input samples.
- * @note any call to swr_inject_silence(), swr_convert(), swr_next_pts()
- * or swr_set_compensation() invalidates this limit
- * @note it is recommended to pass the correct available buffer size
- * to all functions like swr_convert() even if swr_get_out_samples()
- * indicates that less would be used.
- * @returns an upper bound on the number of samples that the next swr_convert
- * will output or a negative value to indicate an error
- */
- int swr_get_out_samples(struct SwrContext *s, int in_samples);
就说如果传入的nb_samles大于了传出的nb_samplse则SwrContext中会有缓存,会导致内存一直暴涨,解决方法,可以看如下代码:
没有缓存的重采样这么处理:
[cpp] view plain copy
- ret = swr_convert(swrcontext, pOutputFrame->data,pOutputFrame->nb_samples,
- (const uint8_t**)pInputFrame->data,pInputFrame->nb_samples);
有缓存的代码这么处理:
[cpp] view plain copy
- //如果还有缓存在swrcontext中,第二个参数要填写0才能获取到,缓存数据
- int fifo_size = swr_get_out_samples(swrcontext,0);
- if ( fifo_size >= pOutputFrame->nb_samples)
- {
- ret = swr_convert(swrcontext, pOutputFrame->data,pOutputFrame->nb_samples,
- NULL,0);
- }
即如果有缓存则先判断是否有缓存在里面,如果有则传入数据为空取出缓存。
ffmpeg重采样中swr_convert和swr_get_out_samples的用法相关推荐
- @ini_get php,php中get_cfg_var()和ini_get()的用法及区别_php技巧_脚本之家
本文实例讲述了php中get_cfg_var()和ini_get()的用法及区别.分享给大家供大家参考.具体分析如下: php里get_cfg_var()和ini_get()都是取得配置值的函数,当你 ...
- java7 javascript引擎_Java7中脚本引擎的一般用法,共三种方法获得JavaScript引擎:名称、文件扩展名、MIME类型 | 学步园...
package com.sino.java7; import javax.script.ScriptEngine; import javax.script.ScriptEngineManager; i ...
- Oracle中INSTR和SUBSTR的用法
2019独角兽企业重金招聘Python工程师标准>>> Oracle中INSTR和SUBSTR的用法 Oracle中INSTR的用法: INSTR方法的格式为 INSTR(源字符串, ...
- python threading join_Python中threading模块join函数用法实例分析
本文实例讲述了Python中threading模块join函数用法.分享给大家供大家参考.具体分析如下: join的作用是众所周知的,阻塞进程直到线程执行完毕.通用的做法是我们启动一批线程,最后joi ...
- sklearn中cross_val_score、cross_val_predict的用法比较
sklearn中cross_val_score.cross_val_predict的用法比较_程大海的博客-CSDN博客_cross_val_predict
- MapInfo中常用查询函数及用法
MapInfo中常用查询函数及用法: 函数用途 语法 备注 图层中选点 Str$(obj)="point": Str(String)表示字符串:point表示点: 图层中选线 St ...
- 【Java学习笔记之二十九】Java中的equals和==的用法及区别
Java中的"equals"和"=="的用法及区别 在初学Java时,可能会经常碰到下面的代码: 1 String str1 = new String(&quo ...
- jquery中this与$(this)的用法区别.
2019独角兽企业重金招聘Python工程师标准>>> jquery中this与$(this)的用法区别.先看以下代码: $("#textbox").hover( ...
- C#中static静态变量的用法
原文:C#中static静态变量的用法 使用 static 修饰符声明属于类型本身而不是属于特定对象的静态成员static修饰符可用于类.字段.方法.属性.运算符.事件和构造函数,但不能用于索引器.析 ...
最新文章
- Java网络编程基础(三)---基于UDP编程
- java对于文件传输时---编码格式的一些设置方法
- 标识为普通SQL语法
- 省钱有简单的祛痘方法 - 健康程序员,至尚生活!
- Systemd 入门教程:命令篇、实战篇
- 37. 两个链表的第一个公共节点(C++版本)
- 光圈和景深对摄影的影响
- 4173: 数学 欧拉函数 思路题
- ros讯飞语音交互学习记录
- MLP-Mixer详解
- 速读原著-TCP/IP(互联网与实现)
- Linux下查看网络流量常用方法
- java安卓模拟器和电脑通信_PC电脑和Android模拟器访问及模拟器之间tcp/udp通信
- QR分解的三种实现方法
- #让我们用python跑回归#Fama-French三因素模型(一)
- Linux 中安装宋体字体
- 关于MATLAB中直接计算cos90不等于0的解决办法
- Python 办公小助手:读取 PDF 中表格并重命名
- 对于编码器与解码器的理解
- Howdoo欢迎Mitel成为内容发布支持者