Tuesday, 15 July 2014

java - Kill a process started by exec() after some duration and store frames in an array -



java - Kill a process started by exec() after some duration and store frames in an array -

let me start off saying i'm new java. i'm php background, happens 1 of php tasks need converted java.

the task splitting video frames using ffmpeg , working frames. i've completed process in php. , can convert java.

i went on tutorials , have got bases covered (using ide, running java programme etc). i'm using eclipse purpose.

i've far managed start ffmpeg withing java programme using

public static void main(string[] args) throws ioexception { string livestream = "d:/video.mpg"; string folderpth = "d:/frames"; string cmd="d:/ffmpeg/bin/ffmpeg.exe -i "+ livestream +" -r 10 "+folderpth+"/image%d.jpg"; //system.out.println(cmd); runtime r = runtime.getruntime(); process p = r.exec(cmd); // starts creating frames // , stores them on local disk // way store frame name in array? // string[] frames = {"image%d.jpg"} // frames array contains image1.jpg, image2.jpg..and on? }

this working fine, i'm getting frames in folder. want kill process after some, 5 minutes, video on 2 hours long , don't want have go taskbar , kill process manually. know if there way store frame names created ffmpeg array future use.

i tried using p.destroy() didn't stop process @ all. how go using similar settimeout() used in jquery?

some metadata

os : windows 7

ide : eclipse

p.destroy() sends kill pid on linux. means process receives signal not terminates. have execute kill -9 pid sure process indeed terminated. unfortunately standard java api not provide such functionality, have yourself.

but not complicated. there 2 commands: kill unix , killtask windows. both take process id. can find reflection: private int filed pid presents in platform specific subclass of process instance of runtime.exec()

edit

on linux runtime.exec() returns instance of unixprocess extends process. not have windows available , cannot check far remember on windows returns instance of windowsprocess or that. both have private int field pid can extracted using reflection:

process proc = rutime.getruntime().exec("my command"); field f = proc.getclass().getdeclaredfield("pid"); f.setaccessible(true); int pid = (integer)f.get(proc);

java ffmpeg exec

No comments:

Post a Comment