mythpreviewgen fails on MKV files with H264 video

Have a MythTV related problem? Ask for help from other MythTV users here.

Moderator: Forum Moderators

Post Reply
goldpizza44
Newcomer
Posts: 5
Joined: Sat Jan 04, 2020 11:07 pm
United States of America

mythpreviewgen fails on MKV files with H264 video

Post by goldpizza44 » Sun Jan 05, 2020 12:22 am

Looking for experts on mythpreviewgen.

I record programs over the air with an HDHR3 box and the videos land in my recordings directory as MPEG2 with suffix .ts which are large. I wrote a custom transcoder using HandBrakeCLI to convert them from 1080p MPEG2 to 720p H264 which reduces filesize to below 25% of the original.

However I discovered continuous mythpreviewgen processes running which were trying and failing to generate the preview PNG files from these MKV files.

I attempted to manually run it with:

Code: Select all

mythpreviewgen --size 0x0 --chanid 10501 --starttime 20191011003000 --outfile ./preview.png  --verbose all
I see errors coming from avformatdecoder.cpp and when I grep just those messages I see:

Code: Select all

020-01-04 19:00:02.925028 I  avformatdecoder.cpp:473:AvFormatDecoder  AFD: PlayerFlags: 0x30100, AudioReadAhead: 100 msec
2020-01-04 19:00:02.925274 I  avformatdecoder.cpp:1010:InitByteContext  AFD: Buffer size: 32768 streamed 0 seekable 1
2020-01-04 19:00:02.944829 I  avformatdecoder.cpp:2175:ScanStreams  AFD: Stream #0, has id 0x0 codec id H264, type Video, bitrate 0 at 0x5740c0
2020-01-04 19:00:02.944837 I  avformatdecoder.cpp:2175:ScanStreams  AFD: Stream #1, has id 0x0 codec id AAC, type Audio, bitrate 0 at 0x5750c0
2020-01-04 19:00:02.944842 I  avformatdecoder.cpp:2219:ScanStreams  AFD: codec AAC has 2 channels
2020-01-04 19:00:02.944844 I  avformatdecoder.cpp:2278:ScanStreams  AFD: Looking for decoder for AAC
2020-01-04 19:00:02.945272 I  avformatdecoder.cpp:2767:OpenAVCodec  AFD: Opened codec 0x698f00, id(AAC) type(Audio)
2020-01-04 19:00:02.945309 I  avformatdecoder.cpp:2426:ScanStreams  AFD: Audio Track #1, of type (Normal) is A/V stream #1 (id=0x0) and has 2 channels in the Eng
lish language(6647399).
2020-01-04 19:00:02.945315 I  avformatdecoder.cpp:2175:ScanStreams  AFD: Stream #2, has id 0x0 codec id AC3, type Audio, bitrate 384000 at 0x593400
2020-01-04 19:00:02.945318 I  avformatdecoder.cpp:2219:ScanStreams  AFD: codec AC3 has 6 channels
2020-01-04 19:00:02.945320 I  avformatdecoder.cpp:2278:ScanStreams  AFD: Looking for decoder for AC3
2020-01-04 19:00:02.945660 I  avformatdecoder.cpp:2767:OpenAVCodec  AFD: Opened codec 0x5d1800, id(AC3) type(Audio)
2020-01-04 19:00:02.945671 I  avformatdecoder.cpp:2426:ScanStreams  AFD: Audio Track #2, of type (Normal) is A/V stream #2 (id=0x0) and has 6 channels in the Eng
lish language(6647399).
2020-01-04 19:00:02.945676 I  avformatdecoder.cpp:2175:ScanStreams  AFD: Stream #3, has id 0x0 codec id Unknown Codec ID, type Subtitle, bitrate 0 at 0x5942c0
2020-01-04 19:00:02.945682 I  avformatdecoder.cpp:2235:ScanStreams  AFD: subtitle codec (Subtitle)
2020-01-04 19:00:02.945684 I  avformatdecoder.cpp:2278:ScanStreams  AFD: Looking for decoder for Unknown Codec ID
2020-01-04 19:00:02.945712 I  avformatdecoder.cpp:2767:OpenAVCodec  AFD: Opened codec 0x5fb180, id(Unknown Codec ID) type(Subtitle)
2020-01-04 19:00:02.945717 I  avformatdecoder.cpp:2379:ScanStreams  AFD: Subtitle track #1 is A/V stream #3 and is in the English language(6647399).
2020-01-04 19:00:02.945719 I  avformatdecoder.cpp:2441:ScanStreams  AFD: Trying to select best video track
2020-01-04 19:00:02.945744 I  avformatdecoder.cpp:2474:ScanStreams  AFD: Selected track #0 (id 0x0 codec id H264, type Video, bitrate 500000 at 0x5740c0)
2020-01-04 19:00:02.948152 I  avformatdecoder.cpp:2655:ScanStreams  AFD: Using 1 CPUs for decoding
2020-01-04 19:00:02.948156 I  avformatdecoder.cpp:1616:InitVideoCodec  AFD: InitVideoCodec() 0x59ad40 id(H264) type (Video).
2020-01-04 19:00:02.948176 I  avformatdecoder.cpp:1458:normalized_fps  AFD: Selected FPS is 29.97 (avg 29.97 codec 0 container 1000 estimated 29.97)
2020-01-04 19:00:02.948212 I  avformatdecoder.cpp:2667:ScanStreams  AFD: Using ffmpeg for video decoding
2020-01-04 19:00:02.948447 I  avformatdecoder.cpp:2767:OpenAVCodec  AFD: Opened codec 0x59ad40, id(H264) type(Video)
2020-01-04 19:00:02.948485 I  avformatdecoder.cpp:4770:AutoSelectAudioTrack  AFD: Trying to select audio track (w/lang)
2020-01-04 19:00:02.949782 I  avformatdecoder.cpp:4909:AutoSelectAudioTrack  AFD: Selected track 2: English AC3 5.1ch (A/V Stream #2)
2020-01-04 19:00:02.949789 I  avformatdecoder.cpp:5663:SetupAudioStream  AFD: Audio data is planar
2020-01-04 19:00:02.949797 I  avformatdecoder.cpp:5712:SetupAudioStream  AFD: Initializing audio parms from audio track #2
2020-01-04 19:00:02.949808 I  avformatdecoder.cpp:5717:SetupAudioStream  AFD: Audio format changed 
2020-01-04 19:00:02.961410 I  avformatdecoder.cpp:350:myth_av_log  Input #0, matroska,webm, from '/mnt/videos/mythtv/10501_20191011003000.mkv':
2020-01-04 19:00:02.961419 I  avformatdecoder.cpp:350:myth_av_log  Metadata:
2020-01-04 19:00:02.961426 I  avformatdecoder.cpp:350:myth_av_log  creation_time   : 2019-10-11T01:02:03.000000Z
2020-01-04 19:00:02.961430 I  avformatdecoder.cpp:350:myth_av_log  ENCODER         : Lavf58.20.100
2020-01-04 19:00:02.961438 I  avformatdecoder.cpp:350:myth_av_log  Duration: 00:30:58.12, start: 0.426000, bitrate: 2195 kb/s
2020-01-04 19:00:02.961518 I  avformatdecoder.cpp:350:myth_av_log  Stream #0:0: Video: h264 (Main), yuv420p(tv, bt709, progressive), 1280x720 [SAR 1:1 DAR 16:9],
 500 kb/s, 29.97 fps, 29.97 tbr, 1k tbn, 180k tbc (default)
2020-01-04 19:00:02.961521 I  avformatdecoder.cpp:350:myth_av_log  Metadata:
2020-01-04 19:00:02.961525 I  avformatdecoder.cpp:350:myth_av_log  DURATION        : 00:30:58.115000000
2020-01-04 19:00:02.961552 I  avformatdecoder.cpp:350:myth_av_log  Stream #0:1(eng): Audio: aac (LC), 48000 Hz, stereo, fltp (default)
2020-01-04 19:00:02.961554 I  avformatdecoder.cpp:350:myth_av_log  Metadata:
2020-01-04 19:00:02.961557 I  avformatdecoder.cpp:350:myth_av_log  title           : Stereo
2020-01-04 19:00:02.961560 I  avformatdecoder.cpp:350:myth_av_log  DURATION        : 00:30:57.642000000
2020-01-04 19:00:02.961582 I  avformatdecoder.cpp:350:myth_av_log  Stream #0:2(eng): Audio: ac3, 48000 Hz, 5.1(side), fltp, 384 kb/s
2020-01-04 19:00:02.961584 I  avformatdecoder.cpp:350:myth_av_log  Metadata:
2020-01-04 19:00:02.961587 I  avformatdecoder.cpp:350:myth_av_log  title           : Surround
2020-01-04 19:00:02.961590 I  avformatdecoder.cpp:350:myth_av_log  DURATION        : 00:30:57.653000000
2020-01-04 19:00:02.961610 I  avformatdecoder.cpp:350:myth_av_log  Stream #0:3(eng): Subtitle: ass
2020-01-04 19:00:02.961612 I  avformatdecoder.cpp:350:myth_av_log  Metadata:
2020-01-04 19:00:02.961615 I  avformatdecoder.cpp:350:myth_av_log  DURATION        : 00:30:57.086000000
2020-01-04 19:00:02.961618 I  avformatdecoder.cpp:1360:OpenFile  AFD: Position map found
2020-01-04 19:00:02.961623 I  avformatdecoder.cpp:1363:OpenFile  AFD: Successfully opened decoder for file: "/mnt/videos/mythtv/10501_20191011003000.mkv". novide
o(0)
2020-01-04 19:00:03.003311 I  avformatdecoder.cpp:683:DoFastForward  AFD: DoFastForward(18880 (0), do discard frames)
2020-01-04 19:00:03.003554 I  avformatdecoder.cpp:806:SeekReset  AFD: SeekReset(18858, 22, do flush, do discard)
2020-01-04 19:00:03.003826 I  avformatdecoder.cpp:840:SeekReset  AFD: SeekReset() flushing
2020-01-04 19:00:03.007811 E  avformatdecoder.cpp:350:myth_av_log  [h264 @ 0x7f20604332c0] Missing reference picture, default is 0
2020-01-04 19:00:03.007820 E  avformatdecoder.cpp:350:myth_av_log  [h264 @ 0x7f20604332c0] co located POCs unavailable
2020-01-04 19:00:03.011952 E  avformatdecoder.cpp:350:myth_av_log  [h264 @ 0x7f20604332c0] Missing reference picture, default is 0
2020-01-04 19:00:03.011959 E  avformatdecoder.cpp:350:myth_av_log  [h264 @ 0x7f20604332c0] co located POCs unavailable
2020-01-04 19:00:03.015423 E  avformatdecoder.cpp:350:myth_av_log  [h264 @ 0x7f20604332c0] reference picture missing during reorder
2020-01-04 19:00:03.015428 E  avformatdecoder.cpp:350:myth_av_log  [h264 @ 0x7f20604332c0] reference picture missing during reorder
2020-01-04 19:00:03.015450 E  avformatdecoder.cpp:350:myth_av_log  [h264 @ 0x7f20604332c0] reference picture missing during reorder
2020-01-04 19:00:03.015456 E  avformatdecoder.cpp:350:myth_av_log  [h264 @ 0x7f20604332c0] Missing reference picture, default is 0
2020-01-04 19:00:03.015462 E  avformatdecoder.cpp:350:myth_av_log  [h264 @ 0x7f20604332c0] Missing reference picture, default is 0
2020-01-04 19:00:03.015466 E  avformatdecoder.cpp:350:myth_av_log  [h264 @ 0x7f20604332c0] Missing reference picture, default is 0
2020-01-04 19:00:03.021105 E  avformatdecoder.cpp:350:myth_av_log  [h264 @ 0x7f20604332c0] Missing reference picture, default is 0
2020-01-04 19:00:03.025542 E  avformatdecoder.cpp:350:myth_av_log  [h264 @ 0x7f20604332c0] mmco: unref short failure
2020-01-04 19:00:03.033709 E  avformatdecoder.cpp:350:myth_av_log  [h264 @ 0x7f20604332c0] reference picture missing during reorder
2020-01-04 19:00:03.033731 E  avformatdecoder.cpp:350:myth_av_log  [h264 @ 0x7f20604332c0] Missing reference picture, default is 65540
2020-01-04 19:00:03.044481 E  avformatdecoder.cpp:350:myth_av_log  [h264 @ 0x7f20604332c0] mmco: unref short failure
2020-01-04 19:00:03.128318 E  avformatdecoder.cpp:5311:GetFrame  decoding error End of file (-541478725)
2020-01-04 19:00:03.153320 E  avformatdecoder.cpp:5311:GetFrame  decoding error End of file (-541478725)
2020-01-04 19:00:03.163220 E  avformatdecoder.cpp:5311:GetFrame  decoding error End of file (-541478725)
2020-01-04 19:00:03.174267 E  avformatdecoder.cpp:5311:GetFrame  decoding error End of file (-541478725)
.
.  ## About 500 of these "GetFrame decoding error End of file" messages
.
2020-01-04 19:00:08.182935 E  avformatdecoder.cpp:5311:GetFrame  decoding error End of file (-541478725)
2020-01-04 19:00:08.192763 E  avformatdecoder.cpp:5311:GetFrame  decoding error End of file (-541478725)
2020-01-04 19:00:08.203576 E  avformatdecoder.cpp:350:myth_av_log  [buffer @ 0x7f205f76c0e0] Value -0.562500 for parameter 'pixel_aspect' out of range [0 - 1.797
69e+308]
2020-01-04 19:00:08.203597 E  avformatdecoder.cpp:350:myth_av_log  [buffer @ 0x7f205f76c0e0] Value -0.562500 for parameter 'pixel_aspect' out of range [0 - 1.797
69e+308]
2020-01-04 19:00:08.203632 E  avformatdecoder.cpp:350:myth_av_log  [buffer @ 0x7f205f76c0e0] Value -0.562500 for parameter 'pixel_aspect' out of range [0 - 1.797
69e+308]
2020-01-04 19:00:08.203649 E  avformatdecoder.cpp:350:myth_av_log  [buffer @ 0x7f205f76c0e0] Value -0.562500 for parameter 'pixel_aspect' out of range [0 - 1.797
69e+308]
2020-01-04 19:00:08.203655 E  avformatdecoder.cpp:350:myth_av_log  [buffer @ 0x7f205f76c0e0] Error setting option pixel_aspect to value -9/16.
2020-01-04 19:00:08.203660 E  avformatdecoder.cpp:350:myth_av_log  [Parsed_buffer_0 @ 0x7f205f732c80] Error applying options to the filter.
2020-01-04 19:00:08.203672 E  avformatdecoder.cpp:350:myth_av_log  [AVFilterGraph @ 0x7f205f76bf60] Error initializing filter 'buffer' with args 'video_size=1280
x720:pix_fmt=0:time_base=1/1:pixel_aspect=-9/16'

What I have done to stop the rolling process is to move the XXXXXXXXXXXXXXX.ts.png file that is generated with the original recording to XXXXXXXXXXXX.mkv.png.

But the question remains, why can't mythpreviewgen extract the PNG from my MKV file?

The command used to transcode is:

Code: Select all

HandBrakeCLI --preset-import-file /mnt/videos/mythtv/MY_Presets.json -Z "OTA 5.1 Audio"      -i $FILE --subtitle 1,2,3 -o $MKVFILE
The HandBrake Presets are:

Code: Select all

    [
        {
            "ChildrenArray": [
                {
                    "AudioCopyMask": [
                        "copy:aac",
                        "copy:ac3"
                    ],
                    "AudioEncoderFallback": "ac3",
                    "AudioList": [
                        {
                            "AudioBitrate": 128,
                            "AudioEncoder": "aac",
                            "AudioMixdown": "dpl2",
                            "AudioSamplerate": "auto",
                            "AudioTrackDRCSlider": 0.0,
                            "AudioTrackGainSlider": 0.0
                        },
                        {
                            "AudioBitrate": 640,
                            "AudioCompressionLevel": -1.0,
                            "AudioDitherMethod": "auto",
                            "AudioEncoder": "copy:ac3",
                            "AudioMixdown": "none",
                            "AudioNormalizeMixLevel": false,
                            "AudioSamplerate": "auto",
                            "AudioTrackQualityEnable": false,
                            "AudioTrackQuality": -1.0,
                            "AudioTrackGainSlider": 0.0,
                            "AudioTrackDRCSlider": 0.0
                        }

                    ],
                    "ChapterMarkers": true,
                    "Default": false,
                    "FileFormat": "mkv",
                    "Folder": false,
                    "Mp4HttpOptimize": false,
                    "Mp4iPodCompatible": false,
                    "PictureAutoCrop": true,
                    "PictureBottomCrop": 0,
                    "PictureLeftCrop": 0,
                    "PictureRightCrop": 0,
                    "PictureTopCrop": 0,
                    "PictureDeblock": 0,
                    "PictureDeinterlaceCustom": "",
                    "PictureDeinterlaceFilter": "off",
                    "PictureDeinterlacePreset": "default",
                    "PictureDenoiseCustom": "",
                    "PictureDenoiseFilter": "off",
                    "PictureDetelecine": "off",
                    "PictureDetelecineCustom": "",
                    "PictureHeight": 720,
                    "PictureKeepRatio": true,
                    "PictureModulus": 2,
                    "PicturePAR": "loose",
                    "PictureWidth": 1280,
                    "PresetDescription": "Davids Preset for OTA with 5.1 audio",
                    "PresetName": "David OTA 5.1 Audio",
                    "Type": 0,
                    "UsesPictureFilters": true,
                    "UsesPictureSettings": 1,
                    "VideoAvgBitrate": 2500,
                    "VideoEncoder": "x264",
                    "VideoFramerate": "30",
                    "VideoFramerateMode": "pfr",
                    "VideoGrayScale": false,
                    "VideoLevel": "3.1",
                    "VideoOptionExtra": "",
                    "VideoPreset": "medium",
                    "VideoProfile": "main",
                    "VideoQualitySlider": 22.0,
                    "VideoQualityType": 2,
                    "VideoTune": "",
                    "VideoTurboTwoPass": false,
                    "VideoTwoPass": false,
                    "x264Option": "",
                    "x264UseAdvancedOptions": false
                },
                {
                    "AudioCopyMask": [
                        "copy:aac",
                        "copy:ac3"
                    ],
                    "AudioEncoderFallback": "ac3",
                    "AudioList": [
                        {
                            "AudioBitrate": 128,
                            "AudioEncoder": "aac",
                            "AudioMixdown": "dpl2",
                            "AudioSamplerate": "auto",
                            "AudioTrackDRCSlider": 0.0,
                            "AudioTrackGainSlider": 0.0
                        },
                        {
                            "AudioBitrate": 640,
                            "AudioCompressionLevel": -1.0,
                            "AudioDitherMethod": "auto",
                            "AudioEncoder": "copy:ac3",
                            "AudioMixdown": "none",
                            "AudioNormalizeMixLevel": false,
                            "AudioSamplerate": "auto",
                            "AudioTrackQualityEnable": false,
                            "AudioTrackQuality": -1.0,
                            "AudioTrackGainSlider": 0.0,
                            "AudioTrackDRCSlider": 0.0
                        }

                    ],
                    "ChapterMarkers": true,
                    "Default": false,
                    "FileFormat": "mp4",
                    "Folder": false,
                    "Mp4HttpOptimize": false,
                    "Mp4iPodCompatible": false,
                    "PictureAutoCrop": true,
                    "PictureBottomCrop": 0,
                    "PictureLeftCrop": 0,
                    "PictureRightCrop": 0,
                    "PictureTopCrop": 0,
                    "PictureDeblock": 0,
                    "PictureDeinterlaceCustom": "",
                    "PictureDeinterlaceFilter": "off",
                    "PictureDeinterlacePreset": "default",
                    "PictureDenoiseCustom": "",
                    "PictureDenoiseFilter": "off",
                    "PictureDetelecine": "off",
                    "PictureDetelecineCustom": "",
                    "PictureHeight": 720,
                    "PictureKeepRatio": true,
                    "PictureModulus": 2,
                    "PicturePAR": "loose",
                    "PictureWidth": 1280,
                    "PresetDescription": "Davids Preset for OTA with 5.1 audio",
                    "PresetName": "David OTA 5.1 Audio MP4",
                    "Type": 0,
                    "UsesPictureFilters": true,
                    "UsesPictureSettings": 1,
                    "VideoAvgBitrate": 2500,
                    "VideoEncoder": "x264",
                    "VideoFramerate": "30",
                    "VideoFramerateMode": "pfr",
                    "VideoGrayScale": false,
                    "VideoLevel": "3.1",
                    "VideoOptionExtra": "",
                    "VideoPreset": "medium",
                    "VideoProfile": "main",
                    "VideoQualitySlider": 22.0,
                    "VideoQualityType": 2,
                    "VideoTune": "",
                    "VideoTurboTwoPass": false,
                    "VideoTwoPass": false,
                    "x264Option": "",
                    "x264UseAdvancedOptions": false
                }

           ],
            "Folder": true,
            "PresetName": "Davids Presets",
            "Type": 0

        }
    ]
Hope somebody can make sense of this...

blm-ubunet
Senior
Posts: 119
Joined: Sun Jun 15, 2014 1:08 am
Cambodia

Re: mythpreviewgen fails on MKV files with H264 video

Post by blm-ubunet » Sun Jan 05, 2020 2:51 am

I presume you are replacing the recorded file with the transcoded version "in-place".

The original file has a seektable as recorded & it is possible that mythpreviewgen converts time t to seektable keyframe (18858) to grab an image at t.

MythTV can not generate a seektable for mkv container (& MKV is purported to have been designed to help fast seeking) but I would recreate seektable for any transcoded file (using 'mythcommflag --rebuild' is best bizarrely).
This may server to clear the now erroneous seektable for mkv.

MKV container has some bad design failings like inadequate framerate resolution/timing.

User avatar
pgbennett
Developer
Posts: 355
Joined: Mon Apr 27, 2015 5:41 pm
United States of America

Re: mythpreviewgen fails on MKV files with H264 video

Post by pgbennett » Sun Jan 05, 2020 3:52 pm

Seektables for mkv files do not work. Running mythcommflag --rebuild effectively deletes the seektable. A faster way to delete the seektable is

Code: Select all

mythutil --clearseektable --chanid "$chanid" --starttime "$starttime"
I have been transcoding recordings to h264 for years using HandBrakeCLI. The only mthpeviewgen problem I have had is that when you have a non-standard video size (e.g. 1918 x 1078 instead of 1920 x 1080), the preview picture is scrambled on the screen. This was happening as a result of Handbrake's automatic cropping, so I disabled that.

goldpizza44
Newcomer
Posts: 5
Joined: Sat Jan 04, 2020 11:07 pm
United States of America

Re: mythpreviewgen fails on MKV files with H264 video

Post by goldpizza44 » Sun Jan 05, 2020 7:29 pm

You both are good!

Yes, I am updating "in-place" by manually updating the 'recorded' table replacing the filename and filesize. I originally started with the MP4 container but found that either the subtitles or the multichannel sound (I forget which now) would not play in a Kodi frontend for unknown reasons. I switched to the MKV container and the subtitles would show and sound worked.. The transcoding keeps both the original OTA subtitles as well as the 5.1CH sound if it is broadcast.

I added:

Code: Select all

mythutil --clearseektable --chanid $chanid --starttime $starttime
mythpreviewgen --size 0x0 --chanid $chanid --starttime $starttime --outfile $MKVFILE.png
to my script and I believe that will completely solve the problem.

I also noticed that the net effect of mythcommflag was to delete all entries from the recordedseek table and I was thinking to just use mysql directly to do that, but mythutil is cleaner.

Out of curiosity I tried to run:

Code: Select all

mythcommflag --chanid $chanid --starttime $starttime --method blank
on one of my MKV files and it failed with the same error: ast above:

Code: Select all

2020-01-05 14:08:21.121042 E  avformatdecoder.cpp:5311:GetFrame  decoding error End of file (-541478725)
2020-01-05 14:08:21.130711 E  avformatdecoder.cpp:5311:GetFrame  decoding error End of file (-541478725)
2020-01-05 14:08:21.141574 E  avformatdecoder.cpp:5311:GetFrame  decoding error End of file (-541478725)
which I suppose confirms that seek tables don't work for MKV files.

Thanks again for both responses!

User avatar
pgbennett
Developer
Posts: 355
Joined: Mon Apr 27, 2015 5:41 pm
United States of America

Re: mythpreviewgen fails on MKV files with H264 video

Post by pgbennett » Mon Jan 06, 2020 3:23 pm

IIRC, that error always comes out of mythcommflag, even when it is working. End of file is not really an error.

FHSauce
Newcomer
Posts: 3
Joined: Tue Jan 07, 2020 9:47 am
United States of America

Re: mythpreviewgen fails on MKV files with H264 video

Post by FHSauce » Tue Jan 07, 2020 9:50 am

@goldpizza44

What you are doing is exactly what I wish to do with my system, I was wondering if you could share your script? I assume you are running this as a user job?

goldpizza44
Newcomer
Posts: 5
Joined: Sat Jan 04, 2020 11:07 pm
United States of America

Re: mythpreviewgen fails on MKV files with H264 video

Post by goldpizza44 » Tue Jan 07, 2020 11:51 am

Here is my script. It makes use of HandBrakeCLI and a custom preset file shown above. You can tune the presets to your liking. You can also change to ffmpeg or any other transcoder.

The script can be run by either giving a CHANID and STARTTIME (-c CCCCC -s YYYYMMDDHHMMSS ), or a filename which is encoded with the CHANID and STARTTIME (-f CCCCC_YYYYMMDDHHMMSS.ts).

It directly reads/updates the tables in the mythconverg database and there might be better ways to do this with mythutil or other programs.

The 'UserJob1' and 'UserJobDesc1' settings are set to:

Code: Select all

UserJob1       /usr/local/bin/myth_transcode_to_mkv -c %CHANID% -s %STARTTIME%
UserJobDesc1   Transcode to MKV
I use mythweb to setup/manage recordings.

Note in this script I have hard coded the paths to my presets and to the output log which records how long the transcoding took

Code: Select all

#!/bin/bash
export PATH=$PATH:/usr/local/bin

while getopts "dzc:s:f:" opt
do
	case "${opt}" in 
	d) DBUPDATEONLY=YES;;
	z) # TIMEZONE in UTC...dont convert
		export TZ=UTC;;
	c) chanid=${OPTARG};;

	s) starttime=${OPTARG};;

	f) FILE=${OPTARG##*/}
	   chanid=${FILE%%_*}
	   starttime=${FILE##*_}
	   starttime=${starttime%%.*}
	   export TZ=UTC;;
	
	esac
done

shift $((OPTIND-1))

if [[ -z "$chanid" || -z "starttime" ]]
then
	echo "USAGE: $0  -c chanid  -t YYYYMMDDHHMMSS [ -z ]"
	exit
fi

# Convert the STARTTIME to UTC.  starttime will have format YYYYMMDDHHMMSS.  
# The date command will convert to seconds from EPOCH, and then back to a UTC time
ST=$(echo $starttime | sed "s/\(....\)\(..\)\(..\)\(..\)\(..\)\(..\)/\1-\2-\3 \4:\5:\6/")
STsec=$(date "+%s" --date "$ST")
export TZ=UTC
starttime=$(date "+%Y%m%d%H%M%S" --date=@$STsec)

STARTCONV=$(date '+%Y/%m/%d %H:%M:%S')
STARTSEC=$(date '+%s' --date="$STARTCONV")

# set FILEDB, CHANNUM, CHANNAME and TITLE variables from the recorded, channel and storagegroup tables
eval $(echo "Select C.chanid,C.channum,C.callsign,R.starttime,R.title,S.dirname,R.basename from recorded R, channel C, storagegroup S where S.hostname='$(uname -n)' and R.storagegroup=S.groupname and R.chanid=C.chanid and  C.chanid=$chanid and R.starttime='$starttime' ;" |mysql -s -u mythtv --password=mythtv mythconverg | gawk -F'	' '
{gsub(/,/,"",$5);printf("export FILEDB=%s%s;export CHANNUM=%s;export CHANNAME=%s;export TITLE=\"%s\";",$6,$7,$2,$3,$5)}')

[ -z "$FILE" ] && export FILE=$FILEDB

export MKVFILE=${FILE%.*}.mkv

echo FILE=$FILE   MP4FILE=$MP4FILE    MKVFILE=$MKVFILE   DBUPDATEONLY=$DBUPDATEONLY

export INFILESIZE=$(stat -c %s $FILE)

if [ "$DBUPDATEONLY" != YES ]
then
	# If HandBrakeCLI returns failure don't update the database
	HandBrakeCLI --preset-import-file /mnt/videos/mythtv/MY_Presets.json -Z "OTA 5.1 Audio"        -i $FILE --subtitle 1,2,3 -o $MKVFILE
	FAILCODE=$?
else
	FAILCODE=0
fi

FILESIZE=$(ls -ls $MKVFILE | gawk '{print $6}')

if [ "$FAILCODE" == 0 ]
then
	echo "Updating Datbase"
	echo "update recorded set basename='${MKVFILE##*/}',filesize=$FILESIZE where basename='${FILE##*/}';"|mysql -u mythtv --password=mythtv mythconverg
	# Rebuild the seektable, generate a new preview image, and remove any old preview image
	mythutil      --clearseektable -chanid $chanid --starttime $starttime
	#mythcommflag   --rebuild  --chanid $chanid --starttime $starttime
	mythpreviewgen --size 0x0 --chanid $chanid --starttime $starttime --outfile $MKVFILE.png
	rm $FILE.png
fi

let DURATION=$(date '+%s')-$STARTSEC
export OUTFILESIZE=$(stat -c %s $MKVFILE)

echo "$(date '+%Y/%m/%d %H:%M:%S'),$STARTCONV,$DURATION,$FAILCODE,$FILE,$INFILESIZE,$MKVFILE,$OUTFILESIZE,$CHANNUM,$CHANNAME,$TITLE" >> /mnt/videos/mythtv/myth_transcode_to_mkv.log

rm -f $FILE
Have fun

FHSauce
Newcomer
Posts: 3
Joined: Tue Jan 07, 2020 9:47 am
United States of America

Re: mythpreviewgen fails on MKV files with H264 video

Post by FHSauce » Wed Jan 08, 2020 8:11 am

Thanks for sharing, I can get this to work via command line using the -f CCCCC_YYYYMMDDHHMMSS.ts option but ideally I wanted it to run after a recording as a user job - I assume that's how you are using it as well. After I set it up as a user job I went to an existing recording and tried to run the job by clicking "Transcode to MKV", it shows in the backend status as queued but never runs. Doesn't look like the script ever gets kicked off looking at the backend logs / system top. Am I missing something?

goldpizza44
Newcomer
Posts: 5
Joined: Sat Jan 04, 2020 11:07 pm
United States of America

Re: mythpreviewgen fails on MKV files with H264 video

Post by goldpizza44 » Wed Jan 08, 2020 6:15 pm

Check the value of JobAllowUserJob1 in the settings:

Code: Select all

echo "select * from mythconverg.settings where value='JobAllowUserJob1';"|mysql -u mythtv --password=mythtv
The 'data' should be 1 and the 'hostname' should be the name of your server (eg. myserver.example.com) or the IP address of your server (look at other parameters to get the most likely value for hostname.

If either data is not 1 or hostname is not correct the Job will not run.

I think you can also set this in mythtv-setup (probably better than messing with the database) by going to:

General -> Job Queue (Backend-Specific) -> Allow Transcode to MKV Jobs (or Allow User Job 1)

This should be checked. There may be other settings in here that need tweaking.

In my system it runs as a User Job after every recording (I specifically have each recording schedule configured to run it). It normally doesn't start immediately after the recording is finished though. I am not sure what controls when the jobs start. They typically run over night for content recorded during the past evening.

FHSauce
Newcomer
Posts: 3
Joined: Tue Jan 07, 2020 9:47 am
United States of America

Re: mythpreviewgen fails on MKV files with H264 video

Post by FHSauce » Thu Jan 09, 2020 7:06 am

That was it, missed that step - thanks a lot working great!

Post Reply