mp4解析器无法尝试加入2 mp4文件

时间:2015-01-08 12:06:34

标签: android video mp4parser

我正在尝试使用mp4parser库追加两个mp4文件,但它给了我以下错误:

我正在使用isoparser-1.0.5.4.jar和aspectjrt-1.8.2.jar

01-08 17:00:49.731: E/AndroidRuntime(14156): FATAL EXCEPTION: DoAppend
01-08 17:00:49.731: E/AndroidRuntime(14156): Process: org.bestforce.testmp4parser, PID: 14156
01-08 17:00:49.731: E/AndroidRuntime(14156): java.lang.NoClassDefFoundError: com.googlecode.mp4parser.authoring.Movie[]
01-08 17:00:49.731: E/AndroidRuntime(14156):    at org.bestforce.testmp4parser.AppendExample$1.run(AppendExample.java:124)
01-08 17:00:49.731: E/AndroidRuntime(14156):    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
01-08 17:00:49.731: E/AndroidRuntime(14156):    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
01-08 17:00:49.731: E/AndroidRuntime(14156):    at java.lang.Thread.run(Thread.java:841)

我正在使用以下代码:

private void doAppend() {
        mProgressDialog = Ut.ShowWaitDialog(mCxt, 0);

        if(mThreadExecutor == null)
            mThreadExecutor = Executors.newSingleThreadExecutor(new SimpleThreadFactory("DoAppend"));

        this.mThreadExecutor.execute(new Runnable() {
            public void run() {
                try {
                    File folder = Ut.getTestMp4ParserVideosDir(mCxt);

                    if (!folder.exists()) {
                        Log.d(TAG, "failed to create directory");
                    }

//                  AssetFileDescriptor afd1 = mCxt.getResources().openRawResourceFd(R.raw.sample1);
//                  AssetFileDescriptor afd2 = mCxt.getResources().openRawResourceFd(R.raw.sample2);
//                  FileDescriptor fd1 = afd1.getFileDescriptor();
//                  FileDescriptor fd2 = afd2.getFileDescriptor();
//                  FileChannel fc1 = new FileInputStream(fd1).getChannel();
//                  FileChannel fc2 = new FileInputStream(fd2).getChannel();
//                  
//                  Movie[] inMovies = new Movie[]{MovieCreator.build(fc1),
//                          MovieCreator.build(fc2)};
//
//                  afd1.close();
//                  afd2.close();

//                  InputStream is1 = getResources().openRawResource(R.raw.sample1);
//                  InputStream is2 = getResources().openRawResource(R.raw.sample2);

                    FileInputStream fis1 = new FileInputStream(folder.getPath() + File.separator + "sample1" + ".mp4");
                    FileInputStream fis2 = new FileInputStream(folder.getPath() + File.separator + "sample2" + ".mp4");

//                  Movie[] inMovies = new Movie[]{MovieCreator.build(new FileInputStream(folder.getPath() + File.separator + "sample1" + ".mp4").getChannel()),
//                          MovieCreator.build(new FileInputStream(folder.getPath() + File.separator + "sample2" + ".mp4").getChannel())};
                    Movie[] inMovies = new Movie[]{MovieCreator.build((DataSource) fis1.getChannel()),
                    MovieCreator.build((DataSource) fis2.getChannel())};

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

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

                    // Create a media file name
                    String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
                    String filename = folder.getPath() + File.separator + "TMP4_APP_OUT_" + timeStamp + ".mp4";

//                  File fo = new File(filename);

//                  FileChannel fc = new RandomAccessFile(String.format("output.mp4"), "rw").getChannel();
//                  FileChannel fco = new FileOutputStream(filename).getChannel();
                    FileOutputStream fos = new FileOutputStream(filename);
                    FileChannel fco = fos.getChannel();

                    fco.position(0);
                    out.getBox(fco);
                    fco.close();
                    fos.close();
                    fis1.close();
                    fis2.close();

                    Message.obtain(mHandler, R.id.append, 1, 0, filename).sendToTarget();
                } catch (FileNotFoundException e) {
                    Message.obtain(mHandler, R.id.append, 0, 0, e.getMessage()).sendToTarget();
                    e.printStackTrace();
                } catch (IOException e) {
                    Message.obtain(mHandler, R.id.append, 0, 0, e.getMessage()).sendToTarget();
                    e.printStackTrace();
                }

            }
        });
    }

请帮助我陷入困境。

0 个答案:

没有答案