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

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个回答

用我的这个可以
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链接

maogedadada
maogedadada 回复航行在蓝天的蚂蚱: 我的几十个音频也成了啊,你检查看看是不是音频文件有问题
接近 2 年之前 回复
xy1213236113
航行在蓝天的蚂蚱 代码都没有问题,和我的代码是一样的,可以拼接,只是一次性拼接几十个音频就会报错的,你可以试试,我通过分析backtrace,发现应该是C代码中出现了野指针
接近 2 年之前 回复
maogedadada
maogedadada 如果可以解决你的问题,顺便给个star,蟹蟹
接近 2 年之前 回复

看来这类问题还是蛮多的,这是信道出问题了,和代码关系不大,不过可以通过内存优化解决

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问