No sound in MP4 file - Android

I am using MP4ParserMergeAudioVideo to add a new sound to a file MP4

. The library said it uses a file .wav

, if I save the file .wav

in a directory and name the audio file as example.m4a

, I get a file not found exception. So I changed the file to audio file .m4a

. The code is shown below.

findViewById(R.id.append).setOnClickListener(new OnClickListener() {
    @Override
    public void onClick(View v) {
        String root = Environment.getExternalStorageDirectory().toString();
        Log.e("",""+root);
        String audio = root + "/download/"+"mymovieaudio.m4a";
        String video = root + "/download/"+"My_Movie.mp4";
        String output = root + "/download/ouput.mp4";
        mux(video, audio, output);
    }
});

      

The mux function is like this

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);
        video.addTrack(audioTrack);

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

      

I am successfully getting the file output.mp4

in the download directory of my device. The problem is that it has no sound. Please help. Thanks in advance.

+1


source to share





All Articles