Recently developing a program that uses FFmpeg to complete the video recording of the camera, which mentions the need to start and end the recording separately when triggering the start and end signs, and just start planning to use the FFmpeg directly to complete the function, but when the development process found that can not fully implement the function, Because FFmpeg can record a specified length of video, but this project in the beginning of the recording is not known the length of the specified, so think only in the process of starting ffmpeg to make a fuss.
Sure enough, the way to end the process can actually complete the function, the specific idea is as follows, in the receiving end of the flag, the process is killed directly, do not use the dispose,close, etc., will be error, direct a kill can reach your request, Originally thought has completed the function, but the careful test found that ffmpeg recorded video length of only 10 seconds or so length, will not record longer length, this look caught in the pit, found an interesting phenomenon, once the main program is closed, Ffmpeg.exe will continue to execute, it is obvious: The process of recording the video was blocked by the parent process , but it was not known what the cause of the blockage was, and two processes did not have shared resources.
This problem bothered me one night, the next day to continue debugging will still have a corresponding problem, found on the Internet related Java blocking posts, but all with I/O interaction, there is a mention need to set up the process (object). Redirectstandardinput, with the Redirectstandarderror property of true, reflects the need to set these two properties to interact with the command line, but ffmpeg this process does not need to interact with the command line should not need to set these two properties, Comment out the two attributes, test, solve the problem.
Problems raised by C # multi-process