完美解决个人微信音频amr文件与mp3格式互转

tar -jxvf ffmpeg-3.4.1.tar.bz2

cd ffmpeg-3.4.1

./configure --prefix=/usr/local --pkg-config-flags=–static --enable-libmp3lame --disable-x86asm

make && make install


2、安装/silk-v3-decoder
 

cd /usr/local/soft

wget https://github.com/kn007/silk-v3-decoder/archive/master.zip

unzip master.zip

chmod -R +x /usr/local/soft/silk-v3-decoder-master/

silk-v3-decoder/converter.sh 微信amr文章文件路径名 mp3


3、改造一个encoder脚本,decoder已经有了不用改造了

converter-encoder.sh(请拷贝以下脚本放到silk-v3-decoder-master目录下)

#!/bin/bash

File: converter.sh

Date: August 19th, 2016

Time: 18:56:52 +0800

Author: kn007 <kn007@126.com>

Blog: https://kn007.net

Link: https://github.com/kn007/silk-v3-encoder

Usage: sh converter.sh silk_v3_file/input_folder output_format/output_folder flag(format)

Flag: not define ---- not define, convert a file

other value ---- format, convert a folder, batch conversion support

Requirement: gcc ffmpeg

Colors

RED=“$(tput setaf 1 2>/dev/null || echo ‘\e[0;31m’)”

GREEN=“$(tput setaf 2 2>/dev/null || echo ‘\e[0;32m’)”

YELLOW=“$(tput setaf 3 2>/dev/null || echo ‘\e[0;33m’)”

WHITE=“$(tput setaf 7 2>/dev/null || echo ‘\e[0;37m’)”

RESET=“$(tput sgr 0 2>/dev/null || echo ‘\e[0m’)”

Main

cur_dir=$(cd dirname $0; pwd)

if [ ! -r “$cur_dir/silk/encoder” ]; then

echo -e “ W H I T E [ N o t i c e ] {WHITE}[Notice] WHITE[Notice]{RESET} Silk v3 Encoder is not found, compile it.”

cd $cur_dir/silk

make && make encoder

[ ! -r “KaTeX parse error: Expected 'EOF', got '&' at position 24: …silk/encoder" ]&̲amp;&amp;echo -…{RED}[Error]${RESET} Silk v3 Encoder Compile False, Please Check Your System For GCC.”&&exit

echo -e “ W H I T E = = = = = = = = = S i l k v 3 E n c o d e r C o m p i l e F i n i s h = = = = = = = = = {WHITE}========= Silk v3 Encoder Compile Finish ========= WHITE=========Silkv3EncoderCompileFinish========={RESET}”

fi

cd $cur_dir

while [ $3 ]; do

[[ ! -z “KaTeX parse error: Expected 'EOF', got '&' at position 19: …dof ffmpeg)" ]]&̲amp;&amp;echo -…{RED}[Error]${RESET} ffmpeg is occupied by another application, please check it.”&&exit

[ ! -d “KaTeX parse error: Expected 'EOF', got '&' at position 5: 1" ]&̲amp;&amp;echo -…{RED}[Error]${RESET} Input folder not found, please check it.”&&exit

TOTAL=$(ls $1|wc -l)

[ ! -d “$2” ]&&mkdir “KaTeX parse error: Expected 'EOF', got '&' at position 3: 2"&̲amp;&amp;echo -…{WHITE}[Notice]${RESET} Output folder not found, create it.”

[ ! -d “KaTeX parse error: Expected 'EOF', got '&' at position 5: 2" ]&̲amp;&amp;echo -…{RED}[Error]${RESET} Output folder could not be created, please check it.”&&exit

CURRENT=0

echo -e “ W H I T E = = = = = = = = = B a t c h C o n v e r s i o n S t a r t = = = = = = = = = = {WHITE}========= Batch Conversion Start ========== WHITE=========BatchConversionStart=========={RESET}”

ls $1 | while read line; do

let CURRENT+=1

ffmpeg -i “ 1 / 1/ 1/line” -f s16le -ar 24000 -ac 1 -acodec pcm_s16le “ 2 / 2/ 2/line.pcm” > /dev/null 2>&1 

$cur_dir/silk/encoder “ 2 / 2/ 2/line.pcm” “ 2 / 2/ 2/{line%.*}.$3” -tencent > /dev/null 2>&1

rm “ 2 / 2/ 2/line.pcm”

[ ! -f “ 2 / 2/ 2/{line%.*}.KaTeX parse error: Expected 'EOF', got '&' at position 5: 3" ]&̲amp;&amp;echo -…CURRENT/ T O T A L ] TOTAL] TOTAL]{YELLOW}[Warning]${RESET} Convert $line false, maybe ffmpeg no format handler for $3.”&&continue

echo -e “[ C U R R E N T / CURRENT/ CURRENT/TOTAL] G R E E N [ O K ] {GREEN}[OK] GREEN[OK]{RESET} Convert $line To ${line%.*}.$3 Finish.”

done

echo -e “ W H I T E = = = = = = = = = B a t c h C o n v e r s i o n F i n i s h = = = = = = = = = {WHITE}========= Batch Conversion Finish ========= WHITE=========BatchConversionFinish========={RESET}”

exit

done

ffmpeg -i “$1” -f s16le -ar 24000 -ac 1 -acodec pcm_s16le “$1.pcm” > /dev/null 2>&1 

$cur_dir/silk/encoder “ 1. p c m " " 1.pcm" " 1.pcm""{1%.*}.amr” -tencent > /dev/null 2>&1

rm “$1.pcm”

[ ! -f “KaTeX parse error: Expected '}', got 'EOF' at end of input: …;&amp;echo -e "{YELLOW}[Warning]${RESET} Convert $1 false, maybe ffmpeg no format handler for amr.”&&exit

echo -e “ G R E E N [ O K ] {GREEN}[OK] GREEN[OK]{RESET} Convert $1 To ${1%.*}.amr Finish.”

exit


4、用java调用脚本
 

private static String silkv3Path=“/usr/local/soft/silk-v3-decoder-master/”;

/**

  • 将amr转成mp3

  • @param coderPath

  • @param amrfilePath

*/

public static void converterDecoderMp3(String coderPath, String amrfilePath) {

if(StringUtils.isBlank(coderPath)){

coderPath = silkv3Path;

}

String decoderCmd = coderPath + "converter.sh " + amrfilePath;

exeCmd(decoderCmd);

}

/**

  • 将mp3转成amr

  • @param coderPath

  • @param mp3filePath

*/

public static void converterEncoderAmr(String coderPath, String mp3filePath) {

if(StringUtils.isBlank(coderPath)){

coderPath = silkv3Path;

}

String encoderCmd= coderPath + "converter-encoder.sh " + mp3filePath;

exeCmd(encoderCmd);

}

private static void exeCmd(String commandStr) {

BufferedReader br = null;

try {

Process p = Runtime.getRuntime().exec(commandStr);

br = new BufferedReader(new InputStreamReader(p.getInputStream()));

String line = null;

StringBuilder sb = new StringBuilder();

while ((line = br.readLine()) != null) {

sb.append(line + “\n”);

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值