其他分享
首页 > 其他分享> > ffmepg入门学习七 ffmepg把多个视频合成一个视频

ffmepg入门学习七 ffmepg把多个视频合成一个视频

作者:互联网

1.准备

  

ffmpeg

链接:https://pan.baidu.com/s/1oh_36qFxnLW5Kmdf8F5eTQ 
提取码:rsdn 
复制这段内容后打开百度网盘手机App,操作更方便哦

 

准备3个视频

test.txt

  1. file '20190516150254.mp4'
  2. file '20190516151754.mp4'
  3. file '20190516153254.mp4'

2.代码 

  1. package com.qihui.qxj.services.system;
  2. import java.io.IOException;
  3. import java.io.InputStream;
  4. import java.util.ArrayList;
  5. import java.util.List;
  6. import org.junit.Test;
  7. public class Test1 {
  8. /**
  9. * 把多个视频合成一个视频
  10. */
  11. @Test
  12. public void test4(){
  13. try {
  14. List commend = new ArrayList();
  15. commend.add("c:/bin/ffmpeg.exe");
  16. commend.add("-loglevel");
  17. commend.add("8");
  18. commend.add("-y");
  19. commend.add("-f");
  20. commend.add("concat");
  21. commend.add("-safe");
  22. commend.add("0");
  23. commend.add("-i");
  24. commend.add("D:/project/direct/40/test.txt");
  25. commend.add("-c");
  26. commend.add("copy");
  27. commend.add("-y");
  28. commend.add("d:/out.mp4");
  29. start(commend);
  30. } catch (Exception e) {
  31. e.printStackTrace();
  32. }
  33. }
  34. private void start(List commend) {
  35. Process p = null;
  36. try {
  37. ProcessBuilder builder = new ProcessBuilder(commend);
  38. builder.command(commend);
  39. p = builder.start();
  40. p.getOutputStream().close();
  41. doWaitFor(p);
  42. p.destroy();
  43. } catch (Exception e) {
  44. PrintCatchErrorMsg.Print(e, "Part", "getRSTPPicture.catch", "Exception");
  45. p.destroy();
  46. }
  47. }
  48. public static int doWaitFor(Process p) {
  49. InputStream in = null;
  50. InputStream err = null;
  51. int exitValue = -1;
  52. try {
  53. in = p.getInputStream();
  54. err = p.getErrorStream();
  55. boolean finished = false;
  56. while(!finished) {
  57. try {
  58. Character c;
  59. while(in.available() > 0) {
  60. c = new Character((char)in.read());
  61. System.out.print(c);
  62. }
  63. while(err.available() > 0) {
  64. c = new Character((char)err.read());
  65. System.out.print(c);
  66. }
  67. exitValue = p.exitValue();
  68. finished = true;
  69. } catch (IllegalThreadStateException var19) {
  70. Thread.currentThread();
  71. Thread.sleep(500L);
  72. }
  73. }
  74. } catch (Exception var20) {
  75. } finally {
  76. try {
  77. if (in != null) {
  78. in.close();
  79. }
  80. } catch (IOException var18) {
  81. }
  82. if (err != null) {
  83. try {
  84. err.close();
  85. } catch (IOException var17) {
  86. }
  87. }
  88. }
  89. return exitValue;
  90. }
  91. }

c:/bin/ffmpeg.exe 是ffmepg的安装地址

3、注意事项


输入文件必须是有序的,写入文件text.txt中
输入文件格式最好相同,分辨率大小最好相同

转载自:https://blog.csdn.net/qq_16855077/article/details/90265073

luoyong_blog 发布了42 篇原创文章 · 获赞 115 · 访问量 1万+ 私信 关注

标签:视频,入门,err,try,commend,add,ffmepg,catch,import
来源: https://blog.csdn.net/luoyong_blog/article/details/104497633