ffmpeg解码aac并重采样
来源:互联网 发布:创建触发器 sql 编辑:程序博客网 时间:2024/06/18 11:00
一 谈到音频解码,我们先了解一些基本概念。
声道数目 立体声(stero)单声道(mono)
采样率 单位时间内对音频ad芯片的采样次数,常见的音频采样率有。
- 0: 96000 Hz
- 1: 88200 Hz
- 2: 64000 Hz
- 3: 48000 Hz
- 4: 44100 Hz
- 5: 32000 Hz
- 6: 24000 Hz
- 7: 22050 Hz
- 8: 16000 Hz
- 9: 12000 Hz
- 10: 11025 Hz
- 11: 8000 Hz
- 12: 7350 Hz
- 13: Reserved
- 14: Reserved
- 15: frequency is written explicitly
左边是adts头里面对应的采样率编码值,右边是对应的采样率值。
单采样bit数目 单个采样的bit位数,16/8 bit。
ffmpeg中的一些参数:
out_sample_format 音频采样格式
sample_rate 采样率值(非编码值)
in_channel_layout 解码后的PCM数据layout格式,左左左右右右 左右左右左右
nb_samples 一帧音频中的采样个数,用于计算一帧数据大小
下面看详细示例:
注意ffmpeg中的两个结构,AVPacket(编码的音视频帧),AVFrame(解码后的音视频数据)
AVPacket packet = {0};
packet.data =(uint8_t*)buf;
packet.size = len;
AVFrame *decode_frame = avcodec_alloc_frame();
if(decode_frame == NULL)
{
return -1;
}
packet.data =(uint8_t*)buf;
packet.size = len;
AVFrame *decode_frame = avcodec_alloc_frame();
if(decode_frame == NULL)
{
return -1;
}
//前面已经初始化过解码器
int audio4_decode_len = avcodec_decode_audio4(av_codec_ctx_,decode_frame,got_frame,&packet);//解码
if(audio4_decode_len < 0||*got_frame != 1)
{
return -1;
}
AVSampleFormat out_sample_format = AV_SAMPLE_FMT_S16;
struct SwrContext *audio_convert_ctx;
audio_convert_ctx = swr_alloc();
unsigned long long in_channel_layout = av_get_default_channel_layout(av_codec_ctx_->channels);
audio_convert_ctx = swr_alloc_set_opts(audio_convert_ctx,in_channel_layout,out_sample_format,av_codec_ctx_->sample_rate,
in_channel_layout,av_codec_ctx_->sample_fmt,av_codec_ctx_->sample_rate,0,NULL);
swr_init(audio_convert_ctx);
int nb_samples = swr_convert(audio_convert_ctx,//重采样,返回的值是新的采样率的一帧中的采样个数,可以根据声道和采样bit数目计算一帧数据大小
(uint8_t **)&outbuf,
AVCODEC_MAX_AUDIO_FRAME_SIZE,
(const uint8_t **)decode_frame->data,
decode_frame->nb_samples);
outlen = av_samples_get_buffer_size(NULL,av_codec_ctx_->channels ,nb_samples,out_sample_format, 1);//计算出重采样后一帧pcm数据的大小
sample_rate = av_codec_ctx_->sample_rate;
channels = av_codec_ctx_->channels;
avcodec_free_frame(&decode_frame);
int audio4_decode_len = avcodec_decode_audio4(av_codec_ctx_,decode_frame,got_frame,&packet);//解码
if(audio4_decode_len < 0||*got_frame != 1)
{
return -1;
}
AVSampleFormat out_sample_format = AV_SAMPLE_FMT_S16;
struct SwrContext *audio_convert_ctx;
audio_convert_ctx = swr_alloc();
unsigned long long in_channel_layout = av_get_default_channel_layout(av_codec_ctx_->channels);
audio_convert_ctx = swr_alloc_set_opts(audio_convert_ctx,in_channel_layout,out_sample_format,av_codec_ctx_->sample_rate,
in_channel_layout,av_codec_ctx_->sample_fmt,av_codec_ctx_->sample_rate,0,NULL);
swr_init(audio_convert_ctx);
int nb_samples = swr_convert(audio_convert_ctx,//重采样,返回的值是新的采样率的一帧中的采样个数,可以根据声道和采样bit数目计算一帧数据大小
(uint8_t **)&outbuf,
AVCODEC_MAX_AUDIO_FRAME_SIZE,
(const uint8_t **)decode_frame->data,
decode_frame->nb_samples);
outlen = av_samples_get_buffer_size(NULL,av_codec_ctx_->channels ,nb_samples,out_sample_format, 1);//计算出重采样后一帧pcm数据的大小
sample_rate = av_codec_ctx_->sample_rate;
channels = av_codec_ctx_->channels;
avcodec_free_frame(&decode_frame);
更多开源流媒体技术,请关注我们的微信:EasyDarwin
阅读全文
0 0
- ffmpeg解码aac并重采样
- ffmpeg解复用解码重采样
- ffmpeg 接收h264+aac并解码
- SDL播放ffmpeg解码的AAC
- ffmpeg aac
- faad2解码aac-解决采样频率和通道数不对的问题
- faad2解码aac到pcm (采样频率和通道数问题)
- ffmpeg实战教程(三)音频PCM采样为AAC,视频YUV编码为H264/HEVC
- Android FFMpeg(三)——使用FFMpeg解码h264、aac
- FFmpeg学习—android 编译 ffmpeg 集成fdk-aac、x264 精简解码库
- 【FFMPEG】各种音视频编解码学习详解 h264 ,mpeg4 ,aac 等所有音视频格式
- AAC编解码
- AAC解码流程图
- AAC编解码
- AAC 编解码封装
- MediaCodec解码aac
- MediaCodec解码aac,播放
- 使用mediacodec 解码AAC
- HDU1395 ZOJ1489 2^x mod n = 1【暴力法+数论】
- python 接收用户的输入
- mysql升级
- python turtle库常用方法
- POJ 3126 Prime Path
- ffmpeg解码aac并重采样
- bitwise const与一些零碎知识
- oracle 定时任务
- 173. Binary Search Tree Iterator
- 树形DP 专题训练
- Leetcode009-Palindrome Number
- c51编译时的错误提示解决方法
- Big-man进军Linux系统(二)
- MySQL日志管理