Advertisement
Guest User

Untitled

a guest
Sep 6th, 2014
3,749
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. final ArrayList<SilenceInfo> silence = new ArrayList<SilenceInfo>();
  2.  
  3. ProcessBuilder n = new ProcessBuilder();
  4.  
  5. // just run silence detect to null
  6. List<String> meta = new ArrayList<String>();
  7. meta.add("ffmpeg");
  8. meta.add("-i");
  9. meta.add("PATH/TO/MP3");
  10. meta.add("-af");
  11. meta.add("silencedetect=n=-50dB:d=1");
  12. meta.add("-f");
  13. meta.add("null");
  14. meta.add("-");
  15. n.command(meta);
  16.  
  17. // TODO: run it, parse the lines and add the SilenceInfos to silence!
  18.  
  19. // we got the silence now!     
  20. double firstSilenceEnd = 0, lastSilenceStart = 0;
  21.  
  22. boolean cutStart = false, cutEnd = false;
  23.  
  24. // no silence at all
  25. if(silence.size() == 0) {
  26.     // skip
  27. } else if(silence.size() == 1) {
  28.     // has to be at the end because no end was given
  29.     lastSilenceStart = silence.get(0).getTimeStart();
  30.     cutEnd = true;
  31. } else {
  32.     // silence at all ends
  33.     for(SilenceInfo s : silence) {
  34.         if(firstSilenceEnd == 0 && s.getTimeEnd() != -1)
  35.             firstSilenceEnd = s.getTimeEnd();
  36.        
  37.         if(s.getTimeStart() != -1)
  38.             lastSilenceStart = s.getTimeStart();
  39.     }
  40.     cutStart = true;
  41.     cutEnd = true;
  42. }
  43.  
  44. n = new ProcessBuilder();
  45.  
  46. meta = new ArrayList<String>();
  47. meta.add("ffmpeg");
  48. meta.add("-i");
  49. meta.add("PATH/TO/MP3);
  50. if(cutStart) {
  51.     meta.add("-ss");
  52.     meta.add(firstSilenceEnd + "");
  53. }
  54. if(cutEnd) {
  55.     meta.add("-t");
  56.     meta.add((lastSilenceStart - firstSilenceEnd) + "");
  57. }
  58. meta.add("-y");
  59. meta.add("-ab");
  60. meta.add("AUDIO BIRATE EG 192k");
  61. meta.add("PATH/TO/TARGET");
  62. n.command(meta);
  63.  
  64. // TODO: run it
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement