0

I have a simple task which I want to achieve.

I am trying to encode multiple files using ffmpeg on command line using C#.

This is what I want to achieve.

Assume there are 'x' number of files in a list. And I want to run 'y' number of encoding processes simultaneously. After all files are encoded I am merging all x files. Encoding and merging part is done. Where I am stuck is the simultaneous working. I am familiar with backgroundworker, threadpooling, ParallelFor but all of these aren't giving me the result that I want. May be my approach is wrong. So I would appreciate if someone could help me how should I go about it and solve this problem using 1 technique or a combination of few.

P.S. While the files are encoding, I want to be able to update a progress bar on screen (Simple Form). Obviously I would want the process to be as fast as possible.

amyn
  • 922
  • 11
  • 24
  • You want to spawn multiple threads to encode multiple files, once all files finished you want to merge the new files together? – Tsukasa Jul 17 '14 at 11:59
  • 1
    `all of these are giving me the result that I want`. What result do you want and what are you getting now? And can you post the code for what you've tried? – Philip Pittle Jul 17 '14 at 12:03
  • @Tsukasa yes that is exactly what I want. – amyn Jul 18 '14 at 05:27

1 Answers1

1

Use the Parallel.ForEach with ParallelOptions as argument. That object has a property MaxDegreeOfParallelism specifying the maximum number of concurrent tasks.

In the callback method You may increase a progress value that may be shown in GUI.

erikH
  • 2,286
  • 1
  • 17
  • 19
  • 2
    And make sure that you're increasing that progress value in a thread-safe manner. – svick Jul 17 '14 at 12:44
  • @erikH the problem is that Parallel.ForEach stops the main UI thread because of which I am not able to update my progress bar. – amyn Jul 18 '14 at 05:28
  • Then look at [this question](http://stackoverflow.com/q/8365346/386544) – erikH Jul 18 '14 at 06:45