¿Cómo combinar múltiples archivos de audio en un momento específico con un archivo de vídeo en android?
Lo que quiero hacer es fusionar múltiples archivos de audio a un archivo de video a tiempo específico en mi proyecto android.
Por ejemplo, con dos archivos de audio: a1 con 5 segundos de longitud, a2 con 5 segundos de longitud y vídeo V1 con 20 segundos de longitud. Así que quiero fusionar audio a1 a video V1 en el tiempo 00: 01s a 00: 05s, audio a2 a video V1 a tiempo 00: 10s a 00: 15s. "Mezclar" aquí me refiero al archivo de vídeo se añadirá voz en off de los archivos de audio a1 y a2 en el momento específico, no añadir.
- Rotar vídeo con Mp4parser
- Problema al cortar varios clips de una película con la biblioteca mp4parser
- Mp4parser se ejecuta en el dispositivo de Android Studio pero se bloquea al instalar manualmente el APK
- Es la biblioteca mp4parser java tiene la versión de Android
- Rotar vídeo con mp4parser de acuerdo con la cámara utilizada
Después de buscar en torno a Google y StackOverflow, he encontrado la biblioteca Mp4Parser, pero por desgracia, sólo puedo fusionar totalmente la pista de audio a pista de vídeo. Mi pregunta es cómo fusionarlo en un momento específico y de varias pistas de audio?
Aquí está el código que usé:
public boolean mux(String videoFile, String audioFile, String outputFile) { Movie video; try { video = new MovieCreator().build(videoFile); } catch (RuntimeException e) { e.printStackTrace(); return false; } catch (IOException e) { e.printStackTrace(); return false; } Movie audio; try { audio = new MovieCreator().build(audioFile); } catch (IOException e) { e.printStackTrace(); return false; } catch (NullPointerException e) { e.printStackTrace(); return false; } Track audioTrack = audio.getTracks().get(0); List<Track> tracks = new ArrayList<Track>(); tracks.add(video.getTracks().get(0)); tracks.add(audioTrack); video.setTracks(tracks); Container out = new DefaultMp4Builder().build(video); FileOutputStream fos; try { fos = new FileOutputStream(outputFile); } catch (FileNotFoundException e) { e.printStackTrace(); return false; } BufferedWritableFileByteChannel byteBufferByteChannel = new BufferedWritableFileByteChannel(fos); try { out.writeContainer(byteBufferByteChannel); byteBufferByteChannel.close(); fos.close(); } catch (IOException e) { e.printStackTrace(); return false; } return true; } private static 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]; private 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); } } }
Cualquier ayuda sería muy apreciar! Muchas gracias.
- Combine Mp4s usando mp4parser en Android
- Combinar / fusionar / mezclar múltiples archivos de audio con MP4Parser en Android
- Vídeo inverso en android
- Concatenar archivos mp4 en Android usando halfninja ffmpeg
- Cómo fusionar archivos de audio y video en android
- Aplicación de falla en la fusión de videoclips MP4
- Android: Fusionar / concatenar dos archivos de audio cuelga la aplicación
- La fusión de clips mp4 con mp4parser hace que el audio detrás del video