lame mp3编码器返回坏的mp3文件

时间:2013-11-19 12:03:32

标签: android mp3 lame

我在android中尝试了蹩脚的mp3编码器将wav文件转换为mp3,生成了libmp3lame.so并且应用程序将test.wav成功转换为test.mp3,但问题是mp3文件就像THIS ,我的wav文件是一个说话的声音,当它转换时没有什么可以理解,有什么问题?是因为mp3选项还是没有?

这是我的主要代码:

public class Main extends Activity {

static {
    System.loadLibrary("mp3lame");
}

private native void initEncoder(int numChannels, int sampleRate,
        int bitRate, int mode, int quality);

private native void destroyEncoder();

private native int encodeFile(String sourcePath, String targetPath);

public static final int NUM_CHANNELS = 1;
public static final int SAMPLE_RATE = 16000;
public static final int BITRATE = 128;
public static final int MODE = 1;
public static final int QUALITY = 2;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    initEncoder(NUM_CHANNELS, SAMPLE_RATE, BITRATE, MODE, QUALITY);

    encodeFile(Environment.getExternalStorageDirectory()
            .getPath() + "/test.wav", Environment
            .getExternalStorageDirectory().getPath() + "/test.mp3")
}

@Override
public void onDestroy() {
    destroyEncoder();
    super.onDestroy();
}

}

1 个答案:

答案 0 :(得分:0)

  

我们在Windows中使用php和MediaHuman的ffmpeg.exe进行转换,   还会备份原始文件。

<?php

ini_set('display_errors', 1);
const SAMPLERATE = 44100;
const BITRATE = 128;
const CHANNELS = 2;
$dir = 'newmusic';

include('ID3TagsReader.php');

function needsConversion($file) {
$reader = new ID3TagsReader();
$headers = $reader->getMP3BitRateSampleRate($file);

if($headers['sampleRate'] != SAMPLERATE) return true;
if($headers['bitRate'] != BITRATE) return true;

return false;
}

function backupFile($file) {
$source = $file;
$dest = "C:\\backup\\music\\" . $file . " - "  . date('YmdHis') . ".mp3";

echo "Copying $source to $dest\n";
copy($source, $dest);
}

function convertFile($file) {
    echo "Converting file " . $file . "\n";

    $ffmpeg = escapeshellarg("C:\\Program Files\\MediaHuman\\Audio 
Converter\\ffmpeg.exe");
    $source = escapeshellarg($file);
    $samplerate = escapeshellarg(SAMPLERATE);
    $bitrate = escapeshellarg(BITRATE * 1000);
    $channels = escapeshellarg(CHANNELS);

    echo system("$ffmpeg -i $source -ar $samplerate -ac $channels -ab $bitrate -y 
temp.mp3 2>&1");

    rename('temp.mp3', $file);
}

chdir($dir);
foreach(glob('*.mp3') as $file) {
if(needsConversion($file)) {
    backupFile($file);
    convertFile($file);
}
}

header('Location: some place to go');
?>