хромой mp3-кодировщик возвращает плохой mp3-файл

Я пробовал использовать хромой mp3-кодировщик в android для преобразования wav-файла в mp3, libmp3lame.so был сгенерирован, и приложение успешно конвертировало test.wav в test.mp3, но проблема в том, что mp3-файл похож на ЭТО, мой файл wav - это голос говорящего, и когда он ничего не конвертирует, можно понять, в чем проблема? это из-за опций мп3 или нет?

Вот мой основной код:

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();
}

}

person user2975740    schedule 19.11.2013    source источник
comment
привет ты нашел решение этой проблемы?   -  person Majid Laissi    schedule 29.08.2014
comment
LAME должен быть очень стабильным кодировщиком, вряд ли проблема в LAME. Опции не должны испортить конечный результат. Вы, наверное, что-то делаете не так.   -  person Danijel    schedule 14.01.2016


Ответы (1)


Мы конвертируем с помощью php в Windows и ffmpeg.exe от MediaHuman, который также делает резервную копию оригинала.

<?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');
?>
person Community    schedule 25.05.2019