Android – 连接两个视频

前端之家收集整理的这篇文章主要介绍了Android – 连接两个视频前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在尝试在 Android上连接两个视频.我已经在使用ffmpeg来满足其他需求,但我使用的是 halfninja’s one,只有0.9. 0.9版本不允许以下方式执行此操作:
  1. // filter_complex isn't recognized
  2. vk.run(new String[] {
  3. "ffmpeg","-i",inputFile1,inputFile2,"-filter_complex","'[0:1] [0:0] [1:1] [1:0] concat=n=2:v=1:a=1 [v] [a]'","-map","'[v]'","'[a]'",outputFile
  4. });
  5.  
  6. // Or,after converting the two videos to ts,trying to merge them: concat:file1.ts|file2.ts: No such file or directory
  7. vk.run(new String[] {
  8. "ffmpeg","'concat:" + ts1 + "|" + ts2 + "'","-vcodec","copy","-acodec","-absf","aac_adtstoasc",output
  9. });

我尝试的第三件事是使用here解释的concat demuxer,ffmpeg 0.9也无法识别.

有没有办法在Android上用ffmpeg 0.9(或其他库)连接两个视频?

解决方法

嗯,找到的唯一解决方案是使用ffmpeg≥1.1.我编译了2.1,它工作得很好.这是我现在使用的:
  1. /**
  2. * Concatenates two videos
  3. * @param inputFile1 First video file path
  4. * @param inputFile2 Second video file path
  5. * @param outputFile Output file path
  6. */
  7. public static void concatenate(String inputFile1,String inputFile2,String outputFile) {
  8. Log.d(TAG,"Concatenating " + inputFile1 + " and " + inputFile2 + " to " + outputFile);
  9. String list = generateList(new String[] {inputFile1,inputFile2});
  10. Videokit vk = Videokit.getInstance();
  11. vk.run(new String[] {
  12. "ffmpeg","-f","concat",list,"-c",outputFile
  13. });
  14. }
  15.  
  16. /**
  17. * Generate an ffmpeg file list
  18. * @param inputs Input files for ffmpeg
  19. * @return File path
  20. */
  21. private static String generateList(String[] inputs) {
  22. File list;
  23. Writer writer = null;
  24. try {
  25. list = File.createTempFile("ffmpeg-list",".txt");
  26. writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(list)));
  27. for (String input: inputs) {
  28. writer.write("file '" + input + "'\n");
  29. Log.d(TAG,"Writing to list file: file '" + input + "'");
  30. }
  31. } catch (IOException e) {
  32. e.printStackTrace();
  33. return "/";
  34. } finally {
  35. try {
  36. if (writer != null)
  37. writer.close();
  38. } catch (IOException ex) {
  39. ex.printStackTrace();
  40. }
  41. }
  42.  
  43. Log.d(TAG,"Wrote list file to " + list.getAbsolutePath());
  44. return list.getAbsolutePath();
  45. }

猜你在找的Android相关文章