title: How to kill FFmpeg currently running process?
body: <p>I'm working on an application that trims a video using FFmpeg. While the trimming process has started and I cancel it, the FFmpeg is terminated fully. How can I achieve by killing the current working process only?</p>
  
  <pre><code>   /* define PID */
    try {
       String pid = ffmpeg.toString();
       pid = pid.substring(pid.indexOf("[") + 1, pid.indexOf("]"));
       Process process = Runtime.getRuntime().exec("kill -2 " + pid);
  
       process.waitFor();
       ffmpeg.wait();
    } catch (IOException | InterruptedException e) {
       Log.e(TAG, "kill_ffmpeg: exception failed ",e );
       e.printStackTrace();
    }
  </code></pre>
  
  <p>This is the code I've been using now. when this code awake the activity restarts with an exception of the index out of bound.</p>
  
  <p>This is the library I've been using for achieving a video editing feature using FFmpeg <a href="https://github.com/WritingMinds/ffmpeg-android-java" rel="nofollow noreferrer">Here</a></p>
  
  <p>There is a method in this FFmpeg library called <code>killRunningProcess()</code>. When I use this method, shows an error called <code>cannot resolve method killRunningProcess()</code></p>
  
  <p>How can I achieve Killing a process without memory leaks and without crashing the app when the particular code has been invoked?</p>