[mythtv-users] Tweaking the Transcode Wrapper Stub

Joseph Fry joe at thefrys.com
Fri May 2 13:22:03 UTC 2014


Thanks Raymond, and I apologize for not being more clear.  Yes, I want
to read the output while the command is in progress.so that I can
update the job's progress information (as you see when you look at an
in progress mythtranscode job).

>From what you said above, it looks like I need to adjust this block
somehow to tell it to use the ._runasync() method instead of
._runcmd() method... but the code doesn't explicitly call either
method so what do I change?:

  task = System(path=transcoder, db=db)
      try:
          output = task(<my avconv arguments>)

Also, I had looked at the Process.poll method, however I cannot figure
out how to use it.  Is it as simple as doing something like this in my
try: block?

while True:
    output.poll()
    line = output.stdout.readline()
    eline = output.stderr.readline()
    if line:
        <parse and update db>
    if eline:
        <parse and update db>
    if (line == "" and eline == "" and process.returncode != None):
        break

Is there a script that you are aware of that uses this that I could look at?

On Fri, May 2, 2014 at 7:43 AM, Raymond Wagner <raymond at wagnerrp.com> wrote:
> 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
> _______________________________________________
> mythtv-users mailing list
> mythtv-users at mythtv.org
> http://www.mythtv.org/mailman/listinfo/mythtv-users
> http://wiki.mythtv.org/Mailing_List_etiquette
> MythTV Forums: https://forum.mythtv.org


More information about the mythtv-users mailing list