java.io.IOException:无法使用Mp4Parser合并视频中的AudioSampleEntry

时间:2017-08-22 08:27:16

标签: android video merge mp4parser

我一直在努力合并两个视频。我正在从手机存储中取出视频并以字符串的形式传递它们。然后这些视频正在合并。我已经看到,如果我合并从相机中取出的视频,那么它工作正常,合并很顺利。但是,只要采取不同的视频文件并尝试合并,它就会抛出一个例外

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)

并且不会将任何文件保存在存储中。此外,如果视频的高度不同,那么它会给我这个例外,这也不会保存任何文件

E/isoparser: AppendTrack:height differs

这是我的活动,你可以看到代码:

//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();
    }

有一种方法可以做到这一点,方法是在合并之前使音频和高度(分辨率)相等。我已经找了FFMPEG,但在android中实现它很安静。我需要一个很好的解决方案

0 个答案:

没有答案