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

制作网站的商家拟一份饰品网站建设合同

制作网站的商家,拟一份饰品网站建设合同,全网推广平台有哪些,找外贸工作哪个网站好一、编译与环境配置 ‌libopus库集成‌ 需在编译FFmpeg时添加--enable-libopus参数,编译前需先安装libopus源码并配置动态库路径‌。最新FFmpeg 7.1版本默认支持Opus的浮点运算优化和VBR/CVBR模式‌。 ‌多平台兼容性‌ Opus支持Windows/Linux/macOS平台&#xff0…
一、编译与环境配置
  1. libopus库集成
    需在编译FFmpeg时添加--enable-libopus参数,编译前需先安装libopus源码并配置动态库路径‌。最新FFmpeg 7.1版本默认支持Opus的浮点运算优化和VBR/CVBR模式‌。

  2. 多平台兼容性
    Opus支持Windows/Linux/macOS平台,编译时需注意不同系统的依赖库路径差异‌。

二、命令行编解码操作
  1. 编码

    # PCM转Opus(48kHz双通道)
    ffmpeg -f s16le -ar 48000 -ac 2 -i input.pcm -c:a libopus -b:a 128k -vbr on output.opus

    -ar:指定输入采样率(支持8k/16k/48k等)‌
    -ac:设置通道数(WebRTC场景强制要求双通道)‌

  2. 解码

    # Opus转PCM并重采样至16kHz单通道
    ffmpeg -i input.opus -ar 16000 -ac 1 -f s16le output.pcm

    支持动态调整输出采样率(8k/16k/44.1k/48k)
    解码后需通过nb_samples获取实际音频帧大小‌

三、代码编解码实现
1、Opus编码代码 
#include <libavcodec/avcodec.h>
#include <libavformat/avformat.h>int decode_opus_to_pcm(const char* input_file, const char* output_file) {AVFormatContext *fmt_ctx = NULL;AVCodecContext *codec_ctx = NULL;const AVCodec *codec = NULL;FILE *pcm_out = fopen(output_file, "wb");// 1. 注册编解码器av_register_all();avcodec_register_all();// 2. 打开输入文件if(avformat_open_input(&fmt_ctx, input_file, NULL, NULL) < 0) {fprintf(stderr, "无法打开输入文件\n");return -1;}// 3. 查找音频流if(avformat_find_stream_info(fmt_ctx, NULL) < 0) {fprintf(stderr, "无法找到流信息\n");return -1;}// 4. 获取Opus解码器codec = avcodec_find_decoder(AV_CODEC_ID_OPUS);if(!codec) {fprintf(stderr, "Opus解码器未找到\n");return -1;}codec_ctx = avcodec_alloc_context3(codec);avcodec_parameters_to_context(codec_ctx, fmt_ctx->streams->codecpar);// 5. 打开解码器if(avcodec_open2(codec_ctx, codec, NULL) < 0) {fprintf(stderr, "无法打开解码器\n");return -1;}AVPacket packet;AVFrame *frame = av_frame_alloc();// 6. 解码循环while(av_read_frame(fmt_ctx, &packet) >= 0) {if(packet.stream_index == 0) {int ret = avcodec_send_packet(codec_ctx, &packet);while(ret >= 0) {ret = avcodec_receive_frame(codec_ctx, frame);if(ret == AVERROR(EAGAIN) || ret == AVERROR_EOF)break;else if(ret < 0) {fprintf(stderr, "解码错误\n");break;}// 7. 输出PCM数据(16-bit小端)fwrite(frame->data, 1, frame->nb_samples * av_get_bytes_per_sample(codec_ctx->sample_fmt), pcm_out);}}av_packet_unref(&packet);}// 8. 清理资源av_frame_free(&frame);avcodec_free_context(&codec_ctx);avformat_close_input(&fmt_ctx);fclose(pcm_out);return 0;
}
2、Opus解码代码 
#include <libavcodec/avcodec.h>
#include <libavutil/opt.h>int encode_pcm_to_opus(const char* input_pcm, const char* output_opus) {const AVCodec *codec = avcodec_find_encoder(AV_CODEC_ID_OPUS);AVCodecContext *codec_ctx = NULL;FILE *opus_out = fopen(output_opus, "wb");FILE *pcm_in = fopen(input_pcm, "rb");// 1. 创建编码器上下文codec_ctx = avcodec_alloc_context3(codec);codec_ctx->bit_rate = 64000;         // 目标码率codec_ctx->sample_fmt = AV_SAMPLE_FMT_S16; // 输入格式codec_ctx->sample_rate = 48000;      // 采样率codec_ctx->channel_layout = AV_CH_LAYOUT_STEREO; // 双声道codec_ctx->channels = 2;// 2. 设置编码参数av_opt_set(codec_ctx->priv_data, "application", "audio", 0); // 音乐优化av_opt_set_int(codec_ctx->priv_data, "compression_level", 10, 0); // 最高质量// 3. 打开编码器if(avcodec_open2(codec_ctx, codec, NULL) < 0) {fprintf(stderr, "无法打开编码器\n");return -1;}AVFrame *frame = av_frame_alloc();frame->nb_samples = codec_ctx->frame_size; // 帧大小(如960 samples@48kHz)frame->format = codec_ctx->sample_fmt;frame->channel_layout = codec_ctx->channel_layout;av_frame_get_buffer(frame, 0);AVPacket *pkt = av_packet_alloc();// 4. 编码循环while(1) {// 读取PCM数据size_t read_size = fread(frame->data, 1, frame->nb_samples * av_get_bytes_per_sample(codec_ctx->sample_fmt), pcm_in);if(read_size <= 0) break;// 发送帧到编码器int ret = avcodec_send_frame(codec_ctx, frame);while(ret >= 0) {ret = avcodec_receive_packet(codec_ctx, pkt);if(ret == AVERROR(EAGAIN) || ret == AVERROR_EOF)break;else if(ret < 0) {fprintf(stderr, "编码错误\n");break;}// 写入输出文件(需添加OGG封装头)fwrite(pkt->data, 1, pkt->size, opus_out);av_packet_unref(pkt);}}// 5. 清理资源av_frame_free(&frame);av_packet_free(&pkt);avcodec_free_context(&codec_ctx);fclose(opus_out);fclose(pcm_in);return 0;
}
3、关键代码说明
  1. 编解码器初始化

    • avcodec_find_decoder/encoder(AV_CODEC_ID_OPUS) 查找编解码器
    • avcodec_alloc_context3() 创建编解码上下文
    • avcodec_open2() 打开编解码器
  2. 数据处理流程

    • 解码‌:av_read_frame() → avcodec_send_packet() → avcodec_receive_frame()
    • 编码‌:avcodec_send_frame() → avcodec_receive_packet()
  3. 参数优化

    // 设置低延迟模式
    av_opt_set(codec_ctx->priv_data, "application", "lowdelay", 0);// 设置VBR模式(0-固定码率,1-可变码率)
    av_opt_set_int(codec_ctx->priv_data, "vbr", 1, 0);// 设置帧持续时间(单位:ms)
    av_opt_set_int(codec_ctx->priv_data, "frame_duration", 20, 0);
    4、编译与运行
    # 编译命令(需链接FFmpeg库)
    gcc opus_example.c -o opus_demo \-lavcodec -lavformat -lavutil -lswresample# 运行解码示例
    ./opus_demo input.opus output.pcm# 运行编码示例(输入需为48kHz双通道s16 PCM)
    ./opus_demo input.pcm output.opus


文章转载自:

http://Imx8BJEj.zfxnd.cn
http://dpyTcjiH.zfxnd.cn
http://YBS6oUug.zfxnd.cn
http://fD7rmtPi.zfxnd.cn
http://U3olBJOJ.zfxnd.cn
http://BW3zHzSp.zfxnd.cn
http://dYGAPu4W.zfxnd.cn
http://c5mew0Ne.zfxnd.cn
http://lOzbANUR.zfxnd.cn
http://B5g3eK4n.zfxnd.cn
http://e9tjHR5O.zfxnd.cn
http://IBPVtZTb.zfxnd.cn
http://bbyDORqt.zfxnd.cn
http://KvH3Xt0E.zfxnd.cn
http://8NyYFYZ0.zfxnd.cn
http://Y8OC7dbr.zfxnd.cn
http://1vK40YMw.zfxnd.cn
http://9lhDSYjf.zfxnd.cn
http://y2jW9XyA.zfxnd.cn
http://w16aNoKc.zfxnd.cn
http://dADgzlhl.zfxnd.cn
http://wkiJgXVJ.zfxnd.cn
http://pxM3gwXL.zfxnd.cn
http://D67ASmWG.zfxnd.cn
http://IWL3qsoA.zfxnd.cn
http://V1RRFXmD.zfxnd.cn
http://74i9H1lU.zfxnd.cn
http://GYWi6Fnu.zfxnd.cn
http://msOyFxRe.zfxnd.cn
http://tNhjTLK1.zfxnd.cn
http://www.dtcms.com/wzjs/662456.html

相关文章:

  • 网站建设一般花多少费用优品ppt模板网免费
  • 新闻发布网站建设实训小结wordpress qq快捷登陆
  • 南京网站制作百家号邢台信息港首页
  • 成都网络公司网站建网站买完域名后怎么做
  • 网站建设收费详情python 网站开发 前端
  • 相城苏州网站建设织梦医院网站模板
  • 安徽省建设质量安全协会网站给公司做网站费用
  • 智能网站建设软件有哪些方面干煤棚网架公司
  • 一家只做t恤的网站免费行情软件网站有哪些
  • 自己做的网站无法访问多城市地方门户网站系统
  • 广州中企动力网站制作网站的加盟代理
  • 优化推广网站推荐广州seo全网营销
  • 小企业网站建设的连接方式宁波网站制作优化服务
  • 网站建设合同书(范本)广东前20大互联网公司
  • wordpress搜索页分类网络优化seo是什么工作
  • 东莞销售网站建设佛山cms建站
  • 搜索不到的网站苗木公司网站模板
  • 申请域名的网站微博推广费用一般多少
  • 兰州网站建设公司排名如何做商业网站分析
  • 沈阳高端网站制作公司dede关闭手机网站
  • 做58网站空调维修接单怎么样做网站外包好吗
  • 网站测速陕西政务服务网注册公司流程
  • 在excel表里做网站模板重庆好的推广网站
  • 推广网站的论坛大量图片展示网站模板
  • 微网站建设86215珠海高端网站制作公司
  • 网站没备案能百度推广吗网站建设报价清单
  • 河北中凯建设有限公司网站网站开发基本过程
  • 做网站容易还是app拿word如何做网站
  • 建一个优化网站多少钱商务网站设计制作
  • 低价网站建设费用预算做图书馆网站