Page 1 of 1

transcode-h264-v2.py thru System Events

Posted: Thu Aug 09, 2018 10:12 pm
by cythraul
Hi everyone,

I wanted to share about my experience trying to use this script thru events instead of a user job. I already use mythlink.pl thru the record started and recordings deleted/expired events so I can get access to my recordings thru Plex.

The script: https://www.mythtv.org/wiki/Transcode_Mpeg2_to_H264 (v2.)

1- Figured out how to add a finished recording event

Found the event names here:

https://code.mythtv.org/doxygen/mythsys ... ource.html

2- Added to the settings table using "mysql -u root mythconverg". It should be done thru mythtv-setup but I just hate starting an X session for that tool. So bloody painful.

Previously, I copied the script under /usr/local/bin/ and made it executable with chmod a+x

INSERT INTO mythconverg.settings (value,data,hostname) values ('EventCmdRecFinished','/usr/local/bin/transcode-h264-v2.py --chanid "%CHANID%" --starttime "%STARTTIMEUTC%" --tzoffset "-05" --verbose all >> /var/log/mythtv/transcode-h264-v2.log','[backend hostname]')

The tzoffset depends on your location. I don't quite understand why it's needed at all but the script requires it for the moment.

Verbosity is optional, so is the redirection to the log file.

3- Commented out line 195-197 so it can run without having a jobid:

Code: Select all

#                        job.update({'status':job.PAUSED, 
#                                    'comment':'Waited %d secs for the commercial flagging job' % (waititer*POLL_INTERVAL) \
#                                     + ' currently running on this recording to complete.'})
There's probably a better way but I'm not knowledgeable enough about Python. :( Besides, I'm not a fan about indentation errors.

Also, I commented out the break at line 204. If I understand correctly, that's to get out of a while loop when the condition is still true. We don't want that here.. I think.

Anyway, I hope that helps or, at least, does not confuse anyone.

Cheers!
cythraul

Re: transcode-h264-v2.py thru System Events

Posted: Mon Aug 13, 2018 2:03 pm
by cythraul
Hi everyone,

I have a small problem with the script. I noticed it always ended with result code 1. It turns out that it has problem committing the recording markups...
Traceback (most recent call last):
File "/myth/transcode-h264-v2.py", line 683, in <module>
main()
File "/myth/transcode-h264-v2.py", line 676, in main
runjob(chanid=opts.chanid, starttime=opts.starttime, tzoffset=opts.tzoffset)
File "/myth/transcode-h264-v2.py", line 560, in runjob
rec.markup.commit()
File "/usr/lib/python2.7/dist-packages/MythTV/database.py", line 625, in commit
','.join(['?' for a in fields])), data)
File "/usr/lib/python2.7/dist-packages/MythTV/_conn_mysqldb.py", line 99, in executemany
raise MythDBError(MythDBError.DB_RAW, e.args)
MythTV.exceptions.MythDBError: MySQL error 1062: Duplicate entry '1171-2018-01-15 21:00:00-33-0' for key 'PRIMARY'
Line 625 is the commit() line below:

Code: Select all

    # fix during in the recorded markup table this will be off if commercials are removed
    duration_msecs, e = get_duration(db, rec, transcoder, outfile)
    duration_msecs = 1000*duration_msecs
    for index,mark in reversed(list(enumerate(rec.markup))):
        # find the duration markup entry and correct any error in the video duration that might be there
        if mark.type == 33:
            if debug:
                print 'Markup Duration in milliseconds "%s"' % mark.data
            error = mark.data - duration_msecs
            if error != 0:
                if debug:
                    print 'Markup Duration error is "%s"msecs' % error
                mark.data = duration_msecs
                #rec.bookmark = 0
                #rec.cutlist = 0
                rec.markup.commit()
I'm not sure how to troubleshoot this. As I said earlier, I'm not good with Python. :(