音频批量转换pcm到opus格式

音频批量转换pcm到opus格式

#!/bin/bash
#author:wgn
#date:20210812
#description:auido fomat batch rerplace, pcm & wav to opus, for cloud auto test
#wav批量转换为opus,文件名无序
for filename1 in *.wav
do
    echo ${filename1%.*}
    opusenc --raw-bits 16 --raw-rate 16000 --raw-chan 1 --comp 10 --cvbr  --framesize 20 --bitrate 28  ${filename1%.*}.wav  ${filename1%.*}.opus
done
#pcm批量转换为opus,文件名无序
for filename2 in *.pcm
do
    echo ${filename2%.*}
    opusenc --raw-bits 16 --raw-rate 16000 --raw-chan 1 --comp 10 --cvbr  --framesize 20 --bitrate 28  ${filename2%.*}.pcm  ${filename2%.*}.opus
done
#pcm批量转换为opus,文件名有序
for i in {1..10}
do
    echo $i
    opusenc --raw-bits 16 --raw-rate 16000 --raw-chan 1 --comp 10 --cvbr  --framesize 20 --bitrate 28  ${i}.pcm  ${i}.opus

参考文章:
1、shell获取文件名和后缀

  • 4
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
非常感谢您的提问。以下是使用c语言编写pcmopus格式的代码: #include <stdio.h> #include <stdlib.h> #include <opus/opus.h> #define FRAME_SIZE 960 #define CHANNELS 1 #define APPLICATION OPUS_APPLICATION_AUDIO int main(int argc, char *argv[]) { if (argc != 3) { printf("Usage: %s input.pcm output.opus\n", argv[0]); return 1; } FILE *input_file = fopen(argv[1], "rb"); if (!input_file) { printf("Failed to open input file: %s\n", argv[1]); return 1; } FILE *output_file = fopen(argv[2], "wb"); if (!output_file) { printf("Failed to open output file: %s\n", argv[2]); fclose(input_file); return 1; } int error; OpusEncoder *encoder = opus_encoder_create(48000, CHANNELS, APPLICATION, &error); if (error != OPUS_OK) { printf("Failed to create encoder: %s\n", opus_strerror(error)); fclose(input_file); fclose(output_file); return 1; } opus_encoder_ctl(encoder, OPUS_SET_BITRATE(64000)); unsigned char *input_buffer = (unsigned char *) malloc(FRAME_SIZE * CHANNELS * sizeof(short)); unsigned char *output_buffer = (unsigned char *) malloc(FRAME_SIZE * CHANNELS * sizeof(short)); while (1) { int samples_read = fread(input_buffer, sizeof(short), FRAME_SIZE * CHANNELS, input_file); if (samples_read <= 0) { break; } int bytes_written = opus_encode(encoder, (opus_int16 *) input_buffer, FRAME_SIZE, output_buffer, FRAME_SIZE * CHANNELS); if (bytes_written < 0) { printf("Failed to encode frame: %s\n", opus_strerror(bytes_written)); break; } fwrite(output_buffer, 1, bytes_written, output_file); } free(input_buffer); free(output_buffer); opus_encoder_destroy(encoder); fclose(input_file); fclose(output_file); return 0; }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值