Multiprocessing | Multithreading ffmpeg in python
<p>I am developing a <a href="https://github.com/lordcantide/Alien-FFMPEG-Transcoder-Framework-for-HDHomeRun-PRIME" rel="nofollow">python WSGI script</a> to interface with an HDHomeRun Prime. In a perfect world it will pass URI values as commands to FFMPEG and display the resulting stream in a browser. I have the "show stuff in browser" and the "pass instructions to FFMPEG" parts working fine, but I do not have them working simultaneously.</p>

<p>1) Given that this middleware is being used to transcode MPEG-2 to h.264, does it make more sense to use multiprocessing or multithread to start and stop the respective processes?</p>

<p>2) If the WSGI script is brokering the initiation of FFMPEG feeds (if the input feed isn't already brokered) and connecting clients to the associated FFServer streams, does mean I'll need to use some sort of pool to keep track of the middleware's activities?</p>

<p>I don't really understand your whole process, but IMO you should start with <code>multithreading</code>, as it is much easier to setup (variables are shared like usual in Python). IF that doesn't meet your requirement (e.g not fast enough), you can move to <code>multiprocessing</code> but it will increase the complexity if you never used <code>multiprocessing</code> in Python (no communication between <code>process</code>, need to use <code>queues</code> or shared variables).</p>

<p>Setup your threads :</p>

<pre><code>import threading 
a = threading.Thread(target = func, args=(vars)) 
a.start() 
</code></pre>

<p>A nice tutorial <a href="https://pymotw.com/2/threading/" rel="nofollow">here.</a></p>

<p>You should also know about python's <a href="https://en.wikipedia.org/wiki/Global_interpreter_lock" rel="nofollow">GIL</a> to understand what you are doing in Threading/multiprocessing .</p>

python ffmpeg wsgi python-multithreading python-multiprocessing