航行在蓝天的蚂蚱 2018-02-23 06:56 采纳率: 0%
浏览 2347
已结题

FFmpeg音频拼接报错,恳请大牛们帮忙解决一下吧!

android端用FFmpeg命令拼接音频时,只要超过8个音频就会报错,不知道是怎么回事?
ffmpeg -i "concat:a.mp3|b.mp3" -acodec copy c.mp3,代码原理就是这段FFmpeg拼接命令。
哪位大牛知道这个问题怎么解决?

 public native int command(String[] argv);


    public void handlerCommand(final List<String> paths) {
        Observable.create(new ObservableOnSubscribe<String>() {
            @Override
            public void subscribe(ObservableEmitter<String> e) throws Exception {
                try {
                    System.out.println("---------------");
                    //调用ffmpeg进行处理
                    String path = jointAudio(paths);
                    System.out.println("----------------");
//                    File file = new File(path);
//                    String parent = file.getParent();
                    //最终拼接的音频文件进行重命名
//                    File reNameFile = new File(parent.concat("/eng100.mp3"));
//                    boolean isSuccess = file.renameTo(reNameFile);
//                    //删除碎片音频文件
//                    if (isSuccess) {
//                        deleteFile(parent);
//                    }
                    e.onNext(path);
                } catch (Exception ex) {
                    ex.printStackTrace();
                    e.onError(ex);
                }
            }
        }).subscribeOn(Schedulers.newThread())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<String>() {
                    @Override
                    public void onSubscribe(Disposable d) {
                        if (onHandleListener != null) {
                            onHandleListener.onStart();
                        }
                    }

                    @Override
                    public void onNext(String msg) {
                        if (onHandleListener != null) {
                            onHandleListener.onEnd(msg);
                        }
                    }

                    @Override
                    public void onError(Throwable e) {
                        e.printStackTrace();

                    }

                    @Override
                    public void onComplete() {

                    }
                });

    }

    //递归拼接音频
    private String jointAudio(List<String> paths) {
        List<String> alls = new ArrayList<>();
        for (int i = 0; i < paths.size(); i++) {

            if ((i+1) % 2 == 0) {
                String[] pathArr = new String[2];
                pathArr[0] = paths.get(i - 1);
                pathArr[1] = paths.get(i);
                File file = new File(pathArr[0]);
                String path = file.getParent().concat(File.separator).concat(String.valueOf(System.currentTimeMillis()).concat("-debris.mp3"));
                String[] command = FFmpegUtil.concatAudio(pathArr, path);
                command(command);
                alls.add(path);
            } else if (i == paths.size() - 1) {
                alls.add(paths.get(i));
            }
        }
        if (alls.size() == 1) {
            return alls.get(alls.size() - 1);
        } else {
            return jointAudio(alls);
        }

    }

一下是我两个两个拼接的打印的命令,最后报错了!

 02-23 14:11:57.643 13189-13189/com.xy.openndk.audiojointdemo I/System.out: 开始拼接
02-23 14:11:57.655 13189-13810/com.xy.openndk.audiojointdemo I/System.out: ---------------
02-23 14:11:57.657 13189-13810/com.xy.openndk.audiojointdemo I/System.out: ffmpeg -i concat:/storage/emulated/0/com.wanhe.eng100.listening/UploadFile/Book/4b517786-04b4-47ec-8fb9-0eea869002f1/common/Book_Year.mp3|/storage/emulated/0/com.wanhe.eng100.listening/UploadFile/Book/4b517786-04b4-47ec-8fb9-0eea869002f1/common/Book_Title.mp3 -acodec copy /storage/emulated/0/com.wanhe.eng100.listening/UploadFile/Book/4b517786-04b4-47ec-8fb9-0eea869002f1/common/1519366317655-debris.mp3
02-23 14:11:57.706 13189-13810/com.xy.openndk.audiojointdemo I/System.out: ffmpeg -i concat:/storage/emulated/0/com.wanhe.eng100.listening/UploadFile/Book/4b517786-04b4-47ec-8fb9-0eea869002f1/common/5s.mp3|/storage/emulated/0/com.wanhe.eng100.listening/UploadFile/Book/4b517786-04b4-47ec-8fb9-0eea869002f1/common/Section_One_Begin.mp3 -acodec copy /storage/emulated/0/com.wanhe.eng100.listening/UploadFile/Book/4b517786-04b4-47ec-8fb9-0eea869002f1/common/1519366317706-debris.mp3
02-23 14:11:57.761 13189-13810/com.xy.openndk.audiojointdemo I/System.out: ffmpeg -i concat:/storage/emulated/0/com.wanhe.eng100.listening/UploadFile/Book/4b517786-04b4-47ec-8fb9-0eea869002f1/common/5s.mp3|/storage/emulated/0/com.wanhe.eng100.listening/UploadFile/Book/4b517786-04b4-47ec-8fb9-0eea869002f1/common/Section_One_End.mp3 -acodec copy /storage/emulated/0/com.wanhe.eng100.listening/UploadFile/Book/4b517786-04b4-47ec-8fb9-0eea869002f1/common/1519366317761-debris.mp3
02-23 14:11:57.781 13189-13810/com.xy.openndk.audiojointdemo I/System.out: ffmpeg -i concat:/storage/emulated/0/com.wanhe.eng100.listening/UploadFile/Book/4b517786-04b4-47ec-8fb9-0eea869002f1/common/5s.mp3|/storage/emulated/0/com.wanhe.eng100.listening/UploadFile/Book/4b517786-04b4-47ec-8fb9-0eea869002f1/common/Section_Two_Begin.mp3 -acodec copy /storage/emulated/0/com.wanhe.eng100.listening/UploadFile/Book/4b517786-04b4-47ec-8fb9-0eea869002f1/common/1519366317781-debris.mp3
02-23 14:11:57.841 13189-13810/com.xy.openndk.audiojointdemo I/System.out: ffmpeg -i concat:/storage/emulated/0/com.wanhe.eng100.listening/UploadFile/Book/4b517786-04b4-47ec-8fb9-0eea869002f1/common/5s.mp3|/storage/emulated/0/com.wanhe.eng100.listening/UploadFile/Book/4b517786-04b4-47ec-8fb9-0eea869002f1/common/Section_Two_End.mp3 -acodec copy /storage/emulated/0/com.wanhe.eng100.listening/UploadFile/Book/4b517786-04b4-47ec-8fb9-0eea869002f1/common/1519366317841-debris.mp3
02-23 14:11:57.866 13189-13810/com.xy.openndk.audiojointdemo I/System.out: ffmpeg -i concat:/storage/emulated/0/com.wanhe.eng100.listening/UploadFile/Book/4b517786-04b4-47ec-8fb9-0eea869002f1/common/5s.mp3|/storage/emulated/0/com.wanhe.eng100.listening/UploadFile/Book/4b517786-04b4-47ec-8fb9-0eea869002f1/common/Topic_6_7.mp3 -acodec copy /storage/emulated/0/com.wanhe.eng100.listening/UploadFile/Book/4b517786-04b4-47ec-8fb9-0eea869002f1/common/1519366317866-debris.mp3
02-23 14:11:57.897 13189-13810/com.xy.openndk.audiojointdemo I/System.out: ffmpeg -i concat:/storage/emulated/0/com.wanhe.eng100.listening/UploadFile/Book/4b517786-04b4-47ec-8fb9-0eea869002f1/common/5s.mp3|/storage/emulated/0/com.wanhe.eng100.listening/UploadFile/Book/4b517786-04b4-47ec-8fb9-0eea869002f1/common/Topic_8_9.mp3 -acodec copy /storage/emulated/0/com.wanhe.eng100.listening/UploadFile/Book/4b517786-04b4-47ec-8fb9-0eea869002f1/common/1519366317896-debris.mp3
02-23 14:11:57.928 13189-13810/com.xy.openndk.audiojointdemo I/System.out: ffmpeg -i concat:/storage/emulated/0/com.wanhe.eng100.listening/UploadFile/Book/4b517786-04b4-47ec-8fb9-0eea869002f1/common/5s.mp3|/storage/emulated/0/com.wanhe.eng100.listening/UploadFile/Book/4b517786-04b4-47ec-8fb9-0eea869002f1/common/Topic_10_13.mp3 -acodec copy /storage/emulated/0/com.wanhe.eng100.listening/UploadFile/Book/4b517786-04b4-47ec-8fb9-0eea869002f1/common/1519366317928-debris.mp3
02-23 14:11:57.931 13189-13810/com.xy.openndk.audiojointdemo A/libc: Fatal signal 11 (SIGSEGV), code 1, fault addr 0x18 in tid 13810 (RxNewThreadSche)

                                                                     [ 02-23 14:11:57.934   444:  444 W/         ]
                                                                     debuggerd: handling request: pid=13189 uid=10353 gid=10353 tid=13810
  • 写回答

2条回答 默认 最新

  • maogedadada 2018-02-27 02:40
    关注

    用我的这个可以
    public static String[] mergeAudio(List voices, String outputUrl) {
    ArrayList _commands = new ArrayList<>();
    _commands.add("ffmpeg");
    _commands.add("-i");
    String pathCmd="";
    for (int i = 0; i < voices.size(); i++) {
    if (i==0){
    pathCmd=voices.get(i);
    }else {
    pathCmd=pathCmd+"|"+voices.get(i);
    }
    }
    _commands.add("concat:"+pathCmd);
    _commands.add("-acodec");
    _commands.add("copy");
    _commands.add(outputUrl);
    String[] commands = new String[_commands.size()];
    for (int i = 0; i < _commands.size(); i++) {
    commands[i] = _commands.get(i);
    }
    return commands;
    }
    我的ffmpeg demo链接

    评论

报告相同问题?

悬赏问题

  • ¥20 matlab yalmip kkt 双层优化问题
  • ¥15 如何在3D高斯飞溅的渲染的场景中获得一个可控的旋转物体
  • ¥88 实在没有想法,需要个思路
  • ¥15 MATLAB报错输入参数太多
  • ¥15 python中合并修改日期相同的CSV文件并按照修改日期的名字命名文件
  • ¥15 有赏,i卡绘世画不出
  • ¥15 如何用stata画出文献中常见的安慰剂检验图
  • ¥15 c语言链表结构体数据插入
  • ¥40 使用MATLAB解答线性代数问题
  • ¥15 COCOS的问题COCOS的问题