Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FFmpegJob running. how to do force stop job? #298

Open
13330863440 opened this issue Dec 13, 2023 · 2 comments
Open

FFmpegJob running. how to do force stop job? #298

13330863440 opened this issue Dec 13, 2023 · 2 comments
Labels

Comments

@13330863440
Copy link

public  static Set<String> closeIdSet = new HashSet<>();
executor.execute(() -> {
    // thread
     Thread currentThread = Thread.currentThread();
    String currentJobId="xxxx";
   ScheduledExecutorService sche= new ScheduledThreadPoolExecutor(1);
                    sche.scheduleAtFixedRate(() -> {
                       if(closeIdSet.contains(currentJobId)){
                          //force stop thread and stop job  !!  . how to do force stop job?
                           currentThread.stop();
                       }
                    }, 0, 1, TimeUnit.SECONDS);
    
    
    FFmpegJob job = executor.createJob(builder)
    job.run();  // job running.  need force stop running
    
    next steps
    xxxx
    xxxx
    xxxx
});
//add closeIdSet  "xxxx" in  other thread 
@13330863440
Copy link
Author

just stop job.run().
like as

Process p = runFunc.run(path(args));
assert (p != null);
p.destroyForcibly()

Can this be done without modifying the source code

@luoyh
Copy link

luoyh commented Nov 22, 2024

@13330863440
you can implements net.bramp.ffmpeg.RunProcessFunction, the #run() return java.lang.Process.
like :

static class OwnProcessFunction extends RunProcessFunction {
        
        private Process p;

        @Override
        public Process run(List<String> args) throws IOException {
            p = super.run(args);
            // set process
            return p;
        }
        // destroy process.
        private void close() {
                ProcessHandle h = p.toHandle();
                h.destroy();
                h.descendants().forEach(ProcessHandle::destroy);
        }
    }

  public static void main(String[] args) {
        String ffmpegPath = Loader.load(org.bytedeco.ffmpeg.ffmpeg.class);
        // use my processfunction.
        OwnProcessFunction proc = new OwnProcessFunction();
        FFmpeg ffmpeg = new FFmpeg(ffmpegPath, proc);
        // todo
        // in other thread, can call proc.close(); destroy process;
  }
``

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants