首页 > 编程知识 正文

音频解码器DIY,内置ffmpeg解码器

时间:2023-05-03 20:53:45 阅读:115475 作者:2284

av_dump_format ()打印有关输入/输出格式的详细信息,包括持续时间、比特率、流、容器、程序、元数据、边缘数据、编解码器和基于时间的格式其中最后一个参数is_output选择输出或是输入,最后一个参数填0,打印输入流,最后一个参数填1,打印输出流。

# define _ CRT _ secure _ no _ warnings # include stdio.h extern ' c ' { # include libavcodec/av codec.h # includelibavavffe ' avcodec.lib ' ) #pragmacomment ) lib,' avformat.lib ' ) pragmacomment ) ) ' avutil.lib ' ) # PPP ' SW scale.lib ' (int main ) )//定义文件名file*F1=fopen(www_y.yuv )、' www_y.yuv '、file * F2=fopen (' www ) file*F3=fopen('www_v.YUV ',' wb ' ); 测试//dll库是否成功打印(% s/n )、avcodec_configuration ); 注册DLLav_register_all (); //网络avformat_network_init (; AVFormatContext* pFormat=NULL; const char* path='22.mp4 '; //视频文件intret=av format _ open _ input (p format,path,NULL,NULL ); if(ret ) {printf ('无法打开文件n ); 返回- 1; }printf ('文件打开成功n ); 查找//流信息ret=av format _ find _ stream _ info (p format,NULL ); if(ret ) {printf ) )流打开失败n ); 返回- 1; }printf ('成功打开流(n ); av_dump_format(pformat,NULL,path,0 ); int VideoStream=-1,AudioStream=-1; //获取视频流videostream=av _ find _ best _ stream (p格式,AVMEDIA_TYPE_VIDEO,-1,-1,NULL,NULL ) ) //解码器av codec * vcodec=av codec _ find _ decoder (p格式流[ videostream ]-codec-codec _ id ); if (! vCodec ) {printf(vcodec失败n ); 返回- 1; }printf(vcodec成功(n ); //打开解码器ret=av codec _ open2 (p格式流[ videostream ]-codec,vcodec,NULL ); if(ret ) {printf ) )解码器打开失败n ); 返回- 1; }printf ('解码器成功打开(n ); //解码视频以创建//帧空间av帧*帧=av _ frame _ alloc (; av frame * frame YUV=av _ frame _ alloc (; //获取视频宽度高度的intwidth=p format-streams [ videostream ]-codec-width; int height=p format-streams [ videostream ]-codec-height; printf(%d(n )、width ); printf(%d(n ),高); int fmt=p format-streams [ videostream ]-codec-pix _ fmt; //分配空间并转换图像int nsize=av picture _ get _ size (av _ pix _ fmt _ YUV 420 p,width,height ); uint8_t* buff=NULL; buff=(uint8_t* ) av_malloc ) nsize; //1帧图像avpicture_fill(avpicture* ) frameYUV,buff,AV_PIX_FMT_YUV420P,width,height ); avpacket*packet=(avpacket* ) av _ malloc (sizeof ) avpacket ); //上下文SWS上下文* SWS CTX=null; swsCTX=SWS_getcontext(width,height,) AVPixelFormat ) fmt,width,height,AV_PIX_FMT_YUV420P,SWS _ bix int帧计数=0; while(av_read_frame(pformat,packet )=0) if ) packet-stream _ index==av media _ type _ video ) { ret=} }if(go ) (/SWS_scale ) SWSCTX,) const uint8_t** ) frame-data,frame-linesize,0,height,frame YUV-data 写入(帧YUV-data [1],1,width * height/4,f2 ); 写入(frame YUV-data [2],1,width * height/4,f3 ); 框架计数; printf (帧数据: %dn )、帧计数); }//清除包数据av _ free _ packet (包); //关闭和释放空格fclose(f1 ); flose(F2; flose(F3; SWS_freecontext(SWSCTX; av _ frame _ free (帧); av _ frame _ free (帧YUV ); av format _ close _ input (p格式; 返回0; }

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。