[mythtv-users] Tweaking the Transcode Wrapper Stub

Raymond Wagner raymond at wagnerrp.com
Fri May 2 11:43:38 UTC 2014


On 5/1/2014 9:56 PM, Joseph Fry wrote:
> I am developing a script using Raymond Wagner's Transcode wrapper stub
> (http://www.mythtv.org/wiki/Transcode_wrapper_stub) to call avconv to
> transcode to x264.
>
> My script works great, but now I want to expand upon it.
>
> The first thing I want to do is parse the output of the avconv command
> and extract the progress and speed (fps).
>
> At first I thought it would be simple, but upon closer inspection I
> see that it uses the Mythtv Python binding's "System" class to run
> avconv... and I can't find any documentation of how I can poll the
> output of my command.
>
> Can anyone provide some guidance, or better yet a code snippet, that
> demonstrates how I can execute a command, and poll it's output while
> it runs?

The transcode wrapper stub defines an application, and then runs that 
application with arguments using the .command() method, which in turn 
runs ._runcmd().  When ._runcmd() runs, it spawns the process, and then 
waits for it to complete.  If all you want to do is read the output at 
the end, this is the output of the .command() method.  If you want to 
read the output as it is running, you will need to use the ._runasync() 
method instead.  It accepts the same arguments as .command(), but 
returns a Process object.

The Process object will define a .poll() method, and .stdout and .stderr 
objects.  .poll() will return the exit code, or -1 if it is still 
running.  .stdout and .stderr are special DequeBuffer objects, which 
manage a fifo buffer containing the output of the application.  Its 
.read() method is non-blocking, and you can use len() to see how much 
data it currently contains.  This buffer object has its own internal 
thread which continuously pulls data from the application to prevent the 
OS-supplied 64KB pipe from filling and blocking the application.

https://code.mythtv.org/cgit/mythtv/tree/mythtv/bindings/python/MythTV/system.py
https://code.mythtv.org/cgit/mythtv/tree/mythtv/bindings/python/MythTV/utility/dequebuffer.py


More information about the mythtv-users mailing list