2

.opus ファイルを .mp3 に変換するための Android アプリを開発しています。この操作を実行するためにネイティブ コードを使用しています。以下は、私が使用している関数のソースコードです。.mp3 出力は 0 バイトで生成されます。:(

方法

JNIEXPORT void JNICALL Java_methodName 

(JNIEnv *env, jclass クラス, jstring opus_path, jstring empty, jstring dest_path) {

  const char *outputStr = (*env)->GetStringUTFChars(env, dest_path, 0);
  const char *opusStr = (*env)->GetStringUTFChars(env, opus_path, 0);
  const char *v19 = (*env)->GetStringUTFChars(env, test, 0);
  FILE *stream = fopen(outputStr, "wb");
  lame_t lame = lame_init();
  lame_set_in_samplerate(lame, 48000);
lame_set_brate(lame,64);
lame_init_params(lame);
cleanupPlayer();
initPlayer(opusStr);
jint *v20;
jbyte *v22;
jbyte *v23;
jint v12;
jint v13;
jint v21;
jint v16;
jint v17;


 do
  {
    fillBuffer(v22, 16384, v20);

    v12 = lame_encode_buffer(lame, v22, v22, v20, v23, 8192);
    fwrite(v23, v12, 1, stream);
  }
  while ( v20 != 1 );
  v13 = lame_encode_flush(lame, v23, 8192);
    fwrite(v23, v13, 1, stream);
    cleanupPlayer(); 
    fclose(stream);
    lame_close(lame);     
  }

フィルバッファ: コード

void fillBuffer(uint8_t *buffer, int capacity, int *args) {
if (_opusFile) {
    args[1] = max(0, op_pcm_tell(_opusFile));

    if (_finished) {
        args[0] = 0;
        args[1] = 0;
        args[2] = 1;
        return;
    } else {
        int writtenOutputBytes = 0;
        int endOfFileReached = 0;

        while (writtenOutputBytes < capacity) {
            int readSamples = op_read(_opusFile, (opus_int16 *)(buffer + writtenOutputBytes), (capacity - writtenOutputBytes) / 2, NULL);

            if (readSamples > 0) {
                writtenOutputBytes += readSamples * 2;
            } else {
                if (readSamples < 0) {
                    LOGE("op_read failed: %d", readSamples);
                }
                endOfFileReached = 1;
                break;
            }
        }

        args[0] = writtenOutputBytes;

        if (endOfFileReached || args[1] + args[0] == _totalPcmDuration) {
            _finished = 1;
            args[2] = 1;
        } else {
            args[2] = 0;
        }
    }
    } else {
        memset(buffer, 0, capacity);
        args[0] = capacity;
        args[1] = _totalPcmDuration;
    }
}

私はこの時点で立ち往生しています。opusとlame.opusを使用するように変換して、誰かがこれを手伝ってくれませんか。.mp3

4

0 に答える 0