Java.io.IOException: Cannot merge AudioSampleEntry when merging video using Mp4Parser

I am working on a merger of two videos. I take the video from the phone’s memory and transfer it as a string. Then these videos are combined. I saw that if I fasten a video that is shot from the camera, then it works fine, the merger is going well. But as soon as a different video file is taken and taken, trying to combine, it throws an exception:

java.io.IOException: Cannot merge AudioSampleEntry{bytesPerSample=0, bytesPerFrame=0, bytesPerPacket=0, samplesPerPacket=0, packetSize=0, compressionId=0, soundVersion=0, sampleRate=24000, sampleSize=16, channelCount=2, boxes=[com.googlecode.mp4parser.boxes.mp4.ESDescriptorBox@fffffab7]} and AudioSampleEntry{bytesPerSample=0, bytesPerFrame=0, bytesPerPacket=0, samplesPerPacket=0, packetSize=0, compressionId=0, soundVersion=0, sampleRate=22050, sampleSize=16, channelCount=2, boxes=[com.googlecode.mp4parser.boxes.mp4.ESDescriptorBox@fffff9fb]} 08-22 15:59:03.347 27476-27558/in.pinelane.myhovi W/System.err: at com.googlecode.mp4parser.authoring.tracks.AppendTrack.mergeStsds(AppendTrack.java:116) 08-22 15:59:03.347 27476-27558/in.pinelane.myhovi W/System.err: at com.googlecode.mp4parser.authoring.tracks.AppendTrack.<init>(AppendTrack.java:59)

and does not save the file inside the repository. Also, if the height is different from the video, then this gives me this exception, and it does not save any file.

E/isoparser: AppendTrack:height differs

This is my activity, you can see the code:

//asynch task to merge the videos in background
    class MergeVideos extends AsyncTask<ArrayList<File>, Integer, String>{

        @Override
        protected String doInBackground(ArrayList<File>... params) {
                ArrayList<Movie> inMovies = new ArrayList<>();
                for(File file : params[0]){
                    Movie movie = MovieCreator.build(file.getAbsolutePath());
                    inMovies.add(movie);
                }

                List<Track> videoTracks = new LinkedList<Track>();
                List<Track> audioTracks = new LinkedList<Track>();
                for (Movie m : inMovies) {
                    for (Track t : m.getTracks()) {
                        if (t.getHandler().equals("soun")) {
                            audioTracks.add(t);
                        }
                        if (t.getHandler().equals("vide")) {
                            videoTracks.add(t);
                        }
                    }
                }

                Movie result = new Movie();

                if (audioTracks.size() > 0) {
                    result.addTrack(new AppendTrack(audioTracks
                            .toArray(new Track[audioTracks.size()])));
                }
                if (videoTracks.size() > 0) {
                    result.addTrack(new AppendTrack(videoTracks
                            .toArray(new Track[videoTracks.size()])));
                }

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

                @SuppressWarnings("resource")
                FileChannel fileChannel = new RandomAccessFile(String.format(Environment
                        .getExternalStorageDirectory() + "/MyHoviVideo.mp4"),
                        "rw").getChannel();
                out.writeContainer(fileChannel);
                fileChannel.close();

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

            //retruning the file after successfull completion of the merging
            String mFileName = Environment.getExternalStorageDirectory()
                    .getAbsolutePath();
            mFileName += "/MyHoviVideo.mp4";
            //   = mFileName;
            return mFileName;
        }

        @Override
        protected void onPostExecute(String s) {
            super.onPostExecute(s);
            progressDialog.dismiss();
            Log.e("FILE_PATH===",s);
            playVideo(s);

        }
    }

    void playVideo(String play){
        mVideoPlayer.setVideoPath(play);
        mMediaController = new MediaController(this);
        mMediaController.setMediaPlayer(mVideoPlayer);
        mVideoPlayer.setMediaController(mMediaController);
        mVideoPlayer.setBackgroundColor(Color.TRANSPARENT);
        mVideoPlayer.requestFocus();
        mVideoPlayer.start();
    }

There is a way to do this, and the way is to make the sound and pitch (resolution) equal before merging. I searched for FFMPEG, but in android it is very difficult to implement. I need a good solution for this

+4

Source: https://habr.com/ru/post/1684202/


All Articles