Join video (with sound) and external audio

3

I need to join a file mp4 (with audio included, recorded from the camera), a song in mp3 (or aac , or the format that is, I am indifferent in this case). The only condition is that I can not use FFMPEG . I found on the internet the MP4Parser that could be similar to what I'm looking for but, there's been no way to make it work:

String f1 = Environment.getExternalStorageDirectory() + "/small.mp4";
String f2 = Environment.getExternalStorageDirectory() + "/musica_1.aac";
MovieCreator.build(f1);
MovieCreator.build(f2);

The error that always gives me is:

 java.lang.NullPointerException: Attempt to invoke virtual method 'java.util.List com.coremedia.iso.boxes.MovieBox.getBoxes(java.lang.Class)' on a null

Surely someone will tell me to check that f1 and f2 are not null: no, they are not, it is more, this problem only arises when I try to join the file I have recorded; if I use a mp4 downloaded from the internet it does not join me but at least it does not give me that error. The error arises as a result of trying to get List<TrackBox> trackBoxes = isoFile.getMovieBox().getBoxes(TrackBox.class);  I need to be able to do the same for the file recorded with the phone. Next I indicate the configuration to record the video from the phone:

    mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
    mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.SURFACE);
    mMediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
    if (mNextVideoAbsolutePath == null || mNextVideoAbsolutePath.isEmpty()) {
        mNextVideoAbsolutePath = getVideoFilePath(getActivity());
    }
    mMediaRecorder.setCaptureRate(30);
     mMediaRecorder.setOutputFile(Environment.getExternalStorageDirectory()+"/small.mp4");
    mMediaRecorder.setVideoEncodingBitRate(10000000);
    mMediaRecorder.setVideoFrameRate(30);
    mMediaRecorder.setVideoSize(mVideoSize.getWidth(), mVideoSize.getHeight());
    mMediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.H264);
    mMediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);

Does anyone know a way to join an mp4 with an aac (mp3 or whatever)?

    
asked by garodev 21.10.2016 в 14:03
source

1 answer

1

Have you already tried with the documentation examples? First save the video from the camera to a file, since you have it in the file now if you "join" them.

H264TrackImpl h264Track = new H264TrackImpl(new FileDataSourceImpl("video.h264"));
AACTrackImpl aacTrack = new AACTrackImpl(new FileDataSourceImpl("audio.aac"));

Movie movie = new Movie();
movie.addTrack(h264Track);
movie.addTrack(aacTrack);

Container mp4file = new DefaultMp4Builder().build(movie);

FileChannel fc = new FileOutputStream(new File("output.mp4")).getChannel();
mp4file.writeContainer(fc);
fc.close();

link

    
answered by 24.10.2016 в 18:52