softhddevice - jerky/bad frame order(?) playback for live/recorded sd mpeg2

  • Hi. I frequently experience jerky playback on all sd mpeg2 content when using softhddevice. It looks almost like the frame order is mixed up. I created a short sample recording which shows the problem. The sample plays fine with mpv in linux and mpc-hc in windows. It's only jerky when softhddevice is the decoder. If anyone can help fix this, the sample may be downloaded at: https://drive.google.com/file/…3vrQPV3B2VjBDd21sT1E/view


    Thanks for any help!

  • I frequently experience jerky playback on all sd mpeg2 content when using softhddevice.

    Which fork of softhddevice do you use and what is your output hardware?


    Regards
    fnu

    HowTo: APT pinning

  • I use nvidia video cards and vdpau. I use Louis's fork of Johns official repo. Louis added support for an opengl-osd but that's all. The problem is present in the official repo as well, which I mentioned to Johns ages ago. I think we got busy with other fixes to softhdevice at the time and forgot about it.


    I should mention that this problem existed in vdr-xine as well. Rnissl fixed it pretty quickly. If it's the same issue in softhddevice, which it looks like from a user perspective, I don't think it should be hard to figure out. It's been years now but IIRC it may have had something to do with bad pts timing...? Or possibly missing error-handling in case an error occurs in the stream.

  • It's only jerky when softhddevice is the decoder.

    Is your TV/Monitor set to a multiple of the video framerate (in this case 29.97 fps)? AFAIK there is no good pull-up/pull-down mechanism in softhddevice for framerate adaption.

    yaVDR-Dokumentation (Ceterum censeo enchiridia esse lectitanda.)

  • Is your TV/Monitor set to a multiple of the video framerate (in this case 29.97 fps)? AFAIK there is no good pull-up/pull-down mechanism in softhddevice for framerate adaption.


    I've never had to set any of my tvs to anything. They all play different framerates no problem. But I don't believe this is a frame rate problem anyways. If you check the sample I've provided, it looks like the issue is playing frames out of sequence. Maybe something due to timing, or a missing end-of-sequence flag in the headers, or whatever else, I dunno. Like I said though, this exact same problem existed in vdr-xine as well and Rnissl managed to fix it quickly within vdr-xine - it wasn't related to tv settings, video cards, video drivers, etc.


    After looking in my past pm's with Johns, hd mpeg4 h264 had the same problem, which he fixed.

  • It can be a simple parsing error.
    To find these failures, all debug information (mostly disabled in the source) must be enabled and then looked where the packages are lost.


    F.e. dvb docs says only 3 0 are allowed, the stations encoder adds 4 or more 0 at these position.


    Johns

    Sag mir, wo die Developer sind. Wo sind sie geblieben? . . . . . . . . . . . . . . . . . . . . SoftHdDevice - A software and GPU emulated HD output device plugin.
    Sag mir, wo die Developer sind. Was ist geschehn?


    Client0: Crown CW02 MSI_C847MS-E33 Zotac_GT640_passiv Cine-S2 iMon-MCE / streamdev softhddevice
    Client1: Lian_Li_PC-Q09FB ASRock_H67M-ITX/HT I3-2100 ASUS_ENGT520_passiv / streamdev softhddevice
    Test: Lian_Li_PC-Q09R Asus C60M1-I / streamdev
    Server0: Dockstar TT-S2-3600-USB / streamdev
    Server2: Lian_Li_PC-Q07R Intel_DH61DL G620 WD20EARX 90W PicoPSU Cine-S2+DuoFlex-S2+DuoFlex-CT / streamdev / 22 Watt Verbrauch

  • It can be a simple parsing error.
    To find these failures, all debug information (mostly disabled in the source) must be enabled and then looked where the packages are lost.


    F.e. dvb docs says only 3 0 are allowed, the stations encoder adds 4 or more 0 at these position.


    Watching tv here has gotten really bad because of this problem so I'll try stumbling my way through it. A few more questions...


    If I `grep -i "debug" *` I see some lines where debug is commented out, for example: softhddev.c: //Debug(3, "audio: pts %#012" PRIx64 "\n", AudioAvPkt->pts);
    The same is true with `grep -i dsyslog *`. Do I want to uncomment every "//Debug" and "//dsyslog" in all files where they're commented out?


    I start vdr with "--log=3". Do I need to adjust that at all?


    To enable all the debugging I'll need, do I simple enable -DDEBUG in the softhddevice Makefile?


    Is there anything specific I'm supposed to be looking for in the log? I assume enabling the debugging is going to spit out a bunch of technical info that will be like reading Chinese to me so I'm lost about where to even start.


    Last question, will I need any other tools besides the log? Will I have to analyze the sample recording somehow to compare it with whatever debug info the logs contain? Totally lost here as well.


    I greatly appreciate any patience & help trying to fix this!

  • you must build with -DDEBUG otherwise all the debug macros aren't working.


    Code
    1. void VideoRenderFrame(VideoHwDecoder * hw_decoder,
    2. const AVCodecContext * video_ctx, const AVFrame * frame)
    3. {
    4. #if 0
    5. fprintf(stderr, "video: render frame pts %s closing %d\n",
    6. Timestamp2String(frame->pkt_pts), hw_decoder->Vdpau.Closing);
    7. #endif


    Change here the #if 0 to #if 1, here it prints every frame, if correct decoded.
    When this is ok, than the failure is in the display part.
    If here are frames missing, incorrect order, than the failure is in the decoder part.
    This logs to console and not syslog. If you need syslog change the fprintf(stderr, to Debug(2,


    Look if there are no errors in the syslog. I check some errors in the format.


    In CodecVideoDecode,

    Code
    1. Debug(4, "%s: %p %d -> %d %d\n", __FUNCTION__, pkt->data, pkt->size, used,
    2. got_frame);


    Chenge the 4 to 3 or less to see the debug.
    Here decodes ffmpeg 1 video packet to 1 video frame. The complete packet should be used
    and give 1 frame.


    With above debug you should see the message 50x per second (50 Hz station).


    Without any knowledge it is hard to find the bug. But MPEG, H264 and TS are well documented.
    And the failure is somewhere in the parsing.


    Johns

    Sag mir, wo die Developer sind. Wo sind sie geblieben? . . . . . . . . . . . . . . . . . . . . SoftHdDevice - A software and GPU emulated HD output device plugin.
    Sag mir, wo die Developer sind. Was ist geschehn?


    Client0: Crown CW02 MSI_C847MS-E33 Zotac_GT640_passiv Cine-S2 iMon-MCE / streamdev softhddevice
    Client1: Lian_Li_PC-Q09FB ASRock_H67M-ITX/HT I3-2100 ASUS_ENGT520_passiv / streamdev softhddevice
    Test: Lian_Li_PC-Q09R Asus C60M1-I / streamdev
    Server0: Dockstar TT-S2-3600-USB / streamdev
    Server2: Lian_Li_PC-Q07R Intel_DH61DL G620 WD20EARX 90W PicoPSU Cine-S2+DuoFlex-S2+DuoFlex-CT / streamdev / 22 Watt Verbrauch

  • Also wenn ich es richtig sehe wird die PTS falsch berechnet oder falsch gesendet.


    Code
    1. 2017.Aug.07|07:58:52 video: render frame pts 25:28:27.623 closing 0
    2. 2017.Aug.07|07:58:53 video: render frame pts 25:28:27.673 closing 0
    3. 2017.Aug.07|07:58:53 video: render frame pts 25:28:27.707 closing 0
    4. 2017.Aug.07|07:58:53 video: render frame pts 25:28:27.757 closing 0
    5. 2017.Aug.07|07:58:53 video: render frame pts 25:28:27.790 closing 0
    6. 2017.Aug.07|07:58:53 video: render frame pts 25:28:27.840 closing 0
    7. 2017.Aug.07|07:58:53 video: render frame pts 25:28:27.873 closing 0
    8. 2017.Aug.07|07:58:53 video: render frame pts 25:28:27.923 closing 0


    623->673 = 50ms, 673->707 = 34ms, 707->757 = 50ms, 757->790 = 33ms, 790->840 = 50ms, 840->873 = 33ms, 873->923 = 50ms


    Looks like some speedup source material. Its a 20Hz frame interleaved with a 30Hz frame.
    I have no idea how to render this.


    The decoder and rendering looks ok. But my frame render didn't support dynamic frequency changes.


    Johns

    Sag mir, wo die Developer sind. Wo sind sie geblieben? . . . . . . . . . . . . . . . . . . . . SoftHdDevice - A software and GPU emulated HD output device plugin.
    Sag mir, wo die Developer sind. Was ist geschehn?


    Client0: Crown CW02 MSI_C847MS-E33 Zotac_GT640_passiv Cine-S2 iMon-MCE / streamdev softhddevice
    Client1: Lian_Li_PC-Q09FB ASRock_H67M-ITX/HT I3-2100 ASUS_ENGT520_passiv / streamdev softhddevice
    Test: Lian_Li_PC-Q09R Asus C60M1-I / streamdev
    Server0: Dockstar TT-S2-3600-USB / streamdev
    Server2: Lian_Li_PC-Q07R Intel_DH61DL G620 WD20EARX 90W PicoPSU Cine-S2+DuoFlex-S2+DuoFlex-CT / streamdev / 22 Watt Verbrauch


  • I don't know if this is helpful but the framerate should be 29.97 FPS. I also tested the sample with mpv-player, which played it perfectly fine. I asked about this in #mpv-devel on Freenode and the reply I got was, "Don't expect anything from the input and just use the timestamps. That's what mpv follows. Broadcast can switch between soft telecine and actual interlacism. Same for DVDs. It just gets repeat field flags in that case usually".


    Does this help any?

  • I don't know if it works, never tested this: You should set your X11 resolution to 60Hz.


    The repeat bit can't be set or be used in your source:

    Code
    1. if (frame->repeat_pict && !VideoIgnoreRepeatPict) {
    2. Warning(_("video: repeated pict %d found, but not handled\n"), frame->repeat_pict);


    I have this in the source and you get a big warning in the syslog, if it is found.

    Zitat

    "Don't expect anything from the input and just use the timestamps.


    This correct and bullshit. This is what I do and what you see is what happens.


    For good quality the X11 resolution must be a multiple of 20hz and 30hz.

    And then the renderer must render the frames multiple time to get them in correct sync.

    But this is not supported, by my render engine.


    Johns

    Sag mir, wo die Developer sind. Wo sind sie geblieben? . . . . . . . . . . . . . . . . . . . . SoftHdDevice - A software and GPU emulated HD output device plugin.
    Sag mir, wo die Developer sind. Was ist geschehn?


    Client0: Crown CW02 MSI_C847MS-E33 Zotac_GT640_passiv Cine-S2 iMon-MCE / streamdev softhddevice
    Client1: Lian_Li_PC-Q09FB ASRock_H67M-ITX/HT I3-2100 ASUS_ENGT520_passiv / streamdev softhddevice
    Test: Lian_Li_PC-Q09R Asus C60M1-I / streamdev
    Server0: Dockstar TT-S2-3600-USB / streamdev
    Server2: Lian_Li_PC-Q07R Intel_DH61DL G620 WD20EARX 90W PicoPSU Cine-S2+DuoFlex-S2+DuoFlex-CT / streamdev / 22 Watt Verbrauch

  • I forced my refresh rate to 60Hz:

    ~$ sudo xrandr --display :0

    Screen 0: minimum 8 x 8, current 1920 x 1080, maximum 16384 x 16384

    DVI-I-0 disconnected primary (normal left inverted right x axis y axis)

    VGA-0 disconnected (normal left inverted right x axis y axis)

    DVI-I-1 disconnected (normal left inverted right x axis y axis)

    HDMI-0 connected 1920x1080+0+0 (normal left inverted right x axis y axis) 698mm x 392mm

    1920x1080 60.00*+ 59.94 23.97 60.05 60.00

    1280x720 60.00 59.94

    720x480 59.94

    640x480 59.94 59.93


    I created a new log and attached it.


    Just for reference, my softhddevice/Makefile has:

    CONFIG += -DDEBUG
    #-DOSD_DEBUG # enable debug output+functions

    #CONFIG += -DSTILL_DEBUG=2 # still picture debug verbose level

    #CONFIG += -DAV_INFO -DAV_INFO_TIME=3000 # info/debug a/v sync

    CONFIG += -DUSE_PIP # PIP support

    CONFIG += -DHAVE_PTHREAD_NAME # supports new pthread_setname_np

    #CONFIG += -DNO_TS_AUDIO # disable ts audio parser

    #CONFIG += -DUSE_TS_VIDEO # build new ts video parser

    CONFIG += -DUSE_MPEG_COMPLETE # support only complete mpeg packets

    CONFIG += -DH264_EOS_TRICKSPEED # insert seq end packets for trickspeed

    #CONDIF + = -DDUMP_TRICKSPEED # dump packets trickspeed

    #CONFIG += -DUSE_BITMAP # VDPAU, use bitmap surface for OSD

    CONFIG + = -DUSE_VDR_SPU SPU # use VDR decoder.

    #CONFIG += -DUSE_SOFTLIMIT # (tobe removed) limit the buffer fill


    And last, if I understand correctly, this can't be fixed without adding some feature to the softhddevice renderer? Is it possible to just look at what mpv does in this case and copy it since it plays fine in mpv? Or are renderers vastly different? It seems like playing mpeg2 video would be standard..? This makes watching live tv impossible on many channels here.


  • The log is not so important, is the video smooth?


    I have a very simple renderer it outputs a frame every 1/50s or 1/60s which depends on your display rate. When the video is too slow, i show the last frame twice, if the video is to fast i skip frames. When i look into the log, it looks good, it just renders the video without any duplications or drops.


    Johns

    Sag mir, wo die Developer sind. Wo sind sie geblieben? . . . . . . . . . . . . . . . . . . . . SoftHdDevice - A software and GPU emulated HD output device plugin.
    Sag mir, wo die Developer sind. Was ist geschehn?


    Client0: Crown CW02 MSI_C847MS-E33 Zotac_GT640_passiv Cine-S2 iMon-MCE / streamdev softhddevice
    Client1: Lian_Li_PC-Q09FB ASRock_H67M-ITX/HT I3-2100 ASUS_ENGT520_passiv / streamdev softhddevice
    Test: Lian_Li_PC-Q09R Asus C60M1-I / streamdev
    Server0: Dockstar TT-S2-3600-USB / streamdev
    Server2: Lian_Li_PC-Q07R Intel_DH61DL G620 WD20EARX 90W PicoPSU Cine-S2+DuoFlex-S2+DuoFlex-CT / streamdev / 22 Watt Verbrauch

  • The log is not so important, is the video smooth?


    I have a very simple renderer it outputs a frame every 1/50s or 1/60s which depends on your display rate. When the video is too slow, i show the last frame twice, if the video is to fast i skip frames. When i look into the log, it looks good, it just renders the video without any duplications or drops.


    Johns

    Setting 60Hz didn't make any difference, the video playback still has the same problem. Have you downloaded the sample and checked it locally? I don't mind using mpv-player to watch recordings but unfortunately that doesn't help live tv being unwatchable. :(

  • Sorry I haven't downloaded the sample. Send me the link again.


    Johns

    Sag mir, wo die Developer sind. Wo sind sie geblieben? . . . . . . . . . . . . . . . . . . . . SoftHdDevice - A software and GPU emulated HD output device plugin.
    Sag mir, wo die Developer sind. Was ist geschehn?


    Client0: Crown CW02 MSI_C847MS-E33 Zotac_GT640_passiv Cine-S2 iMon-MCE / streamdev softhddevice
    Client1: Lian_Li_PC-Q09FB ASRock_H67M-ITX/HT I3-2100 ASUS_ENGT520_passiv / streamdev softhddevice
    Test: Lian_Li_PC-Q09R Asus C60M1-I / streamdev
    Server0: Dockstar TT-S2-3600-USB / streamdev
    Server2: Lian_Li_PC-Q07R Intel_DH61DL G620 WD20EARX 90W PicoPSU Cine-S2+DuoFlex-S2+DuoFlex-CT / streamdev / 22 Watt Verbrauch

  • On my VDR1, I use Johns' original softhddevice with vdpau output (amd/ati). Here, I see the choppy display that you describe. However, on my VDR2 where I use the pesintta fork and va-api (intel), display seems to be OK. I am not sure if the difference is because of vdpau vs vaapi or because of the different softhddevice forks. It might be worth giving the pesintta fork a try.

    VDR 1: Linux Mint 18.1 mit VDR 2.2.0 und Ausgabe auf X11 (Radeon HD6450) via softhddevice/vdpau. DVB-Karte: DVBSky T9580V3
    VDR 2: Ausgabe auf X11 (Intel i5 Kaby Lake) via softhddevice/vaapi, sonst wie VDR 1

    Dieser Beitrag wurde bereits 1 Mal editiert, zuletzt von mighty-p () aus folgendem Grund: typo

  • On my VDR1, I use Johns' original softhddevice with vdpau output (amd/ati). Here, I see the choppy display that you describe. However, on my VDR2 where I use the pesitta fork and va-api (intel), display seems to be OK. I am not sure if the difference is because of vdpau vs vaapi or because of the different softhddevice forks. It might be worth giving the pesintta fork a try.

    Thank you for testing! I tried the pesintta fork you linked and playback is ok so there is definitely something different between the two. I'm going to do more investigating and hopefully will come up with more info.