Question

I'm given the task to transcode a bunch of GoToMeeting Video files each evening. Once the video has been transcoded, it will be uploaded to a website. However, before I jump too far into the project, I wanted to figure out if this is even possible.

My current sample script is a simple batch file where I can drag and drop several files onto the batch file. It will transcode the first file, display an output and then continue to the second file to transcode. This is the expected behavior that I'm looking for.

@echo off
C:\g2mtranscoder.exe source=%~1
echo %~1 has completed.
C:\g2mtranscoder.exe source=%~2
echo %~2 has completed.
C:\g2mtranscoder.exe source=%~3
echo %~3 has completed.
C:\g2mtranscoder.exe source=%~4
echo %~4 has completed.
pause

My question is that if in C# (will be a Windows Service ultimately), would it be as simple as calling the external program g2mtranscoder.exe to do the transcoding and then put my upload script right afterwards? Obviously, I would not want to upload a video that is currently being transcoded nor would I want the video to be upload without having been transcoded first.

My subquestion is would putting this in a loop (for each file in a directory) cause any issues if the contents of the directory is only ever the pending videos to be transcoded? If in the loop, would it try to loop through and start the transcoding of all files within the directory asynchronously or would it be more synchronous? I would like to avoid the loop happening asynchronously as it could overload the machine causing artifacts or synchronization issues with the audio/video timing. Most importantly, a video in the middle of transcoding or an untranscoded video cannot be uploaded.

Any coding suggestions for this would be great, but I'm really looking for more of a understanding of how C# works with code execution with having a external program called in the middle of the executed C# code.

I'm more of a Ruby/Rails and Linux person and do not have much experience on C#. I know enough to be dangerous, but just want to make sure that what I'm looking to do is feasible.

Était-ce utile?

La solution

I figured it out. I can create a process and then use the HasExited flag to wait for the process to finish. Once finished I can continue to upload the program. A successful exit will have a HasExited value of 0 whereas a failed exit will be 1 or -1.

StartInfo.Arguments will allow me to pass in source=<location of GTM video> to process the video file.

Console.WriteLine("Running");
Process pr = new Process();
pr.StartInfo.FileName = "Notepad.exe";
pr.StartInfo.Arguments = "test.dat";
pr.Start();
while (pr.HasExited == false)
    if ((DateTime.Now.Second % 5) == 0)
    { // Show a tick every five seconds.
        Console.Write(".");
        System.Threading.Thread.Sleep(1000);
    }
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top