当前位置: 首页 > news >正文

邯郸网站建设开发公司前程无忧网广州网站建设分类岗位

邯郸网站建设开发公司,前程无忧网广州网站建设分类岗位,福田瑞沃e3自卸车,网站开发网站制作报价1. 介绍 在提取音视频文件中音频的PCM数据时#xff0c;使用avcodec_receive_frame()函数进行解码时#xff0c;遇到了一些问题#xff0c;代码在Visual Studio 2022中运行结果符合预期#xff0c;但是在CLion中运行时#xff0c;获取的AVFrame有错误#xff0c;和VS中获…1. 介绍 在提取音视频文件中音频的PCM数据时使用avcodec_receive_frame()函数进行解码时遇到了一些问题代码在Visual Studio 2022中运行结果符合预期但是在CLion中运行时获取的AVFrame有错误和VS中获得的结果不一样。 FFMpeg 5.1.2 2. 源码 Utils.h #pragma once#define _CRT_SECURE_NO_WARNINGSextern C { #include libavutil/error.h }static char* wrap_av_err2str(int errnum) {static char str[256] {0};return av_make_error_string(str, sizeof(str), errnum); }AudioDecoder2.h #pragma onceextern C { #include libavutil/log.h #include libavutil/imgutils.h #include libavutil/samplefmt.h #include libavutil/timestamp.h #include libavcodec/avcodec.h #include libavformat/avformat.h }; #include Utils.h #include cinttypesclass AudioDecoder2 { public:AudioDecoder2();AudioDecoder2(const char* src_filename, const char* dst_filename);~AudioDecoder2();int start();private:int ret;char src_filename[256];char dst_filename[256];FILE* dst_fd NULL;AVFormatContext* ifmt_ctx NULL;AVCodecContext* audio_dec_ctx NULL;const AVCodec* audio_dec NULL;AVStream* audio_stream NULL;int audio_stream_index -1;AVFrame* frame NULL;AVPacket* packet NULL; }; AudioDecoder2.cpp #include AudioDecoder2.hAudioDecoder2::AudioDecoder2(const char* src_filename, const char* dst_filename) {sscanf(src_filename, %s, this-src_filename);sscanf(dst_filename, %s, this-dst_filename); }int AudioDecoder2::start() {// 设置日志输出级别av_log_set_level(AV_LOG_INFO);// 打开输入文件ret avformat_open_input(ifmt_ctx, src_filename, NULL, NULL);if (ret 0){av_log(NULL, AV_LOG_ERROR, Cant open source file:%s\n, wrap_av_err2str(ret));return -1;}// 读取一部分数据获得一些相关信息ret avformat_find_stream_info(ifmt_ctx, NULL);if (ret 0){av_log(NULL, AV_LOG_ERROR, Failed to find stream information: %s\n, wrap_av_err2str(ret));return -1;}// 查找流audio_stream_index -1;audio_stream_index av_find_best_stream(ifmt_ctx, AVMEDIA_TYPE_AUDIO, -1, -1, NULL, 0);if (audio_stream_index 0){av_log(NULL, AV_LOG_DEBUG, Failed to find the best audio stream!\n);return AVERROR(EINVAL);}// 获取流audio_stream ifmt_ctx-streams[audio_stream_index];// 通过数据流查找对应的解码器audio_dec avcodec_find_decoder(audio_stream-codecpar-codec_id);if (audio_dec NULL){av_log(NULL, AV_LOG_ERROR, Failed to find codec.\n);return AVERROR(EINVAL);}// 创建解码器上下文audio_dec_ctx avcodec_alloc_context3(audio_dec);if (audio_dec_ctx NULL){av_log(NULL, AV_LOG_ERROR, Failed to allocate the codec context.\n);return AVERROR(ENOMEM);}// 从输入流中拷贝对应的参数到解码器中ret avcodec_parameters_to_context(audio_dec_ctx, audio_stream-codecpar);if (ret 0){av_log(NULL, AV_LOG_ERROR, Failed to copy codec parameters to decoder context.\n);return ret;}// 打开解码器ret avcodec_open2(audio_dec_ctx, audio_dec, NULL);if (ret 0){av_log(NULL, AV_LOG_ERROR, Failed to open codec.\n);return ret;}// 创建输出文件dst_fd fopen(dst_filename, wb);if (!dst_fd){av_log(NULL, AV_LOG_ERROR, Could not open destination file %s\n, dst_filename);return -1;}// 分配帧frame av_frame_alloc();if (frame NULL){av_log(NULL, AV_LOG_ERROR, Failed to allocate frame.\n);return AVERROR(ENOMEM);}// 分配数据包packet av_packet_alloc();if (packet NULL){av_log(NULL, AV_LOG_ERROR, Failed to allocate packet.\n);return AVERROR(ENOMEM);}// 读取音频流的数据包并解码while (av_read_frame(ifmt_ctx, packet) 0){if (packet-stream_index audio_stream_index){ret avcodec_send_packet(audio_dec_ctx, packet);if (ret 0){av_log(NULL, AV_LOG_ERROR, Failed to decode packet.\n);return ret;}// 对数据进行解码输出while (ret 0){ret avcodec_receive_frame(audio_dec_ctx, frame);if (ret 0){if (ret AVERROR_EOF || ret AVERROR(EAGAIN)){break;}else{break;}}if (ret 0){// 将内容输出到文件av_log(NULL, AV_LOG_INFO, pts:%10 PRId64\t packet size:%d\n,packet-pts, packet-size);size_t unpadded_linesize frame-nb_samples * av_get_bytes_per_sample((enum AVSampleFormat)frame-format);fwrite(frame-extended_data[0], 1, unpadded_linesize, dst_fd);}av_frame_unref(frame);}}av_packet_unref(packet);}// 刷新解码器while (true){if (!(audio_dec-capabilities AV_CODEC_CAP_DELAY)){return 0;}ret avcodec_send_packet(audio_dec_ctx, packet);if (ret 0){// av_log(NULL, AV_LOG_ERROR, Failed to decode packet.\n);// return ret;break;}// 对数据进行解码输出while (ret 0){ret avcodec_receive_frame(audio_dec_ctx, frame);if (ret 0){if (ret AVERROR_EOF || ret AVERROR(EAGAIN)){break;}}// 将内容输出到文件size_t unpadded_linesize frame-nb_samples * av_get_bytes_per_sample((enum AVSampleFormat)frame-format);fwrite(frame-extended_data[0], 1, unpadded_linesize, dst_fd);av_frame_unref(frame);}av_packet_unref(packet);}// 释放资源avcodec_free_context(audio_dec_ctx);avformat_close_input(ifmt_ctx);if (dst_fd){fclose(dst_fd);}av_packet_free(packet);av_frame_free(frame);return 0; }main.cpp #include iostream #include AudioDecoder2.h using namespace std;int main(int argc, char** argv) {char src_filename[20] ball_10s.mp4;char audio_dst_filename[20] ball_10s.pcm;AudioDecoder2* audioDecoder2 new AudioDecoder2(src_filename, audio_dst_filename);audioDecoder2-start();return 0; }3. 问题 Visual Studio 2022调试结果 CLion中调试结果
http://www.dnsts.com.cn/news/128575.html

相关文章:

  • 网站建设好专业做官网的公司
  • 做网站要实名认证吗建网站签合同
  • 网站调用优酷视频去除广告的方法个人执业资格注册查询
  • 做的好的网站有哪些境外网站icp备案申请表
  • 网站推广的预算爱链接购买链接
  • 怎么在网站标题做logo世界上有几个空间站
  • 无锡网站排名优化公司哪家好国家城乡住房和建设部网站
  • 网站开发设计技术网络推广十大平台
  • nas 做网站服务器wordpress定时器
  • 本地生活服务网站怎么做公司测名网
  • 高端网站搭建公司企业logo设计用什么软件
  • 做外贸营销型网站营销型网站建站公司
  • 一个公司做网站需要注意什么江苏盐城网络科技有限公司
  • 做聚会的网站东莞cms建站模板
  • 石家庄做物流的网站职业生涯规划网站开发背景
  • 做手机网站尺寸域名注册 阿里云查询
  • 做网站起什么名字好呢免费字体下载网站
  • 通辽住房和城乡建设厅网站用什么面板搭建Wordpress
  • 学校网站建设软件推荐天津做网站找哪家好
  • 吉林建设监理协会网站建网站 发信息 做推广
  • 培训网站网站链接推广
  • 桂林北站地图东莞市网站建设品牌
  • 手机网站的做辽宁城市建设职业技术学院教育网站
  • 专门做化妆品平台的网站有哪些天津建网站
  • 选择网站的关键词山东省城乡建设部网站
  • 深圳做网站补贴网站建设花费
  • 劳动仲裁院内部网站建设wordpress 更换ip
  • 怎样优化手机网站建设备案信息在哪里查
  • 威海网站建设公司哪家好xp网站建设
  • 昆明网站开发报价深圳建网站的网络公司