1

Androidで吹き替えアプリを作りたいです。アプリの流れは次のとおりです。

  1. ギャラリーからビデオとオーディオを取得します。
  2. 動画ファイルの原音を小さくします。そして、このビデオファイルに選択したオーディオをミックス (ダブ) します。
  3. このビデオ ファイルのオーディオをミキシングした後、外部メモリに保存します。

これには MediaMuxer を使用していますが、うまくいきません。これに関して私を助けてください。

よろしく、 プラテック

4

1 に答える 1

0

mediaMuxer を使用してビデオとオーディオをダビングするために同じものを探していましたが、MediaMuxer は私が初心者であるため理解するのが少し難しい概念でした。私はこのgithubコードを参照することになりました。https://github.com/tqnst/MP4ParserMergeAudioVideo 私の救世主でした。あの人には本当に感謝。そこから必要なコードをピックアップしました。つまり、指定したオーディオでビデオをダビングしました。

これが私のプロジェクトで使用した私のコードです

private void mergeAudioVideo(String originalVideoPath,String AudioPath,String OutPutVideoPath) {
    // TODO Auto-generated method stub
    Movie video = null;
    try {
        new MovieCreator();
        video = MovieCreator.build(originalVideoPath);
    } catch (RuntimeException e) {
        e.printStackTrace();

    } catch (IOException e) {
        e.printStackTrace();

    }

    Movie audio = null;
    try {
        new MovieCreator();
        audio = MovieCreator.build(AudioPath);
    } catch (IOException e) {
        e.printStackTrace();

    } catch (NullPointerException e) {
        e.printStackTrace();

    }
    List<Track> videoTracks = new LinkedList<Track>();
    for (Track t : video.getTracks()) {
        if (t.getHandler().equals("vide")) {
            videoTracks.add(t);
         //seperate the video from the orginal video
        }
    }
    Track audioTrack = audio.getTracks().get(0);// get your audio track to dub the video
    Movie result = new Movie();
    result.addTrack(videoTracks.get(0)); // add the video seprated from the originals
    result.addTrack(audioTrack); //add the track to be put in resul video

    Container out = new DefaultMp4Builder().build(result);

    FileOutputStream fos = null;
    try {
        fos = new FileOutputStream(OutPutVideoPath);
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }

    BufferedWritableFileByteChannel byteBufferByteChannel = new BufferedWritableFileByteChannel(fos);
    try {
        out.writeContainer(byteBufferByteChannel);
        byteBufferByteChannel.close();
        fos.close();
    } catch (IOException e) {
        e.printStackTrace();
    }

}

ここでは、outputVideo データをディレクトリに書き込むための BufferedWritableFileByteChannel クラスを示します。

public class BufferedWritableFileByteChannel implements WritableByteChannel {
private static final int BUFFER_CAPACITY = 1000000;

private boolean isOpen = true;
private final OutputStream outputStream;
private final ByteBuffer byteBuffer;
private final byte[] rawBuffer = new byte[BUFFER_CAPACITY];

public BufferedWritableFileByteChannel(OutputStream outputStream) {
    this.outputStream = outputStream;
    this.byteBuffer = ByteBuffer.wrap(rawBuffer);
}

@Override
public int write(ByteBuffer inputBuffer) throws IOException {
    int inputBytes = inputBuffer.remaining();

    if (inputBytes > byteBuffer.remaining()) {
        dumpToFile();
        byteBuffer.clear();

        if (inputBytes > byteBuffer.remaining()) {
            throw new BufferOverflowException();
        }
    }

    byteBuffer.put(inputBuffer);

    return inputBytes;
}

@Override
public boolean isOpen() {
    return isOpen;
}

@Override
public void close() throws IOException {
    dumpToFile();
    isOpen = false;
}
private void dumpToFile() {
    try {
        outputStream.write(rawBuffer, 0, byteBuffer.position());
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
  }
}

プロジェクトにライブラリを追加することを忘れないでください。

これはあなたの質問に対する正確な答えではないかもしれません。しかし、少なくとも可能性のある解決策に光を当てることができます。

于 2015-08-20T11:42:35.327 に答える