ffmpeg中G726解码器用法 编码器用法
来源:互联网 发布:c语言接口与实现 pdf 编辑:程序博客网 时间:2024/05/17 09:09
//解码:
本代码实现将cap1.g726文件中的g726编码帧数据进行解码,然后保存到cap1文件中
1、ffmpeg版本 :
0.10.2
2、源码:
extern "C"{ #include "./h/libavcodec/avcodec.h"};
#pragma comment(lib, "avutil.lib") //ffmpeg#pragma comment(lib, "avformat.lib")#pragma comment(lib, "avcodec.lib")
AVCodec *codec;AVCodecContext *c= NULL;AVPacket avpkt;AVFrame *decoded_frame = NULL;
//编码后一帧大小为 84字节#define framesize 84
int main(int argc, char* argv[]){ printf("Hello World!\n"); unsigned char inbuffer[framesize] = {0}; /* register all the codecs */ avcodec_register_all(); av_init_packet(&avpkt); /* find the mpeg audio decoder */ codec = avcodec_find_decoder(CODEC_ID_ADPCM_G726); if (!codec) { fprintf(stderr, "codec not found\n"); return 0; } c = avcodec_alloc_context3(codec);
//没有如下两句 avcodec_open会返回 -22 错误
//采样率 = 8000 每个采样用的bit数 = 16 通道数 = 1 c->bits_per_coded_sample = 2; //g726压缩比为 8:1 编码前采样用bit数为16 那么编码后应该占16/8 = 2 这是我的理解
c->channels = 1; /* open it */ int iRet = avcodec_open(c, codec); if ( iRet < 0 ) { fprintf(stderr, "could not open codec\n"); return 0; } FILE *f, *outfile;
//打开存放g726音频帧的文件
f = fopen( "cap1.g726", "rb" ); if (!f) { return 0; }
//打开要存放解码后音频帧的文件 outfile = fopen("cap1", "wb"); if (!outfile)
{ av_free(c); return 0; } avpkt.data = inbuffer; while ( (avpkt.size = fread(inbuffer, 1, framesize, f) ) > 0 ) { int got_frame = 0; if (!decoded_frame) { if (!(decoded_frame = avcodec_alloc_frame())) { return 0; } } else { avcodec_get_frame_defaults(decoded_frame); } int len = avcodec_decode_audio4(c, decoded_frame, &got_frame, &avpkt); if (len < 0) { return 0; } if (got_frame) { /* if a frame has been decoded, output it */ int data_size = av_samples_get_buffer_size(NULL, c->channels, decoded_frame->nb_samples, c->sample_fmt, 1); fwrite(decoded_frame->data[0], 1, data_size, outfile); } } fclose(outfile); fclose(f); avcodec_close(c); av_free(c); av_free(decoded_frame); return 0;}
//编码
ffmpeg g726 编码
2012-10-11 10:19:21| 分类: ffmpeg|举报|字号 订阅
- ffmpeg中G726解码器用法 编码器用法
- ffmpeg中G726解码器用法 编码器用法
- ffmpeg中调用解码器过程
- ffmpeg中sws_scale()用法实例
- ffmpeg中sws_scale()用法实例
- ffmpeg 中 swscale 的用法
- ffmpeg中swscale 的用法
- ffmpeg 中 swscale 的用法
- ffmpeg 中 swscale 的用法
- ffmpeg中swscale 的用法
- ffmpeg中swscale 的用法
- ffmpeg用法
- JPEG编码器和解码器
- 从ffmpeg中提取wma pro解码器
- c语言define中##用法---ffmpeg
- ffmpeg中sws_scale()用法实例---part of FFmpeg
- ffmpeg中如何加入trueHD/mlp编码器
- 创建MP3解码器 - 采用Symbian中MAD(MPEG音频解码库)用法
- 省赛小结
- ARMv7处理器各个模式之间是如何切换的?模式切换时上下文的保存哪些是硬件在做?哪些是操作系统在做?
- IOS-应用之间调用
- 如何开启win7端口的图文教程
- 排序算法之选择排序
- ffmpeg中G726解码器用法 编码器用法
- UIImageOrientation 映射关系
- ARMv7用户层发生指令异常的处理流程?是否每个进程都有一个APSR的副本?
- 读取txt 修改文档里面 某个日期到前几天的日期
- 三寸天堂
- 巧妙的按键扫描程序,核心算法只有三行
- iOS开发技术分享协议与代理
- xml解析
- 利用ArcMap的2个功能来帮助学习ArcPy