Andrew Simpson
Andrew Simpson

Reputation: 7324

Running ffmpeg through a website

I have a website and it allows Users to download images as a video clip.

They can choose from say mp4, avi, ogg etc.

I use ffmpeg via the Process Class in C#/Asp.net 4.0 to execute the conversion tool.

I have noticed in testing that if I forcefully abort this conversion like stopping IIS, ending the wp3 process in task manager) that after a while of doing this if I then look at task manager on the Web Server there are many instances of FFMPEG which have not closed down properly.

What I would ideally like to do is kill any processes that maybe lingering for that SPECIFIC User (not any other Users/Session) and then start the conversion tool.

Is it possible to manage/control the FFMPEG process for that User/Session or should I be looking at a queuing system that enables only 1 User at 1 time should be able to use this conversion tool?

I hope I made this sound clear?

I could post the code that shows how the Process/ffmpeg is started in C# but I cannot see how this would aid this question.

Thanks

Upvotes: 0

Views: 555

Answers (1)

online Thomas
online Thomas

Reputation: 9381

Hope this helps:

private void killProcess(String processName, String processOwner)
    {
    foreach (var process in Process.GetProcessesByName(processName))
    {
    if(GetProcessOwner(processName).equals(processOwner))
    {
        process.Kill();
    }
    }
    }
    public string GetProcessOwner(string processName)
    {
        string query = "Select * from Win32_Process Where Name = \"" + processName + "\"";
        ManagementObjectSearcher searcher = new ManagementObjectSearcher(query);
        ManagementObjectCollection processList = searcher.Get();

        foreach (ManagementObject obj in processList)
        {
            string[] argList = new string[] { string.Empty, string.Empty };
            int returnVal = Convert.ToInt32(obj.InvokeMethod("GetOwner", argList));
            if (returnVal == 0)
            {
                // return DOMAIN\user
                string owner = argList[1] + "\\" + argList[0];
                return owner;       
            }
        }

        return "NO OWNER";
    }

Upvotes: 1

Related Questions