ffmpeg-- audio decoder
测试代码来源于:http://ffmpeg.org/doxygen/trunk/decode_audio_8c-example.html
需要在sample code加一行avcodec_register_all()
Makefile如下:
export CC=gcc
FFMPEGPATH=/mnt/hgfs/share/ffmpeg-3.3.3/ffmpeg-3.3.3/output
SOURCE=decode_audio.c
INCLUDE=-I$(FFMPEGPATH)/include
LINK=-L$(FFMPEGPATH)/lib/ -lavcodec -lavformat -lavutil -lswresample
LINK+=-lpthread -lm -ldl
TARGET=adecoder
all:
$(CC) $(SOURCE) $(INCLUDE) $(LINK) -o $(TARGET)
主要函数介绍:
AVPacket *av_packet_alloc(void)
分配并初始化AVPacket结构体,AVPacket是存储压缩编码数据相关信息的结构体。free AVPacket的函数为av_packet_free().
av_packet_alloc只allocate AVPacket本身,并不分配内部data buffer. data buffer 使用其他方式allocate,比如av_new_packet.
AVCodec * avcodec_find_decoder(enum AVCodecID id)
使用codec ID在已经注册的decoders中查找相应的decoder,如果ffmpeg有注册了相应的decoder,则返回AVCodec结构体,否则返回NULL.AVCodec是存储编解码器信息的结构体.
AVCodecParserContex *av_parser_init(int codec_id)
根据codec id,在已经注册的parser中查找,是否有相关codec的parser,如果存在该codec的parser,则分配AVCodecParserContex结构体。parser用于从raw data中parse出packet.AVCodecParserContex存储parser contex相关信息的结构体,包含AVCodecParser结构体和frame_offset,next_frame_offset等,AVCodecParser存储parser相关信息。
AVCodecContext *avcodec_alloc_context3(const AVCodec *codec)
allocate AVCodecContext 结构体,对AVCodecContext 设置一些default值。AVCodecContext 存储codec contex信息,包含AVCodec结构。
int attribute_align_arg avcodec_open2(AVCodecContext *avctx, const AVCodec *codec, AVDictionary **options)
使用AVCodec对AVCodecContex进行初始化。
AVFrame *av_frame_alloc(void)
allocate AVFrame 结构体,并对AVFrame 的Filed设置default值。AVFrame存储解码后的数据。av_frame_alloc只allocate AVFrame本身,并不分配内部data buffer. data buffer 使用其他方式allocate,比如av_frame_get_buffer().
int av_parser_parse2(AVCodecParserContext *s, AVCodecContext *avctx, uint8_t **poutbuf, int *poutbuf_size,const uint8_t *buf, int buf_size, int64_t pts, int64_t dts, int64_t pos)
调用codec的parser的parser_parse函数从输入的数据buf中 parse一个packet出来。packet的data放到poutbuf, size为poutbuf_size.
int attribute_align_arg avcodec_send_packet(AVCodecContext *avctx, const AVPacket *avpkt)
将parser parse出的raw packet作为输入数据给到decoder解码。如果decoder有send_packet函数则调用该函数,如果没有,则调用avcodec_decode_audio4()进行解码,将解码出来的AVFrame结构保存在avctx->internal->buffer_frame。
如果返回0表示该函数成功返回。如果返回负数AVERROR(EAGAIN),decoder当前状态不接收input数据,用户必须调用avcodec_recieve_frame来读走output数据,一旦output数据被读走,resent packet后就不会返回这样的错误。
int attribute_align_arg avcodec_receive_frame(AVCodecContext *avctx, AVFrame *frame)
如果decoder有recieve_frame函数则调用该函数,如果没有该函数,则check avctx->internal->buffer_frame是否有数据,如果有则返回avctx->internal->buffer_frame,没有数据这调用avcodec_decode_audio4()进行解码,将解码出来的AVFrame结构保存在avctx->internal->buffer_frame,并返回AVFrame。
对于video,一个avpkt对应一个video frame,但对于某些audio codec,一个avpkt有多个audio frame.如果有多个audio frame,需要在调用avcodec_send_packet后调用多次avcodec_recieve_frame直到packet完全被消耗,才能send new packet.
int attribute_align_arg avcodec_decode_audio4(AVCodecContext *avctx,AVFrame *frame,int *got_frame_ptr,const AVPacket *avpkt)
从输入的avpcket解码出audio frame.返回值为负值表示decoder出现error,否则返回消耗avpkt的byte数。
对于一个AVPacket包含多个audio frame的情况,第一调用avcodec_decode_audio4只解码出第一个frame,返回值小于avpkt->size.再call一次avcodec_decode_audio4解码出第二个frame.....即使函数不返回frame,也要将packet送到decoder直至消耗完或返回error.
某些decoder在input 和output有delay,这表示一些packet并不是立即经由decoder解码输出,而需要decoding结束时flush,从而获得所有的解码数据。对于没有delay的decoder,flush也是安全的。flush是通过调用该函数,并将avpkt->data=NULL, avpkt->size=0.
ffmpeg-- audio decoder的更多相关文章
- (转)Integrating Intel® Media SDK with FFmpeg for mux/demuxing and audio encode/decode usages 1
Download Article and Source Code Download Integrating Intel® Media SDK with FFmpeg for mux/demuxing ...
- [ffmpeg]deocde audio(v3.3.2)
/* * Copyright (c) 2001 Fabrice Bellard * * Permission is hereby granted, free of charge, to any per ...
- Linux下编译带x264的ffmpeg的配置方法,包含SDL2
一.环境准备 ffmpeg下载:http://www.ffmpeg.org/download.html x264下载:http://download.videolan.org/x264/snapsho ...
- 基于ffmpeg的简单音视频编解码的例子
近日需要做一个视频转码服务器,对我这样一个在该领域的新手来说却是够我折腾一番,在别人的建议下开始研究开源ffmpeg项目,下面是在代码中看到的一 段例子代码,对我的学习非常有帮助.该例子代码包含音频的 ...
- FFmpeg源代码简单分析:configure
===================================================== FFmpeg的库函数源代码分析文章列表: [架构图] FFmpeg源代码结构图 - 解码 F ...
- 最简单的基于FFMPEG+SDL的音频播放器 ver2 (采用SDL2.0)
===================================================== 最简单的基于FFmpeg的音频播放器系列文章列表: <最简单的基于FFMPEG+SDL ...
- FFmpeg(9)-解码器解码代码演示(FFmpeg调用MediaCodec实现硬解码、多线程解码、及音视频解码性能测试)
一.AVFrame 用来存放解码后的数据. [相关函数] AVFrame *frame = av_frame_alloc(); // 空间分配,分配一个空间 ...
- Qt与FFmpeg联合开发指南(一)——解码(1):功能实现
前言:对于从未接触过音视频编解码的同学来说,使用FFmpeg的学习曲线恐怕略显陡峭.本人由于工作需要,正好需要在项目中使用.因此特地将开发过程总结下来.只当提供给有兴趣的同学参考和学习. 由于FFmp ...
- ffmpeg h264+ts +udp传输
http://bbs.csdn.net/topics/370246456 http://1229363.blog.163.com/blog/static/19743427201001244711137 ...
- 最简单的基于FFMPEG+SDL的音频播放器 ver2 (採用SDL2.0)
===================================================== 最简单的基于FFmpeg的音频播放器系列文章列表: <最简单的基于FFMPEG+SDL ...
随机推荐
- NOI Online能力测试游记:退役选手的自娱自乐
2020年2月17日早上8点,CCF发布了关于举办NOI Online能力测试的通知. 为给选手提供一个锻炼的机会,CCF拟举办一场NOI Online能力测试.测试分为入门组和提高组,每组限额报名3 ...
- JavaScript:JSON对象
一.JSON对象概念 JSON (JavaScript Object Notation)一种简单的数据格式,比xml更轻巧. JSON 是 JavaScript 原生格式,这意味着在 JavaScri ...
- H5-设置全屏背景图片样式
.bgimg{ width: 100%; height: 95vh; margin: 0; padding: 0 .32rem; background-image: url('../image/ld. ...
- JS添加和删除表格行
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/stri ...
- react-native-----hello word!
react-native运行helloword 今天是个特殊的时刻,我前天开始学习react-native,一直环境塔建出错,运行打包出错,今晚,我终于把这个难搞的环境给搭建好了,并成功运行了第一个h ...
- 翻转引起 cocos studio 引擎与cocos2d 代码相同坐标显示不同
使用setFlippedX后,又改变锚点为1.此时代码中坐标需要相对于cocos studio 中增加它本身的width,因为(0.5,0.5)是相对于自己中点的翻转,不变坐标.而(1,0.5)是相对 ...
- 在vue项目中播放m3u8格式视频
前言:最近公司在做一个线上会议的项目,要求后台网站播放m3u8格式的视频,查找部分资料,总结一下,方便后边查阅 1.在vue工程中安装以下依赖: cnpm install video.js --sa ...
- Currency Exchange POJ - 1860 spfa判断正环
//spfa 判断正环 #include<iostream> #include<queue> #include<cstring> using namespace s ...
- .NET知识梳理——4.特性Attribute
1. 特性 1.1 特性Attribute 特性就是一个类,继承自Attribute抽象类(该类无抽象方法.避免实例化),约定俗成用Attribute类结尾,标记时可省略掉Attribu ...
- Fragment应用
使用母页和子页配合展示内容:母页和子页都有自己的activity. 母页是含有frameLayout控件的页面.子页通过配置,在frameLayout控件中显示:frameLayout本身没有任何内容 ...